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

Package non-rust objects #65337

Closed
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
4 changes: 4 additions & 0 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl Step for Std {
cargo,
args(builder.kind),
&libstd_stamp(builder, compiler, target),
vec![],
true);

let libdir = builder.sysroot_libdir(compiler, target);
Expand Down Expand Up @@ -103,6 +104,7 @@ impl Step for Rustc {
cargo,
args(builder.kind),
&librustc_stamp(builder, compiler, target),
vec![],
true);

let libdir = builder.sysroot_libdir(compiler, target);
Expand Down Expand Up @@ -155,6 +157,7 @@ impl Step for CodegenBackend {
cargo,
args(builder.kind),
&codegen_backend_stamp(builder, compiler, target, backend),
vec![],
true);
}
}
Expand Down Expand Up @@ -199,6 +202,7 @@ impl Step for Rustdoc {
cargo,
args(builder.kind),
&rustdoc_stamp(builder, compiler, target),
vec![],
true);

let libdir = builder.sysroot_libdir(compiler, target);
Expand Down
63 changes: 41 additions & 22 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Step for Std {
return;
}

builder.ensure(StartupObjects { compiler, target });
let mut target_deps = builder.ensure(StartupObjects { compiler, target });

let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
if compiler_to_use != compiler {
Expand All @@ -91,7 +91,7 @@ impl Step for Std {
return;
}

copy_third_party_objects(builder, &compiler, target);
target_deps.extend(copy_third_party_objects(builder, &compiler, target).into_iter());

let mut cargo = builder.cargo(compiler, Mode::Std, target, "build");
std_cargo(builder, &compiler, target, &mut cargo);
Expand All @@ -102,6 +102,7 @@ impl Step for Std {
cargo,
vec![],
&libstd_stamp(builder, compiler, target),
target_deps,
false);

builder.ensure(StdLink {
Expand All @@ -113,29 +114,36 @@ impl Step for Std {
}

/// Copies third pary objects needed by various targets.
fn copy_third_party_objects(builder: &Builder<'_>, compiler: &Compiler, target: Interned<String>) {
fn copy_third_party_objects(builder: &Builder<'_>, compiler: &Compiler, target: Interned<String>)
-> Vec<PathBuf>
{
let libdir = builder.sysroot_libdir(*compiler, target);

let mut target_deps = vec![];

let mut copy_and_stamp = |sourcedir: &Path, name: &str| {
let target = libdir.join(name);
builder.copy(
&sourcedir.join(name),
&target,
);
target_deps.push(target);
};

// Copies the crt(1,i,n).o startup objects
//
// Since musl supports fully static linking, we can cross link for it even
// with a glibc-targeting toolchain, given we have the appropriate startup
// files. As those shipped with glibc won't work, copy the ones provided by
// musl so we have them on linux-gnu hosts.
if target.contains("musl") {
let srcdir = builder.musl_root(target).unwrap().join("lib");
for &obj in &["crt1.o", "crti.o", "crtn.o"] {
builder.copy(
&builder.musl_root(target).unwrap().join("lib").join(obj),
&libdir.join(obj),
);
copy_and_stamp(&srcdir, obj);
}
} else if target.ends_with("-wasi") {
for &obj in &["crt1.o"] {
builder.copy(
&builder.wasi_root(target).unwrap().join("lib/wasm32-wasi").join(obj),
&libdir.join(obj),
);
}
let srcdir = builder.wasi_root(target).unwrap().join("lib/wasm32-wasi");
copy_and_stamp(&srcdir, "crt1.o");
}

// Copies libunwind.a compiled to be linked wit x86_64-fortanix-unknown-sgx.
Expand All @@ -145,11 +153,11 @@ fn copy_third_party_objects(builder: &Builder<'_>, compiler: &Compiler, target:
// which is provided by std for this target.
if target == "x86_64-fortanix-unknown-sgx" {
let src_path_env = "X86_FORTANIX_SGX_LIBS";
let obj = "libunwind.a";
let src = env::var(src_path_env).expect(&format!("{} not found in env", src_path_env));
let src = Path::new(&src).join(obj);
builder.copy(&src, &libdir.join(obj));
copy_and_stamp(Path::new(&src), "libunwind.a");
}

target_deps
}

/// Configure cargo to compile the standard library, adding appropriate env vars
Expand Down Expand Up @@ -307,7 +315,7 @@ pub struct StartupObjects {
}

impl Step for StartupObjects {
type Output = ();
type Output = Vec<PathBuf>;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/rtstartup")
Expand All @@ -326,13 +334,15 @@ impl Step for StartupObjects {
/// They don't require any library support as they're just plain old object
/// files, so we just use the nightly snapshot compiler to always build them (as
/// no other compilers are guaranteed to be available).
fn run(self, builder: &Builder<'_>) {
fn run(self, builder: &Builder<'_>) -> Vec<PathBuf> {
let for_compiler = self.compiler;
let target = self.target;
if !target.contains("windows-gnu") {
return
return vec![]
}

let mut target_deps = vec![];

let src_dir = &builder.src.join("src/rtstartup");
let dst_dir = &builder.native_dir(target).join("rtstartup");
let sysroot_dir = &builder.sysroot_libdir(for_compiler, target);
Expand All @@ -351,16 +361,22 @@ impl Step for StartupObjects {
.arg(src_file));
}

builder.copy(dst_file, &sysroot_dir.join(file.to_string() + ".o"));
let target = sysroot_dir.join(file.to_string() + ".o");
builder.copy(dst_file, &target);
target_deps.push(target);
}

for obj in ["crt2.o", "dllcrt2.o"].iter() {
let src = compiler_file(builder,
builder.cc(target),
target,
obj);
builder.copy(&src, &sysroot_dir.join(obj));
let target = sysroot_dir.join(obj);
builder.copy(&src, &target);
target_deps.push(target);
}

target_deps
}
}

Expand Down Expand Up @@ -438,6 +454,7 @@ impl Step for Rustc {
cargo,
vec![],
&librustc_stamp(builder, compiler, target),
vec![],
false);

builder.ensure(RustcLink {
Expand Down Expand Up @@ -586,7 +603,7 @@ impl Step for CodegenBackend {

let tmp_stamp = out_dir.join(".tmp.stamp");

let files = run_cargo(builder, cargo, vec![], &tmp_stamp, false);
let files = run_cargo(builder, cargo, vec![], &tmp_stamp, vec![], false);
if builder.config.dry_run {
return;
}
Expand Down Expand Up @@ -954,6 +971,7 @@ pub fn run_cargo(builder: &Builder<'_>,
cargo: Cargo,
tail_args: Vec<String>,
stamp: &Path,
additional_target_deps: Vec<PathBuf>,
is_check: bool)
-> Vec<PathBuf>
{
Expand Down Expand Up @@ -1070,6 +1088,7 @@ pub fn run_cargo(builder: &Builder<'_>,
deps.push((path_to_add.into(), false));
}

deps.extend(additional_target_deps.into_iter().map(|d| (d, false)));
deps.sort();
let mut new_contents = Vec::new();
for (dep, proc_macro) in deps.iter() {
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ impl Build {
pub fn copy(&self, src: &Path, dst: &Path) {
if self.config.dry_run { return; }
self.verbose_than(1, &format!("Copy {:?} to {:?}", src, dst));
if src == dst { return; }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why this is now necessary, but hey, it appears to work!

let _ = fs::remove_file(&dst);
let metadata = t!(src.symlink_metadata());
if metadata.file_type().is_symlink() {
Expand Down
4 changes: 4 additions & 0 deletions src/ci/azure-pipelines/try.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
IMAGE: dist-x86_64-linux
DEPLOY_ALT: 1

dist-various-2:
IMAGE: dist-various-2
DEPLOY: 1

# The macOS and Windows builds here are currently disabled due to them not being
# overly necessary on `try` builds. We also don't actually have anything that
# consumes the artifacts currently. Perhaps one day we can reenable, but for now
Expand Down