Skip to content

[WIP] rustbuild: Build jemalloc and libbacktrace only once #38583

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

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
10 changes: 8 additions & 2 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ impl Build {
//
// These variables are primarily all read by
// src/bootstrap/bin/{rustc.rs,rustdoc.rs}
cargo.env("RUSTC", self.out.join("bootstrap/debug/rustc"))
cargo.env("RUSTBUILD_NATIVE_DIR", self.native_dir(compiler.host))
.env("RUSTC", self.out.join("bootstrap/debug/rustc"))
.env("RUSTC_REAL", self.compiler_path(compiler))
.env("RUSTC_STAGE", stage.to_string())
.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string())
Expand Down Expand Up @@ -736,10 +737,15 @@ impl Build {
}
}

/// Directory for libraries built from C/C++ code and shared between stages.
fn native_dir(&self, target: &str) -> PathBuf {
self.out.join(target).join("native")
}

/// Root output directory for rust_test_helpers library compiled for
/// `target`
fn test_helpers_out(&self, target: &str) -> PathBuf {
self.out.join(target).join("rust-test-helpers")
self.native_dir(target).join("rust-test-helpers")
}

/// Adds the compiler's directory of dynamic libraries to `cmd`'s dynamic
Expand Down
7 changes: 6 additions & 1 deletion src/liballoc_jemalloc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern crate build_helper;
extern crate gcc;

use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
use build_helper::run;
Expand All @@ -24,8 +25,9 @@ fn main() {

let target = env::var("TARGET").expect("TARGET was not set");
let host = env::var("HOST").expect("HOST was not set");
let build_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let src_dir = env::current_dir().unwrap();
let build_dir = PathBuf::from(env::var_os("RUSTBUILD_NATIVE_DIR").unwrap()).join("jemalloc");
let _ = fs::create_dir_all(&build_dir);

// FIXME: This is a hack to support building targets that don't
// support jemalloc alongside hosts that do. The jemalloc build is
Expand Down Expand Up @@ -81,6 +83,7 @@ fn main() {
}
}

if !build_dir.join("Makefile").metadata().is_ok() {
let mut cmd = Command::new("sh");
cmd.arg(src_dir.join("../jemalloc/configure")
.to_str()
Expand Down Expand Up @@ -152,6 +155,8 @@ fn main() {
cmd.arg(format!("--build={}", build_helper::gnu_target(&host)));

run(&mut cmd);
}

let mut make = Command::new(build_helper::make(&host));
make.current_dir(&build_dir)
.arg("build_lib_static");
Expand Down
7 changes: 6 additions & 1 deletion src/libstd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern crate gcc;
extern crate build_helper;

use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command;

Expand Down Expand Up @@ -67,7 +68,9 @@ fn main() {

fn build_libbacktrace(host: &str, target: &str) {
let src_dir = env::current_dir().unwrap().join("../libbacktrace");
let build_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let build_dir =
PathBuf::from(env::var_os("RUSTBUILD_NATIVE_DIR").unwrap()).join("libbacktrace");
let _ = fs::create_dir_all(&build_dir);

println!("cargo:rustc-link-lib=static=backtrace");
println!("cargo:rustc-link-search=native={}/.libs", build_dir.display());
Expand All @@ -89,6 +92,7 @@ fn build_libbacktrace(host: &str, target: &str) {
let ar = build_helper::cc2ar(compiler.path(), target).unwrap();
let cflags = compiler.args().iter().map(|s| s.to_str().unwrap())
.collect::<Vec<_>>().join(" ");
if !build_dir.join("Makefile").metadata().is_ok() {
run(Command::new("sh")
.current_dir(&build_dir)
.arg(src_dir.join("configure").to_str().unwrap()
Expand All @@ -104,6 +108,7 @@ fn build_libbacktrace(host: &str, target: &str) {
.env("AR", &ar)
.env("RANLIB", format!("{} s", ar.display()))
.env("CFLAGS", cflags));
}
run(Command::new(build_helper::make(host))
.current_dir(&build_dir)
.arg(format!("INCDIR={}", src_dir.display()))
Expand Down