Skip to content

Commit 8f402dc

Browse files
committed
Auto merge of rust-lang#117574 - onur-ozkan:fix-compiler-crate-linking, r=<try>
re-enable cranelift on CI First commit addresses the linking issue with compiler crates. Second one ensures that compiler crates are linked correctly, allowing us to detect these hard-to-catch bugs on CI. The remaining three commits cherry-picked from rust-lang#117328 to re-enable the Cranelift backend on CI. More info: rust-lang#117430 cc `@bjorn3` `@RalfJung`
2 parents a42d94e + 2a33287 commit 8f402dc

File tree

6 files changed

+67
-46
lines changed

6 files changed

+67
-46
lines changed

.github/workflows/ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ jobs:
543543
try:
544544
name: "try - ${{ matrix.name }}"
545545
env:
546-
DIST_TRY_BUILD: 1
547546
CI_JOB_NAME: "${{ matrix.name }}"
548547
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
549548
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"

src/bootstrap/src/core/build_steps/compile.rs

-5
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,6 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
413413

414414
let mut features = String::new();
415415

416-
// Cranelift doesn't support `asm`.
417-
if stage != 0 && builder.config.default_codegen_backend().unwrap_or_default() == "cranelift" {
418-
features += " compiler-builtins-no-asm";
419-
}
420-
421416
if builder.no_std(target) == Some(true) {
422417
features += " compiler-builtins-mem";
423418
if !target.starts_with("bpf") {

src/bootstrap/src/core/build_steps/dist.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1298,13 +1298,21 @@ impl Step for CodegenBackend {
12981298
}
12991299

13001300
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1301+
if builder.config.dry_run() {
1302+
return None;
1303+
}
1304+
13011305
// This prevents rustc_codegen_cranelift from being built for "dist"
13021306
// or "install" on the stable/beta channels. It is not yet stable and
13031307
// should not be included.
13041308
if !builder.build.unstable_features() {
13051309
return None;
13061310
}
13071311

1312+
if !builder.config.rust_codegen_backends.contains(&self.backend) {
1313+
return None;
1314+
}
1315+
13081316
if self.backend == "cranelift" {
13091317
if !target_supports_cranelift_backend(self.compiler.host) {
13101318
builder.info("target not supported by rustc_codegen_cranelift. skipping");
@@ -1343,12 +1351,15 @@ impl Step for CodegenBackend {
13431351
let backends_dst = PathBuf::from("lib").join(&backends_rel);
13441352

13451353
let backend_name = format!("rustc_codegen_{}", backend);
1354+
let mut found_backend = false;
13461355
for backend in fs::read_dir(&backends_src).unwrap() {
13471356
let file_name = backend.unwrap().file_name();
13481357
if file_name.to_str().unwrap().contains(&backend_name) {
13491358
tarball.add_file(backends_src.join(file_name), &backends_dst, 0o644);
1359+
found_backend = true;
13501360
}
13511361
}
1362+
assert!(found_backend);
13521363

13531364
Some(tarball.generate())
13541365
}

src/bootstrap/src/core/build_steps/doc.rs

+55-39
Original file line numberDiff line numberDiff line change
@@ -685,18 +685,7 @@ impl Step for Rustc {
685685
target,
686686
);
687687

688-
// This uses a shared directory so that librustdoc documentation gets
689-
// correctly built and merged with the rustc documentation. This is
690-
// needed because rustdoc is built in a different directory from
691-
// rustc. rustdoc needs to be able to see everything, for example when
692-
// merging the search index, or generating local (relative) links.
693688
let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target.triple).join("doc");
694-
t!(fs::create_dir_all(out_dir.parent().unwrap()));
695-
symlink_dir_force(&builder.config, &out, &out_dir);
696-
// Cargo puts proc macros in `target/doc` even if you pass `--target`
697-
// explicitly (https://github.com/rust-lang/cargo/issues/7677).
698-
let proc_macro_out_dir = builder.stage_out(compiler, Mode::Rustc).join("doc");
699-
symlink_dir_force(&builder.config, &out, &proc_macro_out_dir);
700689

701690
// Build cargo command.
702691
let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "doc");
@@ -736,8 +725,29 @@ impl Step for Rustc {
736725
}
737726
}
738727

728+
// This uses a shared directory so that librustdoc documentation gets
729+
// correctly built and merged with the rustc documentation.
730+
//
731+
// This is needed because rustdoc is built in a different directory from
732+
// rustc. rustdoc needs to be able to see everything, for example when
733+
// merging the search index, or generating local (relative) links.
734+
symlink_dir_force(&builder.config, &out, &out_dir);
735+
// Cargo puts proc macros in `target/doc` even if you pass `--target`
736+
// explicitly (https://github.com/rust-lang/cargo/issues/7677).
737+
let proc_macro_out_dir = builder.stage_out(compiler, Mode::Rustc).join("doc");
738+
symlink_dir_force(&builder.config, &out, &proc_macro_out_dir);
739+
739740
builder.run(&mut cargo.into());
740741

742+
if !builder.config.dry_run() {
743+
// Sanity check on linked compiler crates
744+
for krate in &*self.crates {
745+
let dir_name = krate.replace("-", "_");
746+
// Making sure the directory exists and is not empty.
747+
assert!(out.join(&*dir_name).read_dir().unwrap().next().is_some());
748+
}
749+
}
750+
741751
if builder.paths.iter().any(|path| path.ends_with("compiler")) {
742752
// For `x.py doc compiler --open`, open `rustc_middle` by default.
743753
let index = out.join("rustc_middle").join("index.html");
@@ -756,10 +766,10 @@ macro_rules! tool_doc {
756766
$should_run: literal,
757767
$path: literal,
758768
$(rustc_tool = $rustc_tool:literal, )?
759-
$(in_tree = $in_tree:literal, )?
760-
[$($extra_arg: literal),+ $(,)?]
761-
$(,)?
762-
) => {
769+
$(in_tree = $in_tree:literal ,)?
770+
$(is_library = $is_library:expr,)?
771+
$(crates = $crates:expr)?
772+
) => {
763773
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
764774
pub struct $tool {
765775
target: TargetSelection,
@@ -818,9 +828,15 @@ macro_rules! tool_doc {
818828
// Cargo uses a different directory for proc macros.
819829
builder.stage_out(compiler, Mode::ToolRustc).join("doc"),
820830
];
831+
821832
for out_dir in out_dirs {
822833
t!(fs::create_dir_all(&out_dir));
823834
symlink_dir_force(&builder.config, &out, &out_dir);
835+
836+
$(for krate in $crates {
837+
let dir_name = krate.replace("-", "_");
838+
t!(fs::create_dir_all(&out_dir.join(&*dir_name)));
839+
})?
824840
}
825841

826842
// Build cargo command.
@@ -839,9 +855,13 @@ macro_rules! tool_doc {
839855
// Only include compiler crates, no dependencies of those, such as `libc`.
840856
cargo.arg("--no-deps");
841857

842-
$(
843-
cargo.arg($extra_arg);
844-
)+
858+
if false $(|| $is_library)? {
859+
cargo.arg("--lib");
860+
}
861+
862+
$(for krate in $crates {
863+
cargo.arg("-p").arg(krate);
864+
})?
845865

846866
cargo.rustdocflag("--document-private-items");
847867
// Since we always pass --document-private-items, there's no need to warn about linking to private items.
@@ -853,60 +873,56 @@ macro_rules! tool_doc {
853873

854874
let _guard = builder.msg_doc(compiler, stringify!($tool).to_lowercase(), target);
855875
builder.run(&mut cargo.into());
876+
877+
if !builder.config.dry_run() {
878+
// Sanity check on linked doc directories
879+
$(for krate in $crates {
880+
let dir_name = krate.replace("-", "_");
881+
// Making sure the directory exists and is not empty.
882+
assert!(out.join(&*dir_name).read_dir().unwrap().next().is_some());
883+
})?
884+
}
856885
}
857886
}
858887
}
859888
}
860889

861-
tool_doc!(
862-
Rustdoc,
863-
"rustdoc-tool",
864-
"src/tools/rustdoc",
865-
["-p", "rustdoc", "-p", "rustdoc-json-types"]
866-
);
890+
tool_doc!(Rustdoc, "rustdoc-tool", "src/tools/rustdoc", crates = ["rustdoc", "rustdoc-json-types"]);
867891
tool_doc!(
868892
Rustfmt,
869893
"rustfmt-nightly",
870894
"src/tools/rustfmt",
871-
["-p", "rustfmt-nightly", "-p", "rustfmt-config_proc_macro"],
895+
crates = ["rustfmt-nightly", "rustfmt-config_proc_macro"]
872896
);
873-
tool_doc!(Clippy, "clippy", "src/tools/clippy", ["-p", "clippy_utils"]);
874-
tool_doc!(Miri, "miri", "src/tools/miri", ["-p", "miri"]);
897+
tool_doc!(Clippy, "clippy", "src/tools/clippy", crates = ["clippy_utils"]);
898+
tool_doc!(Miri, "miri", "src/tools/miri", crates = ["miri"]);
875899
tool_doc!(
876900
Cargo,
877901
"cargo",
878902
"src/tools/cargo",
879903
rustc_tool = false,
880904
in_tree = false,
881-
[
882-
"-p",
905+
crates = [
883906
"cargo",
884-
"-p",
885907
"cargo-platform",
886-
"-p",
887908
"cargo-util",
888-
"-p",
889909
"crates-io",
890-
"-p",
891910
"cargo-test-macro",
892-
"-p",
893911
"cargo-test-support",
894-
"-p",
895912
"cargo-credential",
896-
"-p",
897913
"mdman",
898914
// FIXME: this trips a license check in tidy.
899-
// "-p",
900915
// "resolver-tests",
901916
]
902917
);
903-
tool_doc!(Tidy, "tidy", "src/tools/tidy", rustc_tool = false, ["-p", "tidy"]);
918+
tool_doc!(Tidy, "tidy", "src/tools/tidy", rustc_tool = false, crates = ["tidy"]);
904919
tool_doc!(
905920
Bootstrap,
906921
"bootstrap",
907922
"src/bootstrap",
908923
rustc_tool = false,
909-
["--lib", "-p", "bootstrap"]
924+
is_library = true,
925+
crates = ["bootstrap"]
910926
);
911927

912928
#[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)]

src/ci/docker/run.sh

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ docker \
302302
--env DIST_TRY_BUILD \
303303
--env PR_CI_JOB \
304304
--env OBJDIR_ON_HOST="$objdir" \
305+
--env CODEGEN_BACKENDS \
305306
--init \
306307
--rm \
307308
rust-ci \

src/ci/github-actions/ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,6 @@ jobs:
700700
<<: *base-ci-job
701701
name: try - ${{ matrix.name }}
702702
env:
703-
DIST_TRY_BUILD: 1
704703
<<: [*shared-ci-variables, *prod-variables]
705704
if: github.event_name == 'push' && (((github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust') || ((github.ref == 'refs/heads/automation/bors/try') && github.repository == 'rust-lang/rust'))
706705
strategy:

0 commit comments

Comments
 (0)