Skip to content

Commit

Permalink
Check for CMAKE_TOOLCHAIN_FILE when creating cmake config
Browse files Browse the repository at this point in the history
We don't do anything fancy anymore for non-cross builds
and when a specific CMAKE_TOOLCHAIN_FILE is specified.
  • Loading branch information
nox committed Oct 16, 2023
1 parent 16958ce commit 9347e6d
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 90 deletions.
2 changes: 2 additions & 0 deletions boring-sys/build/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub(crate) struct Env {
pub(crate) debug: Option<OsString>,
pub(crate) opt_level: Option<OsString>,
pub(crate) android_ndk_home: Option<PathBuf>,
pub(crate) cmake_toolchain_file: Option<PathBuf>,
}

impl Config {
Expand Down Expand Up @@ -148,6 +149,7 @@ impl Env {
debug: target_var("DEBUG"),
opt_level: target_var("OPT_LEVEL"),
android_ndk_home: target_var("ANDROID_NDK_HOME").map(Into::into),
cmake_toolchain_file: target_var("CMAKE_TOOLCHAIN_FILE").map(Into::into),
}
}
}
Expand Down
186 changes: 96 additions & 90 deletions boring-sys/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,107 +185,113 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
let src_path = get_boringssl_source_path(config);
let mut boringssl_cmake = cmake::Config::new(src_path);

if config.host != config.target {
// Add platform-specific parameters for cross-compilation.
match &*config.target_os {
"android" => {
// We need ANDROID_NDK_HOME to be set properly.
let android_ndk_home = config
.env
.android_ndk_home
.as_ref()
.expect("Please set ANDROID_NDK_HOME for Android build");
for (name, value) in cmake_params_android(config) {
eprintln!("android arch={} add {}={}", config.target_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();
eprintln!("android toolchain={}", toolchain_file);
boringssl_cmake.define("CMAKE_TOOLCHAIN_FILE", toolchain_file);

// 21 is the minimum level tested. You can give higher value.
boringssl_cmake.define("ANDROID_NATIVE_API_LEVEL", "21");
boringssl_cmake.define("ANDROID_STL", "c++_shared");
if config.host == config.target {
return boringssl_cmake;
}

if config.env.cmake_toolchain_file.is_some() {
return boringssl_cmake;
}

// Add platform-specific parameters for cross-compilation.
match &*config.target_os {
"android" => {
// We need ANDROID_NDK_HOME to be set properly.
let android_ndk_home = config
.env
.android_ndk_home
.as_ref()
.expect("Please set ANDROID_NDK_HOME for Android build");
for (name, value) in cmake_params_android(config) {
eprintln!("android arch={} add {}={}", config.target_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();
eprintln!("android toolchain={}", toolchain_file);
boringssl_cmake.define("CMAKE_TOOLCHAIN_FILE", toolchain_file);

// 21 is the minimum level tested. You can give higher value.
boringssl_cmake.define("ANDROID_NATIVE_API_LEVEL", "21");
boringssl_cmake.define("ANDROID_STL", "c++_shared");
}

"macos" => {
for (name, value) in cmake_params_apple(config) {
eprintln!("macos arch={} add {}={}", config.target_arch, name, value);
boringssl_cmake.define(name, value);
}
"macos" => {
for (name, value) in cmake_params_apple(config) {
eprintln!("macos arch={} add {}={}", config.target_arch, name, value);
boringssl_cmake.define(name, value);
}
}

"ios" => {
for (name, value) in cmake_params_apple(config) {
eprintln!("ios arch={} add {}={}", config.target_arch, name, value);
boringssl_cmake.define(name, value);
}
"ios" => {
for (name, value) in cmake_params_apple(config) {
eprintln!("ios arch={} add {}={}", config.target_arch, name, value);
boringssl_cmake.define(name, value);
}

// Bitcode is always on.
let bitcode_cflag = "-fembed-bitcode";
// Bitcode is always on.
let bitcode_cflag = "-fembed-bitcode";

// Hack for Xcode 10.1.
let target_cflag = if config.target_arch == "x86_64" {
"-target x86_64-apple-ios-simulator"
} else {
""
};
// Hack for Xcode 10.1.
let target_cflag = if config.target_arch == "x86_64" {
"-target x86_64-apple-ios-simulator"
} else {
""
};

let cflag = format!("{} {}", bitcode_cflag, target_cflag);
boringssl_cmake.define("CMAKE_ASM_FLAGS", &cflag);
boringssl_cmake.cflag(&cflag);
}
let cflag = format!("{} {}", bitcode_cflag, target_cflag);
boringssl_cmake.define("CMAKE_ASM_FLAGS", &cflag);
boringssl_cmake.cflag(&cflag);
}

"windows" => {
if config.host.contains("windows") {
// BoringSSL's CMakeLists.txt isn't set up for cross-compiling using Visual Studio.
// Disable assembly support so that it at least builds.
boringssl_cmake.define("OPENSSL_NO_ASM", "YES");
}
"windows" => {
if config.host.contains("windows") {
// BoringSSL's CMakeLists.txt isn't set up for cross-compiling using Visual Studio.
// Disable assembly support so that it at least builds.
boringssl_cmake.define("OPENSSL_NO_ASM", "YES");
}
}

"linux" => match &*config.target_arch {
"x86" => {
boringssl_cmake.define(
"CMAKE_TOOLCHAIN_FILE",
// `src_path` can be a path relative to the manifest dir, but
// cmake hates that.
config
.manifest_dir
.join(src_path)
.join("src/util/32-bit-toolchain.cmake")
.as_os_str(),
);
}
"aarch64" => {
boringssl_cmake.define(
"CMAKE_TOOLCHAIN_FILE",
config
.manifest_dir
.join("cmake/aarch64-linux.cmake")
.as_os_str(),
);
}
"arm" => {
boringssl_cmake.define(
"CMAKE_TOOLCHAIN_FILE",
config
.manifest_dir
.join("cmake/armv7-linux.cmake")
.as_os_str(),
);
}
_ => {
eprintln!(
"warning: no toolchain file configured by boring-sys for {}",
config.target
);
}
},
"linux" => match &*config.target_arch {
"x86" => {
boringssl_cmake.define(
"CMAKE_TOOLCHAIN_FILE",
// `src_path` can be a path relative to the manifest dir, but
// cmake hates that.
config
.manifest_dir
.join(src_path)
.join("src/util/32-bit-toolchain.cmake")
.as_os_str(),
);
}
"aarch64" => {
boringssl_cmake.define(
"CMAKE_TOOLCHAIN_FILE",
config
.manifest_dir
.join("cmake/aarch64-linux.cmake")
.as_os_str(),
);
}
"arm" => {
boringssl_cmake.define(
"CMAKE_TOOLCHAIN_FILE",
config
.manifest_dir
.join("cmake/armv7-linux.cmake")
.as_os_str(),
);
}
_ => {
eprintln!(
"warning: no toolchain file configured by boring-sys for {}",
config.target
);
}
},

_ => {}
}
_ => {}
}

boringssl_cmake
Expand Down

0 comments on commit 9347e6d

Please sign in to comment.