Skip to content
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
21 changes: 19 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ jobs:
- arm64-android
- i686-android
- x86_64-android
- aarch64-ios
- aarch64-ios-sim
- x86_64-ios
- i686-linux
- arm-linux
- aarch64-linux
Expand Down Expand Up @@ -102,6 +105,15 @@ jobs:
target: x86_64-linux-android
rust: stable
os: ubuntu-latest
- thing: aarch64-ios
target: aarch64-apple-ios
os: macos-latest
- thing: aarch64-ios-sim
target: aarch64-apple-ios-sim
os: macos-latest
- thing: x86_64-ios
target: x86_64-apple-ios
os: macos-latest
- thing: i686-linux
target: i686-unknown-linux-gnu
rust: stable
Expand Down Expand Up @@ -152,13 +164,18 @@ jobs:
- name: Set LIBCLANG_PATH
if: startsWith(matrix.os, 'windows')
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
- if: startsWith(matrix.os, 'windows')
- if: "startsWith(matrix.os, 'windows') && !contains(matrix.target, 'ios')"
# CI's Windows doesn't have require root certs
run: cargo test --workspace --exclude tokio-boring --exclude hyper-boring
name: Run tests (Windows)
- if: "!startsWith(matrix.os, 'windows')"
- if: "!startsWith(matrix.os, 'windows') && !contains(matrix.target, 'ios')"
Comment on lines -155 to +171
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? If it's because the tests were failing, why didn't they fail before this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not possible to run cargo test when building for iOS. It would produce test binaries, but they can't be executed on the host macOS. You'd need to start an iOS Simulator, wrap the binaries into iOS apps, upload the apps to the simulator, run them there, extract results, and post those back. That's too much hassle. I believe it's okay to skip this step until Rust ecosystem catches up.

So for iOS builds the tests are skipped, only checking that boring-sys is able to compile BoringSSL and that rustc can compile Rust code that should be using the library.

Copy link
Contributor Author

@ilammy ilammy Jan 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this reminds me. When CI does cargo test, it compiles for the host. That is, I believe that tests for Android targets are actually testing on the host Linux – not the Android 🤔


I guess I'll make another change to the CI to unify tests into three groups:

  • build only (maybe possible to run via emulation?)
  • build and run
  • build and run (except for hyper/tokio)

Ugh. When I added --target to other tests, basically only "stable", "macos-x86_64", "i686-msvc", "x86_64-msvc" ended up working. Everything else fails for one reason or the other: missing compilers, wrong linkers, etc.

run: cargo test
name: Run tests (not Windows)
- if: "contains(matrix.target, 'ios')"
# It's... theoretically possible to run tests on iPhone Simulator,
# but for now, make sure that BoringSSL only builds.
run: cargo check --target ${{ matrix.target }} --all-targets
name: Check tests (iOS)

test-fips:
name: Test FIPS integration
Expand Down
131 changes: 108 additions & 23 deletions boring-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,65 @@ const CMAKE_PARAMS_ANDROID_NDK: &[(&str, &[(&str, &str)])] = &[
("x86_64", &[("ANDROID_ABI", "x86_64")]),
];

fn cmake_params_android() -> &'static [(&'static str, &'static str)] {
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let cmake_params_android = if cfg!(feature = "ndk-old-gcc") {
CMAKE_PARAMS_ANDROID_NDK_OLD_GCC
} else {
CMAKE_PARAMS_ANDROID_NDK
};
for (android_arch, params) in cmake_params_android {
if *android_arch == arch {
return *params;
}
}
&[]
}

const CMAKE_PARAMS_IOS: &[(&str, &[(&str, &str)])] = &[
(
"aarch64",
"aarch64-apple-ios",
&[
("CMAKE_OSX_ARCHITECTURES", "arm64"),
("CMAKE_OSX_SYSROOT", "iphoneos"),
],
),
(
"x86_64",
"aarch64-apple-ios-sim",
&[
("CMAKE_OSX_ARCHITECTURES", "arm64"),
("CMAKE_OSX_SYSROOT", "iphonesimulator"),
],
),
(
"x86_64-apple-ios",
&[
("CMAKE_OSX_ARCHITECTURES", "x86_64"),
("CMAKE_OSX_SYSROOT", "iphonesimulator"),
],
),
];

fn cmake_params_ios() -> &'static [(&'static str, &'static str)] {
let target = std::env::var("TARGET").unwrap();
for (ios_target, params) in CMAKE_PARAMS_IOS {
if *ios_target == target {
return *params;
}
}
&[]
}

fn get_ios_sdk_name() -> &'static str {
for (name, value) in cmake_params_ios() {
if *name == "CMAKE_OSX_SYSROOT" {
return *value;
}
}
let target = std::env::var("TARGET").unwrap();
panic!("cannot find iOS SDK for {} in CMAKE_PARAMS_IOS", target);
}

