Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better cross compilation support #53

Merged
merged 4 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@ name: Build & Test
on: [push, pull_request]

jobs:
rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt
override: true
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

windows-msvc:
strategy:
fail-fast: false
matrix:
target: [i686-pc-windows-msvc, x86_64-pc-windows-msvc]
channel: [1.36.0, stable, beta, nightly]
channel: [1.48.0, stable, beta, nightly]
runs-on: windows-latest
name: Windows - ${{ matrix.target }} - ${{ matrix.channel }}
env:
Expand Down Expand Up @@ -38,7 +54,7 @@ jobs:
strategy:
fail-fast: false
matrix:
channel: [1.36.0, stable, beta, nightly]
channel: [1.48.0, stable, beta, nightly]
runs-on: windows-latest
name: Windows - x86_64-pc-windows-gnu - ${{ matrix.channel }}
env:
Expand Down Expand Up @@ -76,7 +92,7 @@ jobs:
strategy:
fail-fast: false
matrix:
channel: [1.36.0, stable, beta, nightly]
channel: [1.48.0, stable, beta, nightly]
features: ["--no-default-features", "--features system"]
runs-on: macos-latest
name: macOS - ${{ matrix.channel }} ${{ matrix.features }}
Expand Down Expand Up @@ -110,7 +126,7 @@ jobs:
strategy:
fail-fast: false
matrix:
channel: [1.36.0, stable, beta, nightly]
channel: [1.48.0, stable, beta, nightly]
features: ["--no-default-features", "--features system"]
target:
- x86_64-unknown-linux-gnu
Expand All @@ -131,9 +147,9 @@ jobs:
features: "--features system"
- target: riscv64gc-unknown-linux-gnu
features: "--features system"
# 1.36.0 is too old for riscv64gc-unknown-linux-gnu
# 1.48.0 is too old for riscv64gc-unknown-linux-gnu
- target: riscv64gc-unknown-linux-gnu
channel: 1.36.0
channel: 1.48.0

runs-on: ubuntu-latest
name: Linux - ${{ matrix.channel }} ${{ matrix.features }} ${{ matrix.target }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ libffi = { version = "2.0.0", features = ["system"] }
See [the `libffi-sys` documentation] for more information about how it
finds C libffi.

This crate supports Rust version 1.36 and later.
This crate supports Rust version 1.48 and later.

### Examples

Expand Down
2 changes: 1 addition & 1 deletion libffi-rs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ libffi = { version = "2.0.1", features = ["system"] }
See [the `libffi-sys` documentation] for more information about how it
finds C libffi.

This crate supports Rust version 1.36 and later.
This crate supports Rust version 1.48 and later.

### Examples

Expand Down
2 changes: 1 addition & 1 deletion libffi-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//! See [the `libffi-sys` documentation] for more information about how it
//! finds C libffi.
//!
//! This crate supports Rust version 1.36 and later.
//! This crate supports Rust version 1.48 and later.
//!
//! # Organization
//!
Expand Down
4 changes: 2 additions & 2 deletions libffi-sys-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ complex = []
[package.metadata.docs.rs]
features = ["system"]

[target.'cfg(target_env = "msvc")'.build-dependencies]
cc = "1.0.48"
[build-dependencies]
cc = "1.0"
28 changes: 27 additions & 1 deletion libffi-sys-rs/build/not_msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ pub fn configure_libffi(prefix: PathBuf, build_dir: &Path) {
command
.arg("configure")
.arg("--with-pic")
.arg("--disable-shared")
.arg("--disable-docs");

let target = std::env::var("TARGET").unwrap();
if target != std::env::var("HOST").unwrap() {
let host = std::env::var("HOST").unwrap();
if target != host {
// Autoconf uses riscv64 while Rust uses riscv64gc for the architecture
if target == "riscv64gc-unknown-linux-gnu" {
command.arg("--host=riscv64-unknown-linux-gnu");
Expand All @@ -61,6 +63,30 @@ pub fn configure_libffi(prefix: PathBuf, build_dir: &Path) {
}
}

let mut c_cfg = cc::Build::new();
c_cfg
.cargo_metadata(false)
.target(&target)
.warnings(false)
.host(&host);
let c_compiler = c_cfg.get_compiler();

command.env("CC", c_compiler.path());

let mut cflags = c_compiler.cflags_env();
match env::var_os("CFLAGS") {
None => (),
Some(flags) => {
cflags.push(" ");
cflags.push(&flags);
}
}
command.env("CFLAGS", cflags);

for (k, v) in c_compiler.env().iter() {
command.env(k, v);
}

command.current_dir(&build_dir);

if cfg!(windows) {
Expand Down