Skip to content

Commit c700c03

Browse files
bors[bot]landhbJethro Beekman
authored
Merge #158
158: Add sysroot support for GNU based toolchains r=jethrogb a=landhb This PR adds sysroot detection for GNU based toolchains for targets like `aarch64-unknown-linux-musl`. This prevents bindgen from using incorrect headers when generating bindings. For instance when using cross, the aarch64 musl sysroot is installed in /usr/local/aarch64-linux-musl/ but bindgen/clang will attempt to look for headers in /usr/include unless `--sysroot` is provided. Co-authored-by: landhb <[email protected]> Co-authored-by: Jethro Beekman <[email protected]>
2 parents df3e7ae + f807323 commit c700c03

File tree

5 files changed

+68
-17
lines changed

5 files changed

+68
-17
lines changed

.travis.yml

+12-3
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,26 @@ addons:
2020
- clang-3.9
2121
- clang-11
2222
- cmake
23+
- qemu-user
2324
rust:
2425
- stable
25-
- beta
26-
- nightly
27-
- nightly-2021-03-25
2826
env:
27+
jobs:
28+
# Matrix build of 3 targets against Rust stable
29+
- TARGET=x86_64-unknown-linux-gnu ZLIB_INSTALLED=true AES_NI_SUPPORT=true
30+
- TARGET=aarch64-unknown-linux-musl
31+
- TARGET=x86_64-fortanix-unknown-sgx
2932
global:
3033
- RUST_BACKTRACE=1
3134
# Pinned to this particular nightly version because of core_io. This can be
3235
# re-pinned whenever core_io is updated to the latest nightly.
3336
- CORE_IO_NIGHTLY=nightly-2021-03-25
3437
- LLVM_CONFIG_PATH=llvm-config-3.9
38+
jobs:
39+
include:
40+
# Test additional Rust toolchains on x86_64
41+
- rust: beta
42+
- rust: nightly
43+
- rust: nightly-2021-03-25
3544
script:
3645
- ./ct.sh

ct.sh

+36-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
set -ex
33
cd "$(dirname "$0")"
44

@@ -9,26 +9,50 @@ if [ -z $TRAVIS_RUST_VERSION ]; then
99
exit 1
1010
fi
1111

12+
if [ "$TARGET" == "aarch64-unknown-linux-musl" ]; then
13+
pushd /tmp && wget https://musl.cc/aarch64-linux-musl-cross.tgz;
14+
tar -xzf aarch64-linux-musl-cross.tgz;
15+
popd;
16+
fi
17+
1218
export CFLAGS_x86_64_fortanix_unknown_sgx="-isystem/usr/include/x86_64-linux-gnu -mlvi-hardening -mllvm -x86-experimental-lvi-inline-asm-hardening"
1319
export CC_x86_64_fortanix_unknown_sgx=clang-11
20+
export CC_aarch64_unknown_linux_musl=/tmp/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
21+
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=/tmp/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
22+
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUNNER=qemu-aarch64
23+
24+
# Temporary workaround for MbedTLS 2.26.0 https://github.com/ARMmbed/mbedtls/pull/4237
25+
export CFLAGS_aarch64_unknown_linux_musl="-Wformat-truncation"
1426

15-
if [ $TRAVIS_RUST_VERSION = "stable" ] || [ $TRAVIS_RUST_VERSION = "beta" ] || [ $TRAVIS_RUST_VERSION = "nightly" ]; then
27+
if [ "$TRAVIS_RUST_VERSION" == "stable" ] || [ "$TRAVIS_RUST_VERSION" == "beta" ] || [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then
28+
# Install the rust toolchain
1629
rustup default $TRAVIS_RUST_VERSION
17-
# make sure that explicitly providing the default target works
18-
cargo test --target x86_64-unknown-linux-gnu
19-
cargo test --features zlib
20-
cargo test --features pkcs12
21-
cargo test --features pkcs12_rc2
22-
cargo test --features force_aesni_support
23-
cargo test --features dsa
30+
rustup target add --toolchain $TRAVIS_RUST_VERSION $TARGET
2431

25-
rustup target add --toolchain $TRAVIS_RUST_VERSION x86_64-fortanix-unknown-sgx
26-
cargo +$TRAVIS_RUST_VERSION test --no-run --target=x86_64-fortanix-unknown-sgx
32+
# The SGX target cannot be run under test like a ELF binary
33+
if [ "$TARGET" != "x86_64-fortanix-unknown-sgx" ]; then
34+
# make sure that explicitly providing the default target works
35+
cargo test --target $TARGET
36+
cargo test --features pkcs12 --target $TARGET
37+
cargo test --features pkcs12_rc2 --target $TARGET
38+
cargo test --features dsa --target $TARGET
39+
40+
# If zlib is installed, test the zlib feature
41+
if [ -n "$ZLIB_INSTALLED" ]; then
42+
cargo test --features zlib --target $TARGET
43+
fi
44+
45+
# If AES-NI is supported, test the feature
46+
if [ -n "$AES_NI_SUPPORT" ]; then
47+
cargo test --features force_aesni_support --target $TARGET
48+
fi
49+
else
50+
cargo +$TRAVIS_RUST_VERSION test --no-run --target=$TARGET
51+
fi
2752

2853
elif [ $TRAVIS_RUST_VERSION = $CORE_IO_NIGHTLY ]; then
2954
cargo +$CORE_IO_NIGHTLY test --no-default-features --features no_std_deps,rdrand,time
3055
cargo +$CORE_IO_NIGHTLY test --no-default-features --features no_std_deps,rdrand
31-
3256
else
3357
echo "Unknown version $TRAVIS_RUST_VERSION"
3458
exit 1

mbedtls-sys/build/bindgen.rs

+18
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ impl super::BuildConfig {
9898
cc.flag(cflag);
9999
}
100100

101+
// Determine the sysroot for this compiler so that bindgen
102+
// uses the correct headers
103+
let compiler = cc.get_compiler();
104+
if compiler.is_like_gnu() {
105+
let output = compiler.to_command().args(&["--print-sysroot"]).output();
106+
match output {
107+
Ok(sysroot) => {
108+
let path = std::str::from_utf8(&sysroot.stdout).expect("Malformed sysroot");
109+
let trimmed_path = path
110+
.strip_suffix("\r\n")
111+
.or(path.strip_suffix("\n"))
112+
.unwrap_or(&path);
113+
cc.flag(&format!("--sysroot={}", trimmed_path));
114+
}
115+
_ => {} // skip toolchains without a configured sysroot
116+
};
117+
}
118+
101119
let bindings = bindgen::builder()
102120
.clang_args(cc.get_compiler().args().iter().map(|arg| arg.to_str().unwrap()))
103121
.header_contents("bindgen-input.h", &input)

mbedtls/src/bignum/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl Mpi {
173173
mpi_write_string(
174174
&self.inner,
175175
radix,
176-
buf.as_mut_ptr() as *mut i8,
176+
buf.as_mut_ptr() as *mut _,
177177
buf.len(),
178178
&mut olen,
179179
)

mbedtls/src/pk/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const CUSTOM_PK_INFO: pk_info_t = {
131131
sign_func: None,
132132
verify_func: None,
133133
get_bitlen: None,
134-
name: b"\0" as *const u8 as *const i8,
134+
name: b"\0" as *const u8 as *const _,
135135
ctx_alloc_func: Some(alloc_custom_pk_ctx),
136136
ctx_free_func: Some(free_custom_pk_ctx),
137137
}

0 commit comments

Comments
 (0)