/// Returns the platform-specific output path for lib.
///
/// MSVC generator on Windows place static libs in a target sub-folder,
Expand Down Expand Up @@ -106,24 +148,14 @@ fn get_boringssl_cmake_config() -> cmake::Config {
// Add platform-specific parameters.
match os.as_ref() {
"android" => {
let cmake_params_android = if cfg!(feature = "ndk-old-gcc") {
CMAKE_PARAMS_ANDROID_NDK_OLD_GCC
} else {
CMAKE_PARAMS_ANDROID_NDK
};

// We need ANDROID_NDK_HOME to be set properly.
println!("cargo:rerun-if-env-changed=ANDROID_NDK_HOME");
let android_ndk_home = std::env::var("ANDROID_NDK_HOME")
.expect("Please set ANDROID_NDK_HOME for Android build");
let android_ndk_home = std::path::Path::new(&android_ndk_home);
for (android_arch, params) in cmake_params_android {
if *android_arch == arch {
for (name, value) in *params {
eprintln!("android arch={} add {}={}", arch, name, value);
boringssl_cmake.define(name, value);
}
}
for (name, value) in cmake_params_android() {
eprintln!("android arch={} add {}={}", arch, name, value);
boringssl_cmake.define(name, value);
}
let toolchain_file = android_ndk_home.join("build/cmake/android.toolchain.cmake");
let toolchain_file = toolchain_file.to_str().unwrap();
Expand All @@ -138,13 +170,9 @@ fn get_boringssl_cmake_config() -> cmake::Config {
}

"ios" => {
for (ios_arch, params) in CMAKE_PARAMS_IOS {
if *ios_arch == arch {
for (name, value) in *params {
eprintln!("ios arch={} add {}={}", arch, name, value);
boringssl_cmake.define(name, value);
}
}
for (name, value) in cmake_params_ios() {
eprintln!("ios arch={} add {}={}", arch, name, value);
boringssl_cmake.define(name, value);
}

// Bitcode is always on.
Expand Down Expand Up @@ -227,6 +255,45 @@ fn verify_fips_clang_version() -> (&'static str, &'static str) {
unreachable!()
}

fn get_extra_clang_args_for_bindgen() -> Vec<String> {
let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();

let mut params = Vec::new();

// Add platform-specific parameters.
#[allow(clippy::single_match)]
match os.as_ref() {
"ios" => {
use std::io::Write;
// When cross-compiling for iOS, tell bindgen to use iOS sysroot,
// and *don't* use system headers of the host macOS.
let sdk = get_ios_sdk_name();
let output = std::process::Command::new("xcrun")
.args(["--show-sdk-path", "--sdk", sdk])
.output()
.unwrap();
if !output.status.success() {
if let Some(exit_code) = output.status.code() {
eprintln!("xcrun failed: exit code {}", exit_code);
} else {
eprintln!("xcrun failed: killed");
}
std::io::stderr().write_all(&output.stderr).unwrap();
// Uh... let's try anyway, I guess?
return params;
}
let mut sysroot = String::from_utf8(output.stdout).unwrap();
// There is typically a newline at the end which confuses clang.
sysroot.truncate(sysroot.trim_end().len());
params.push("-isysroot".to_string());
params.push(sysroot);
}
_ => {}
}

params
}

fn main() {
use std::env;

Expand Down Expand Up @@ -287,7 +354,8 @@ fn main() {
println!("cargo:rustc-link-lib=static=ssl");

// MacOS: Allow cdylib to link with undefined symbols
if cfg!(target_os = "macos") {
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
if target_os == "macos" {
println!("cargo:rustc-cdylib-link-arg=-Wl,-undefined,dynamic_lookup");
}

Expand All @@ -313,8 +381,25 @@ fn main() {
.layout_tests(true)
.prepend_enum_name(true)
.rustfmt_bindings(true)
.clang_args(get_extra_clang_args_for_bindgen())
.clang_args(&["-I", &include_path]);

let target = std::env::var("TARGET").unwrap();
match target.as_ref() {
// bindgen produces alignment tests that cause undefined behavior [1]
// when applied to explicitly unaligned types like OSUnalignedU64.
//
// There is no way to disable these tests for only some types
// and it's not nice to suppress warnings for the entire crate,
// so let's disable all alignment tests and hope for the best.
//
// [1]: https://github.com/rust-lang/rust-bindgen/issues/1651
"aarch64-apple-ios" | "aarch64-apple-ios-sim" => {
builder = builder.layout_tests(false);
}
_ => {}
}

let headers = [
"aes.h",
"asn1_mac.h",
Expand Down