2016-01-21 01:14:01 +00:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2023-02-03 06:37:52 +00:00
|
|
|
use std::{
|
|
|
|
env,
|
|
|
|
ffi::OsString,
|
|
|
|
fs, io,
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
process::Command,
|
|
|
|
};
|
2016-01-21 01:03:24 +00:00
|
|
|
|
2022-05-13 21:19:25 +00:00
|
|
|
include!("src/env.rs");
|
2018-11-06 09:58:57 +00:00
|
|
|
|
|
|
|
macro_rules! info {
|
|
|
|
($($args:tt)*) => { println!($($args)*) }
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! warning {
|
|
|
|
($arg:tt, $($args:tt)*) => {
|
|
|
|
println!(concat!(concat!("cargo:warning=\"", $arg), "\""), $($args)*)
|
2017-11-27 13:53:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-14 07:23:49 +00:00
|
|
|
fn read_and_watch_env_impl<T, F>(name: &str, env_getter: F) -> Option<T>
|
|
|
|
where
|
|
|
|
F: Fn(&str) -> Option<T>,
|
|
|
|
{
|
|
|
|
let prefix = env::var("TARGET").unwrap().to_uppercase().replace('-', "_");
|
|
|
|
let prefixed_name = format!("{}_{}", prefix, name);
|
|
|
|
|
|
|
|
println!("cargo:rerun-if-env-changed={}", prefixed_name);
|
|
|
|
if let Some(value) = env_getter(&prefixed_name) {
|
|
|
|
return Some(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("cargo:rerun-if-env-changed={}", name);
|
|
|
|
env_getter(name)
|
|
|
|
}
|
|
|
|
|
2022-06-24 06:54:29 +00:00
|
|
|
fn read_and_watch_env(name: &str) -> Result<String, env::VarError> {
|
2024-07-14 07:23:49 +00:00
|
|
|
read_and_watch_env_impl(name, |n| env::var(n).ok()).ok_or(env::VarError::NotPresent)
|
2022-06-24 06:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn read_and_watch_env_os(name: &str) -> Option<OsString> {
|
2024-07-14 07:23:49 +00:00
|
|
|
read_and_watch_env_impl(name, |n| env::var_os(n))
|
2022-06-24 06:54:29 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 06:37:52 +00:00
|
|
|
fn copy_recursively(src: &Path, dst: &Path) -> io::Result<()> {
|
|
|
|
if !dst.exists() {
|
|
|
|
fs::create_dir_all(dst)?;
|
|
|
|
}
|
|
|
|
for entry in fs::read_dir(src)? {
|
|
|
|
let entry = entry?;
|
|
|
|
let ft = entry.file_type()?;
|
|
|
|
if ft.is_dir() {
|
|
|
|
// There should be very few layer in the project, use recusion to keep simple.
|
|
|
|
copy_recursively(&entry.path(), &dst.join(entry.file_name()))?;
|
|
|
|
} else {
|
|
|
|
fs::copy(entry.path(), dst.join(entry.file_name()))?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2024-04-01 03:28:04 +00:00
|
|
|
fn expect_env(name: &str) -> String {
|
|
|
|
env::var(name).unwrap_or_else(|_| panic!("{} was not set", name))
|
|
|
|
}
|
|
|
|
|
2020-07-17 13:22:46 +00:00
|
|
|
// TODO: split main functions and remove following allow.
|
|
|
|
#[allow(clippy::cognitive_complexity)]
|
2016-01-21 01:03:24 +00:00
|
|
|
fn main() {
|
2024-04-01 03:28:04 +00:00
|
|
|
let target = expect_env("TARGET");
|
|
|
|
let host = expect_env("HOST");
|
|
|
|
let num_jobs = expect_env("NUM_JOBS");
|
2018-05-02 08:04:09 +00:00
|
|
|
let out_dir = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR was not set"));
|
|
|
|
let src_dir = env::current_dir().expect("failed to get current directory");
|
2024-04-01 03:28:04 +00:00
|
|
|
let version = expect_env("CARGO_PKG_VERSION");
|
|
|
|
let je_version = version
|
|
|
|
.split_once('+')
|
|
|
|
.expect("jemalloc version is missing")
|
|
|
|
.1;
|
2017-11-27 18:07:57 +00:00
|
|
|
|
2020-07-17 13:22:46 +00:00
|
|
|
info!("TARGET={}", target);
|
|
|
|
info!("HOST={}", host);
|
|
|
|
info!("NUM_JOBS={}", num_jobs);
|
2018-11-06 09:58:57 +00:00
|
|
|
info!("OUT_DIR={:?}", out_dir);
|
|
|
|
let build_dir = out_dir.join("build");
|
|
|
|
info!("BUILD_DIR={:?}", build_dir);
|
|
|
|
info!("SRC_DIR={:?}", src_dir);
|
2018-11-02 13:53:00 +00:00
|
|
|
|
2018-11-06 09:58:57 +00:00
|
|
|
if UNSUPPORTED_TARGETS.iter().any(|i| target.contains(i)) {
|
|
|
|
panic!("jemalloc does not support target: {}", target);
|
2018-11-02 13:53:00 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 09:58:57 +00:00
|
|
|
if UNTESTED_TARGETS.iter().any(|i| target.contains(i)) {
|
|
|
|
warning!("jemalloc support for `{}` is untested", target);
|
2018-11-02 13:53:00 +00:00
|
|
|
}
|
|
|
|
|
2019-09-30 06:56:09 +00:00
|
|
|
let mut use_prefix =
|
|
|
|
env::var("CARGO_FEATURE_UNPREFIXED_MALLOC_ON_SUPPORTED_PLATFORMS").is_err();
|
|
|
|
|
2022-05-13 21:19:25 +00:00
|
|
|
if !use_prefix
|
|
|
|
&& NO_UNPREFIXED_MALLOC_TARGETS
|
|
|
|
.iter()
|
|
|
|
.any(|i| target.contains(i))
|
|
|
|
{
|
2019-09-30 06:56:09 +00:00
|
|
|
warning!(
|
|
|
|
"Unprefixed `malloc` requested on unsupported platform `{}` => using prefixed `malloc`",
|
|
|
|
target
|
|
|
|
);
|
|
|
|
use_prefix = true;
|
|
|
|
}
|
|
|
|
|
2019-09-30 09:20:40 +00:00
|
|
|
// this has to occur before the early return when JEMALLOC_OVERRIDE is set
|
2019-09-30 06:56:09 +00:00
|
|
|
if use_prefix {
|
|
|
|
println!("cargo:rustc-cfg=prefixed");
|
|
|
|
}
|
|
|
|
|
2022-06-24 06:54:29 +00:00
|
|
|
if let Some(jemalloc) = read_and_watch_env_os("JEMALLOC_OVERRIDE") {
|
2018-11-06 09:58:57 +00:00
|
|
|
info!("jemalloc override set");
|
2016-01-21 01:03:24 +00:00
|
|
|
let jemalloc = PathBuf::from(jemalloc);
|
2018-11-06 09:58:57 +00:00
|
|
|
assert!(
|
|
|
|
jemalloc.exists(),
|
|
|
|
"Path to `jemalloc` in `JEMALLOC_OVERRIDE={}` does not exist",
|
|
|
|
jemalloc.display()
|
|
|
|
);
|
2018-05-03 15:00:07 +00:00
|
|
|
println!(
|
|
|
|
"cargo:rustc-link-search=native={}",
|
|
|
|
jemalloc.parent().unwrap().display()
|
|
|
|
);
|
2016-01-21 01:03:24 +00:00
|
|
|
let stem = jemalloc.file_stem().unwrap().to_str().unwrap();
|
|
|
|
let name = jemalloc.file_name().unwrap().to_str().unwrap();
|
2018-05-03 15:00:07 +00:00
|
|
|
let kind = if name.ends_with(".a") {
|
|
|
|
"static"
|
|
|
|
} else {
|
|
|
|
"dylib"
|
|
|
|
};
|
2016-01-21 01:03:24 +00:00
|
|
|
println!("cargo:rustc-link-lib={}={}", kind, &stem[3..]);
|
2018-05-03 15:00:07 +00:00
|
|
|
return;
|
2016-01-21 01:03:24 +00:00
|
|
|
}
|
2018-05-02 08:04:09 +00:00
|
|
|
// Disable -Wextra warnings - jemalloc doesn't compile free of warnings with
|
|
|
|
// it enabled: https://github.com/jemalloc/jemalloc/issues/1196
|
|
|
|
let compiler = cc::Build::new().extra_warnings(false).get_compiler();
|
2018-05-03 15:00:07 +00:00
|
|
|
let cflags = compiler
|
|
|
|
.args()
|
|
|
|
.iter()
|
|
|
|
.map(|s| s.to_str().unwrap())
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join(" ");
|
2018-11-06 09:58:57 +00:00
|
|
|
info!("CC={:?}", compiler.path());
|
|
|
|
info!("CFLAGS={:?}", cflags);
|
2018-05-02 08:04:09 +00:00
|
|
|
|
2019-03-25 16:00:43 +00:00
|
|
|
assert!(out_dir.exists(), "OUT_DIR does not exist");
|
2020-07-21 03:18:43 +00:00
|
|
|
let jemalloc_repo_dir = PathBuf::from("jemalloc");
|
2019-03-25 16:00:43 +00:00
|
|
|
info!("JEMALLOC_REPO_DIR={:?}", jemalloc_repo_dir);
|
|
|
|
|
2020-07-21 03:18:43 +00:00
|
|
|
if build_dir.exists() {
|
|
|
|
fs::remove_dir_all(build_dir.clone()).unwrap();
|
2018-05-02 22:23:40 +00:00
|
|
|
}
|
2018-05-03 14:41:15 +00:00
|
|
|
// Copy jemalloc submodule to the OUT_DIR
|
2023-02-03 06:37:52 +00:00
|
|
|
copy_recursively(&jemalloc_repo_dir, &build_dir)
|
2018-11-18 11:28:36 +00:00
|
|
|
.expect("failed to copy jemalloc source code to OUT_DIR");
|
2020-07-21 03:18:43 +00:00
|
|
|
assert!(build_dir.exists());
|
2018-05-02 22:23:40 +00:00
|
|
|
|
2018-05-02 15:18:59 +00:00
|
|
|
// Configuration files
|
2024-04-01 03:28:04 +00:00
|
|
|
let config_files = ["configure"];
|
2018-11-06 09:58:57 +00:00
|
|
|
|
2020-07-21 03:18:43 +00:00
|
|
|
// Copy the configuration files to jemalloc's source directory
|
|
|
|
for f in &config_files {
|
|
|
|
fs::copy(Path::new("configure").join(f), build_dir.join(f))
|
|
|
|
.expect("failed to copy config file to OUT_DIR");
|
2018-05-02 15:18:59 +00:00
|
|
|
}
|
2018-05-02 14:06:16 +00:00
|
|
|
|
2018-05-02 08:04:09 +00:00
|
|
|
// Run configure:
|
2020-07-21 03:18:43 +00:00
|
|
|
let configure = build_dir.join("configure");
|
2016-01-21 01:03:24 +00:00
|
|
|
let mut cmd = Command::new("sh");
|
2018-05-03 15:00:07 +00:00
|
|
|
cmd.arg(
|
|
|
|
configure
|
|
|
|
.to_str()
|
|
|
|
.unwrap()
|
|
|
|
.replace("C:\\", "/c/")
|
2022-05-24 23:31:42 +00:00
|
|
|
.replace('\\', "/"),
|
2018-10-30 19:34:36 +00:00
|
|
|
)
|
|
|
|
.current_dir(&build_dir)
|
|
|
|
.env("CC", compiler.path())
|
|
|
|
.env("CFLAGS", cflags.clone())
|
|
|
|
.env("LDFLAGS", cflags.clone())
|
2020-07-17 13:22:46 +00:00
|
|
|
.env("CPPFLAGS", cflags)
|
2024-04-01 03:28:04 +00:00
|
|
|
.arg(format!("--with-version={je_version}"))
|
2022-05-13 21:19:25 +00:00
|
|
|
.arg("--disable-cxx")
|
|
|
|
.arg("--enable-doc=no")
|
|
|
|
.arg("--enable-shared=no");
|
2016-01-21 01:03:24 +00:00
|
|
|
|
2018-10-15 12:55:26 +00:00
|
|
|
if target.contains("ios") {
|
|
|
|
// newer iOS deviced have 16kb page sizes:
|
2019-04-05 14:19:10 +00:00
|
|
|
// closed: https://github.com/gnzlbg/jemallocator/issues/68
|
2018-10-15 12:55:26 +00:00
|
|
|
cmd.arg("--with-lg-page=14");
|
|
|
|
}
|
|
|
|
|
2018-11-06 09:58:57 +00:00
|
|
|
// collect `malloc_conf` string:
|
2018-10-17 13:29:38 +00:00
|
|
|
let mut malloc_conf = String::new();
|
|
|
|
|
2018-11-06 09:58:57 +00:00
|
|
|
if let Some(bg) = BackgroundThreadSupport::new(&target) {
|
|
|
|
// `jemalloc` is compiled with background thread run-time support on
|
|
|
|
// available platforms by default so there is nothing to do to enable
|
|
|
|
// it.
|
2018-10-24 13:00:40 +00:00
|
|
|
|
2018-11-06 09:58:57 +00:00
|
|
|
if bg.always_enabled {
|
2018-10-24 13:00:40 +00:00
|
|
|
// Background thread support does not enable background threads at
|
|
|
|
// run-time, just support for enabling them via run-time configuration
|
|
|
|
// options (they are disabled by default)
|
|
|
|
|
|
|
|
// The `enable_background_threads` cargo feature forces background
|
|
|
|
// threads to be enabled at run-time by default:
|
|
|
|
malloc_conf += "background_thread:true";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Background thread run-time support is disabled by
|
|
|
|
// disabling background threads at compile-time:
|
2018-10-17 13:29:38 +00:00
|
|
|
malloc_conf += "background_thread:false";
|
|
|
|
}
|
|
|
|
|
2022-06-24 06:54:29 +00:00
|
|
|
if let Ok(malloc_conf_opts) = read_and_watch_env("JEMALLOC_SYS_WITH_MALLOC_CONF") {
|
2022-09-29 07:25:17 +00:00
|
|
|
if !malloc_conf.is_empty() {
|
|
|
|
malloc_conf.push(',');
|
|
|
|
}
|
|
|
|
malloc_conf.push_str(&malloc_conf_opts);
|
2018-10-17 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !malloc_conf.is_empty() {
|
2018-11-06 09:58:57 +00:00
|
|
|
info!("--with-malloc-conf={}", malloc_conf);
|
2023-02-06 07:30:20 +00:00
|
|
|
cmd.arg(format!("--with-malloc-conf={malloc_conf}"));
|
2018-10-17 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 06:54:29 +00:00
|
|
|
if let Ok(lg_page) = read_and_watch_env("JEMALLOC_SYS_WITH_LG_PAGE") {
|
2018-11-06 09:58:57 +00:00
|
|
|
info!("--with-lg-page={}", lg_page);
|
2023-02-06 07:30:20 +00:00
|
|
|
cmd.arg(format!("--with-lg-page={lg_page}"));
|
2018-10-17 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 06:54:29 +00:00
|
|
|
if let Ok(lg_hugepage) = read_and_watch_env("JEMALLOC_SYS_WITH_LG_HUGEPAGE") {
|
2018-11-06 09:58:57 +00:00
|
|
|
info!("--with-lg-hugepage={}", lg_hugepage);
|
2023-02-06 07:30:20 +00:00
|
|
|
cmd.arg(format!("--with-lg-hugepage={lg_hugepage}"));
|
2018-10-17 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 06:54:29 +00:00
|
|
|
if let Ok(lg_quantum) = read_and_watch_env("JEMALLOC_SYS_WITH_LG_QUANTUM") {
|
2018-11-06 09:58:57 +00:00
|
|
|
info!("--with-lg-quantum={}", lg_quantum);
|
2023-02-06 07:30:20 +00:00
|
|
|
cmd.arg(format!("--with-lg-quantum={lg_quantum}"));
|
2018-10-17 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 06:54:29 +00:00
|
|
|
if let Ok(lg_vaddr) = read_and_watch_env("JEMALLOC_SYS_WITH_LG_VADDR") {
|
2018-11-06 09:58:57 +00:00
|
|
|
info!("--with-lg-vaddr={}", lg_vaddr);
|
2023-02-06 07:30:20 +00:00
|
|
|
cmd.arg(format!("--with-lg-vaddr={lg_vaddr}"));
|
2018-05-22 14:56:01 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 05:11:34 +00:00
|
|
|
if use_prefix {
|
|
|
|
cmd.arg("--with-jemalloc-prefix=_rjem_");
|
2018-11-06 09:58:57 +00:00
|
|
|
info!("--with-jemalloc-prefix=_rjem_");
|
2018-06-24 05:11:34 +00:00
|
|
|
}
|
2017-07-07 18:07:16 +00:00
|
|
|
|
2018-06-24 20:14:48 +00:00
|
|
|
cmd.arg("--with-private-namespace=_rjem_");
|
|
|
|
|
2018-11-06 09:58:57 +00:00
|
|
|
if env::var("CARGO_FEATURE_DEBUG").is_ok() {
|
|
|
|
info!("CARGO_FEATURE_DEBUG set");
|
2016-01-21 01:03:24 +00:00
|
|
|
cmd.arg("--enable-debug");
|
|
|
|
}
|
|
|
|
|
2018-11-06 09:58:57 +00:00
|
|
|
if env::var("CARGO_FEATURE_PROFILING").is_ok() {
|
|
|
|
info!("CARGO_FEATURE_PROFILING set");
|
2016-08-07 07:55:49 +00:00
|
|
|
cmd.arg("--enable-prof");
|
|
|
|
}
|
2018-07-12 10:51:07 +00:00
|
|
|
|
2018-11-06 09:58:57 +00:00
|
|
|
if env::var("CARGO_FEATURE_STATS").is_ok() {
|
|
|
|
info!("CARGO_FEATURE_STATS set");
|
2018-07-12 10:51:07 +00:00
|
|
|
cmd.arg("--enable-stats");
|
2024-05-10 02:41:40 +00:00
|
|
|
} else {
|
|
|
|
info!("CARGO_FEATURE_STATS not set");
|
|
|
|
cmd.arg("--disable-stats");
|
2018-07-12 10:51:07 +00:00
|
|
|
}
|
|
|
|
|
2019-03-19 22:28:36 +00:00
|
|
|
if env::var("CARGO_FEATURE_DISABLE_INITIAL_EXEC_TLS").is_ok() {
|
|
|
|
info!("CARGO_FEATURE_DISABLE_INITIAL_EXEC_TLS set");
|
|
|
|
cmd.arg("--disable-initial-exec-tls");
|
|
|
|
}
|
|
|
|
|
2023-04-18 06:51:21 +00:00
|
|
|
if env::var("CARGO_FEATURE_DISABLE_CACHE_OBLIVIOUS").is_ok() {
|
|
|
|
info!("CARGO_FEATURE_DISABLE_CACHE_OBLIVIOUS set");
|
|
|
|
cmd.arg("--disable-cache-oblivious");
|
|
|
|
}
|
|
|
|
|
2024-10-23 08:08:50 +00:00
|
|
|
if env::var("CARGO_FEATURE_FILL").is_ok() {
|
|
|
|
info!("CARGO_FEATURE_FILL set");
|
|
|
|
cmd.arg("--enable-fill");
|
|
|
|
}
|
|
|
|
|
2017-11-27 13:53:07 +00:00
|
|
|
cmd.arg(format!("--host={}", gnu_target(&target)));
|
|
|
|
cmd.arg(format!("--build={}", gnu_target(&host)));
|
2016-01-21 01:03:24 +00:00
|
|
|
cmd.arg(format!("--prefix={}", out_dir.display()));
|
|
|
|
|
2020-07-21 03:18:43 +00:00
|
|
|
run_and_log(&mut cmd, &build_dir.join("config.log"));
|
2017-11-06 11:34:30 +00:00
|
|
|
|
2018-05-02 08:04:09 +00:00
|
|
|
// Make:
|
2018-11-06 09:58:57 +00:00
|
|
|
let make = make_cmd(&host);
|
2017-11-06 11:34:30 +00:00
|
|
|
run(Command::new(make)
|
2018-05-02 08:04:09 +00:00
|
|
|
.current_dir(&build_dir)
|
2018-05-03 15:00:07 +00:00
|
|
|
.arg("-j")
|
|
|
|
.arg(num_jobs.clone()));
|
2018-05-02 08:04:09 +00:00
|
|
|
|
2022-06-24 06:54:29 +00:00
|
|
|
// Skip watching this environment variables to avoid rebuild in CI.
|
2018-11-06 09:58:57 +00:00
|
|
|
if env::var("JEMALLOC_SYS_RUN_JEMALLOC_TESTS").is_ok() {
|
|
|
|
info!("Building and running jemalloc tests...");
|
2018-05-02 08:04:09 +00:00
|
|
|
// Make tests:
|
|
|
|
run(Command::new(make)
|
|
|
|
.current_dir(&build_dir)
|
2018-05-03 15:00:07 +00:00
|
|
|
.arg("-j")
|
|
|
|
.arg(num_jobs.clone())
|
2018-05-02 08:04:09 +00:00
|
|
|
.arg("tests"));
|
|
|
|
|
|
|
|
// Run tests:
|
2020-07-21 03:18:43 +00:00
|
|
|
run(Command::new(make).current_dir(&build_dir).arg("check"));
|
2018-05-02 08:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make install:
|
|
|
|
run(Command::new(make)
|
|
|
|
.current_dir(&build_dir)
|
|
|
|
.arg("install_lib_static")
|
|
|
|
.arg("install_include")
|
2018-05-03 15:00:07 +00:00
|
|
|
.arg("-j")
|
2020-07-17 13:22:46 +00:00
|
|
|
.arg(num_jobs));
|
2016-01-21 01:03:24 +00:00
|
|
|
|
|
|
|
println!("cargo:root={}", out_dir.display());
|
|
|
|
|
|
|
|
// Linkage directives to pull in jemalloc and its dependencies.
|
|
|
|
//
|
|
|
|
// On some platforms we need to be sure to link in `pthread` which jemalloc
|
|
|
|
// depends on, and specifically on android we need to also link to libgcc.
|
|
|
|
// Currently jemalloc is compiled with gcc which will generate calls to
|
|
|
|
// intrinsics that are libgcc specific (e.g. those intrinsics aren't present in
|
|
|
|
// libcompiler-rt), so link that in to get that support.
|
|
|
|
if target.contains("windows") {
|
|
|
|
println!("cargo:rustc-link-lib=static=jemalloc");
|
|
|
|
} else {
|
|
|
|
println!("cargo:rustc-link-lib=static=jemalloc_pic");
|
|
|
|
}
|
|
|
|
println!("cargo:rustc-link-search=native={}/lib", build_dir.display());
|
|
|
|
if target.contains("android") {
|
|
|
|
println!("cargo:rustc-link-lib=gcc");
|
|
|
|
} else if !target.contains("windows") {
|
2022-05-13 21:19:25 +00:00
|
|
|
println!("cargo:rustc-link-arg=-pthread");
|
2016-01-21 01:03:24 +00:00
|
|
|
}
|
2021-09-17 08:52:44 +00:00
|
|
|
// GCC may generate a __atomic_exchange_1 library call which requires -latomic
|
|
|
|
// during the final linking. https://github.com/riscv-collab/riscv-gcc/issues/12
|
|
|
|
if target.contains("riscv") {
|
|
|
|
println!("cargo:rustc-link-lib=atomic");
|
|
|
|
}
|
2018-10-17 13:29:38 +00:00
|
|
|
println!("cargo:rerun-if-changed=jemalloc");
|
2024-05-05 08:45:27 +00:00
|
|
|
|
|
|
|
if target.contains("android") {
|
|
|
|
// These symbols are used by jemalloc on android but the really old android
|
|
|
|
// we're building on doesn't have them defined, so just make sure the symbols
|
|
|
|
// are available.
|
|
|
|
cc::Build::new()
|
|
|
|
.file("src/pthread_atfork.c")
|
|
|
|
.compile("pthread_atfork");
|
|
|
|
println!("cargo:rerun-if-changed=src/pthread_atfork.c");
|
|
|
|
}
|
2016-01-21 01:03:24 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 03:18:43 +00:00
|
|
|
fn run_and_log(cmd: &mut Command, log_file: &Path) {
|
|
|
|
execute(cmd, || {
|
|
|
|
run(Command::new("tail").arg("-n").arg("100").arg(log_file));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-01-21 01:03:24 +00:00
|
|
|
fn run(cmd: &mut Command) {
|
2020-07-21 03:18:43 +00:00
|
|
|
execute(cmd, || ());
|
|
|
|
}
|
|
|
|
|
|
|
|
fn execute(cmd: &mut Command, on_fail: impl FnOnce()) {
|
2023-02-06 07:30:20 +00:00
|
|
|
println!("running: {cmd:?}");
|
2016-01-21 01:03:24 +00:00
|
|
|
let status = match cmd.status() {
|
|
|
|
Ok(status) => status,
|
|
|
|
Err(e) => panic!("failed to execute command: {}", e),
|
|
|
|
};
|
|
|
|
if !status.success() {
|
2020-07-21 03:18:43 +00:00
|
|
|
on_fail();
|
2018-05-03 15:00:07 +00:00
|
|
|
panic!(
|
|
|
|
"command did not execute successfully: {:?}\n\
|
|
|
|
expected success, got: {}",
|
|
|
|
cmd, status
|
|
|
|
);
|
2016-01-21 01:03:24 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-06 09:58:57 +00:00
|
|
|
|
|
|
|
fn gnu_target(target: &str) -> String {
|
|
|
|
match target {
|
|
|
|
"i686-pc-windows-msvc" => "i686-pc-win32".to_string(),
|
|
|
|
"x86_64-pc-windows-msvc" => "x86_64-pc-win32".to_string(),
|
|
|
|
"i686-pc-windows-gnu" => "i686-w64-mingw32".to_string(),
|
|
|
|
"x86_64-pc-windows-gnu" => "x86_64-w64-mingw32".to_string(),
|
2019-09-30 09:20:40 +00:00
|
|
|
"armv7-linux-androideabi" => "arm-linux-androideabi".to_string(),
|
2022-09-29 07:25:17 +00:00
|
|
|
"riscv64gc-unknown-linux-gnu" => "riscv64-linux-gnu".to_string(),
|
2024-01-30 10:59:16 +00:00
|
|
|
"riscv64gc-unknown-linux-musl" => "riscv64-linux-musl".to_string(),
|
2018-11-06 09:58:57 +00:00
|
|
|
s => s.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_cmd(host: &str) -> &'static str {
|
2024-02-19 11:10:03 +00:00
|
|
|
const GMAKE_HOSTS: &[&str] = &[
|
|
|
|
"bitrig",
|
|
|
|
"dragonfly",
|
|
|
|
"freebsd",
|
|
|
|
"netbsd",
|
|
|
|
"openbsd",
|
|
|
|
"chimera-linux",
|
|
|
|
];
|
2018-11-06 09:58:57 +00:00
|
|
|
if GMAKE_HOSTS.iter().any(|i| host.contains(i)) {
|
|
|
|
"gmake"
|
2018-11-10 19:04:49 +00:00
|
|
|
} else if host.contains("windows") {
|
|
|
|
"mingw32-make"
|
2018-11-06 09:58:57 +00:00
|
|
|
} else {
|
|
|
|
"make"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct BackgroundThreadSupport {
|
|
|
|
always_enabled: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BackgroundThreadSupport {
|
|
|
|
fn new(target: &str) -> Option<Self> {
|
|
|
|
let runtime_support = env::var("CARGO_FEATURE_BACKGROUND_THREADS_RUNTIME_SUPPORT").is_ok();
|
|
|
|
let always_enabled = env::var("CARGO_FEATURE_BACKGROUND_THREADS").is_ok();
|
|
|
|
|
|
|
|
if !runtime_support {
|
|
|
|
assert!(
|
|
|
|
!always_enabled,
|
|
|
|
"enabling `background_threads` requires `background_threads_runtime_support`"
|
|
|
|
);
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
if NO_BG_THREAD_TARGETS.iter().any(|i| target.contains(i)) {
|
|
|
|
warning!(
|
|
|
|
"`background_threads_runtime_support` not supported for `{}`",
|
|
|
|
target
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(Self { always_enabled })
|
|
|
|
}
|
|
|
|
}
|