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

Fix cross-compilation for static,vendored #95

Merged
merged 3 commits into from
Aug 19, 2024
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
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ jobs:
os-arch: amd64
args: ''

- rust-target: x86_64-unknown-linux-gnu
os-target: x86_64-linux-gnu
os-arch: amd64
args: '-F static,vendored'

- rust-target: x86_64-unknown-linux-gnu
os-target: x86_64-linux-gnu
os-arch: amd64
Expand All @@ -25,6 +30,16 @@ jobs:
os-target: aarch64-linux-gnu
os-arch: arm64
args: ''
# Test cross-compilation to aarch64
- rust-target: aarch64-unknown-linux-gnu
os-target: aarch64-linux-gnu
os-arch: arm64
args: '-F static,vendored'
# Test cross-compilation to riscv64
- rust-target: riscv64gc-unknown-linux-gnu
os-target: riscv64-linux-gnu
os-arch: riscv64
args: '-F static,vendored'
runs-on: ubuntu-22.04
env:
CARGO_BUILD_TARGET: ${{ matrix.rust-target }}
Expand Down Expand Up @@ -53,6 +68,8 @@ jobs:
sudo apt-get update
sudo apt-get install \
build-essential \
autopoint \
gettext \
libelf-dev:${{ matrix.os-arch }} \
zlib1g-dev:${{ matrix.os-arch }}
Expand Down
28 changes: 27 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,23 @@ fn make_elfutils(compiler: &cc::Tool, src_dir: &path::Path, out_dir: &path::Path
.arg("--enable-maintainer-mode")
.arg("--disable-debuginfod")
.arg("--disable-libdebuginfod")
.arg("--disable-demangler")
.arg("--without-zstd")
.arg("--prefix")
.arg(&src_dir.join("elfutils/prefix_dir"))
.arg("--host")
.arg({
let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let arch = match arch.as_str() {
"riscv64gc" => "riscv64",
"riscv32gc" => "riscv32",
other => other,
};
let vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();
let env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
let os = env::var("CARGO_CFG_TARGET_OS").unwrap();
format!("{arch}-{vendor}-{os}-{env}")
})
.arg("--libdir")
.arg(out_dir)
.env("CC", compiler.path())
Expand All @@ -304,12 +318,24 @@ fn make_elfutils(compiler: &cc::Tool, src_dir: &path::Path, out_dir: &path::Path

assert!(status.success(), "make failed");

// Build in elfutils/lib because building libelf requires it.
let status = process::Command::new("make")
.arg("-j")
.arg(&format!("{}", num_cpus()))
.arg("BUILD_STATIC_ONLY=y")
.current_dir(&src_dir.join("elfutils/lib"))
.status()
.expect("could not execute make");

assert!(status.success(), "make failed");

// Build libelf only
let status = process::Command::new("make")
.arg("install")
.arg("-j")
.arg(&format!("{}", num_cpus()))
.arg("BUILD_STATIC_ONLY=y")
.current_dir(&src_dir.join("elfutils"))
.current_dir(&src_dir.join("elfutils/libelf"))
.status()
.expect("could not execute make");

Expand Down
Loading