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

Introduce RUSTC_STATIC_CLANG_RT_PATH and RUSTC_STATIC_UNWIND_PATH envs #91765

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4995,6 +4995,7 @@ version = "0.0.0"
dependencies = [
"addr2line",
"alloc",
"build_helper",
"cfg-if 0.1.10",
"compiler_builtins",
"core",
Expand Down Expand Up @@ -5662,6 +5663,7 @@ dependencies = [
name = "unwind"
version = "0.0.0"
dependencies = [
"build_helper",
"cc",
"cfg-if 0.1.10",
"compiler_builtins",
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env;
use std::path::{Path, PathBuf};
use std::process::Command;

use build_helper::{output, tracked_env_var_os};
use build_helper::{maybe_static_library, output, tracked_env_var_os};

fn detect_llvm_link() -> (&'static str, &'static str) {
// Force the link mode we want, preferring static by default, but
Expand Down Expand Up @@ -307,4 +307,6 @@ fn main() {
if target.contains("windows-gnu") {
println!("cargo:rustc-link-lib=static:-bundle=pthread");
}

maybe_static_library("RUSTC_STATIC_CLANG_RT_PATH", "clang_rt");
}
3 changes: 3 additions & 0 deletions library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ heap_size = 0x8000000
name = "stdbenches"
path = "benches/lib.rs"
test = true

[build-dependencies]
build_helper = { path = "../../src/build_helper" }
4 changes: 4 additions & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::env;

use build_helper::maybe_static_library;

fn main() {
println!("cargo:rerun-if-changed=build.rs");
let target = env::var("TARGET").expect("TARGET was not set");
Expand Down Expand Up @@ -47,4 +49,6 @@ fn main() {
}
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
println!("cargo:rustc-cfg=backtrace_in_libstd");

maybe_static_library("RUSTC_STATIC_CLANG_RT_PATH", "clang_rt");
}
1 change: 1 addition & 0 deletions library/unwind/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ compiler_builtins = "0.1.0"
cfg-if = "0.1.8"

[build-dependencies]
build_helper = { path = "../../src/build_helper" }
cc = "1.0.69"

[features]
Expand Down
6 changes: 6 additions & 0 deletions library/unwind/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use std::env;

use build_helper::maybe_static_library;

fn main() {
println!("cargo:rerun-if-changed=build.rs");
let target = env::var("TARGET").expect("TARGET was not set");

if maybe_static_library("RUSTC_STATIC_UNWIND_PATH", "unwind") {
return;
}

if target.contains("android") {
let build = cc::Build::new();

Expand Down
22 changes: 22 additions & 0 deletions src/build_helper/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,25 @@ fn fail(s: &str) -> ! {
println!("\n\n{}\n\n", s);
std::process::exit(1);
}

/// if you need for some reason to statically inject some library, like clang_rt
/// here a good place. Anyway, you should use only thin .a file on macOS.
/// You may extract it like:
/// lipo -thin x86_64 -output libclang_rt.a /path/to/llvm/lib/../libclang_rt.osx.a
///
/// It returns true, when it had injected static library.
pub fn maybe_static_library(env_path_name: &str, library_name: &str) -> bool {
println!("cargo:rerun-if-env-changed={}", env_path_name);

if let Ok(path) = env::var(env_path_name) {
let target = env::var("TARGET").expect("TARGET was not set");
println!("cargo:rerun-if-env-changed=TARGET");

println!("cargo:rustc-link-search=native={}", path);
println!("cargo:rustc-link-search=native={}/{}", path, target);
println!("cargo:rustc-link-lib=static={}", library_name);
return true;
}

return false;
}