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

Bindgen support #95

Merged
merged 3 commits into from
Feb 25, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ jobs:
zig-version: ${{ matrix.zig }}
- run: zig version
- run: cargo build
- name: Bindgen
run: |
git clone --recurse-submodules https://github.com/gyscos/zstd-rs.git tests/zstd-rs
rustup target add aarch64-unknown-linux-gnu
cargo run zigbuild --manifest-path tests/zstd-rs/Cargo.toml --features bindgen --target aarch64-unknown-linux-gnu
- name: macOS - Test build
run: |
rustup target add x86_64-apple-darwin
Expand Down
19 changes: 19 additions & 0 deletions src/zig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,25 @@ impl Zig {
cmd.env("CARGO_UNSTABLE_TARGET_APPLIES_TO_HOST", "true");
cmd.env("CARGO_TARGET_APPLIES_TO_HOST", "false");
}

// bindgen support (Linux only)
if let Ok(lib_dir) = Zig::lib_dir() {
if raw_target.contains("linux") {
let libc = lib_dir.join("libc");
let bindgen_env = format!("BINDGEN_EXTRA_CLANG_ARGS_{}", env_target);
if raw_target.contains("musl") {
cmd.env(
bindgen_env,
format!("--sysroot={}", libc.join("musl").display()),
);
} else if raw_target.contains("gnu") {
cmd.env(
bindgen_env,
format!("--sysroot={}", libc.join("glibc").display()),
);
}
}
}
}
Ok(())
}
Expand Down