Skip to content
Open
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
97 changes: 97 additions & 0 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,103 @@ impl Step for StdarchVerify {
}
}

/// Runs stdarch's intrinsic-test binary crate to verify that Rust's `core::arch`
/// SIMD intrinsics produce the same results as their C counterparts.
///
/// First runs the `intrinsic-test` binary, which generates C wrapper programs
/// and a Rust Cargo workspace. Then runs `cargo test` on that workspace
/// which compiles both versions and compares their outputs on random inputs.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Comment thread
Kobzol marked this conversation as resolved.
pub struct IntrinsicTest {
host: TargetSelection,
}

impl Step for IntrinsicTest {
type Output = ();
const IS_HOST: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("library/stdarch/crates/intrinsic-test")
}
Comment on lines +975 to +977
Copy link
Copy Markdown
Contributor

@folkertdev folkertdev May 10, 2026

Choose a reason for hiding this comment

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

the intrinsic tests should also run when any of the source in core_arch changes (unless I'm misinterpreting what this function does).

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No you are not misinterpreting :) . You're so right I have added the core_arch path so it triggers . Thanks for the review.


fn make_run(run: RunConfig<'_>) {
let target = run.target;
if !target.contains("aarch64-unknown-linux") && !target.contains("x86_64-unknown-linux") {
return;
}
run.builder.ensure(IntrinsicTest { host: target });
}

fn run(self, builder: &Builder<'_>) {
let host = self.host;

let (input_file, skip_file, cflags, sde_runner) = if host.contains("x86_64-unknown-linux") {
let cpuid_def =
builder.src.join("library/stdarch/ci/docker/x86_64-unknown-linux-gnu/cpuid.def");
let sde_runner = format!(
"/intel-sde/sde64 -cpuid-in {} -rtm-mode full -tsx --",
cpuid_def.display()
);
(
builder.src.join("library/stdarch/intrinsics_data/x86-intel.xml"),
builder.src.join("library/stdarch/crates/intrinsic-test/missing_x86.txt"),
"-I/usr/include/x86_64-linux-gnu/",
Some(sde_runner),
)
} else if host.contains("aarch64-unknown-linux") {
(
builder.src.join("library/stdarch/intrinsics_data/arm_intrinsics.json"),
builder.src.join("library/stdarch/crates/intrinsic-test/missing_aarch64.txt"),
"-I/usr/aarch64-linux-gnu/include/",
None,
)
} else {
panic!("intrinsic-test only supports aarch64/x86_64 Linux, got {host}");
};

let out_dir = builder.out.join(host).join("intrinsic-test");
t!(fs::create_dir_all(&out_dir));

let crates_link = out_dir.join("crates");
if !crates_link.exists() {
t!(
helpers::symlink_dir(
&builder.config,
&builder.src.join("library/stdarch/crates"),
&crates_link
),
format!("failed to symlink stdarch crates into {}", crates_link.display())
);
}

let mut cmd = builder.tool_cmd(Tool::IntrinsicTest);
cmd.current_dir(&out_dir);
cmd.arg(&input_file);
cmd.arg("--target").arg(&*host.triple);
cmd.arg("--skip").arg(&skip_file);
cmd.arg("--sample-percentage").arg("10");
cmd.env("CC", builder.cc(host));
cmd.env("CFLAGS", cflags);
cmd.run(builder);

let manifest = out_dir.join("rust_programs/Cargo.toml");
let mut cargo = command(&builder.initial_cargo);
cargo.arg("test");
cargo.arg("--tests");
cargo.arg("--manifest-path").arg(&manifest);
cargo.arg("--target").arg(&*host.triple);
cargo.arg("--profile").arg("release");
cargo.env("CC", builder.cc(host));
cargo.env("CFLAGS", cflags);
cargo.env("RUSTC", &builder.initial_rustc);
cargo.env("RUSTC_BOOTSTRAP", "1");
if let Some(runner) = sde_runner {
cargo.env("CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER", runner);
}
cargo.run(builder);
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Clippy {
compilers: RustcPrivateCompilers,
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ bootstrap_tool!(
FeaturesStatusDump, "src/tools/features-status-dump", "features-status-dump";
OptimizedDist, "src/tools/opt-dist", "opt-dist", submodules = &["src/tools/rustc-perf"];
RunMakeSupport, "src/tools/run-make-support", "run_make_support", artifact_kind = ToolArtifactKind::Library;
IntrinsicTest, "library/stdarch/crates/intrinsic-test", "intrinsic-test";
);

/// These are the submodules that are required for rustbook to work due to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ expression: test library
[Test] test::StdarchVerify
targets: [x86_64-unknown-linux-gnu]
- Set({test::library/stdarch/crates/stdarch-verify})
[Test] test::IntrinsicTest
targets: [x86_64-unknown-linux-gnu]
- Set({test::library/stdarch/crates/intrinsic-test})
1 change: 1 addition & 0 deletions src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ impl<'a> Builder<'a> {
test::Clippy,
test::CompiletestTest,
test::StdarchVerify,
test::IntrinsicTest,
test::CrateRunMakeSupport,
test::CrateBuildHelper,
test::RustdocJSStd,
Expand Down
1 change: 1 addition & 0 deletions src/ci/docker/host-aarch64/aarch64-gnu-llvm-21/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
gdb \
llvm-21-tools \
llvm-21-dev \
clang \
libedit-dev \
libssl-dev \
pkg-config \
Expand Down
4 changes: 3 additions & 1 deletion src/ci/docker/host-aarch64/aarch64-gnu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libssl-dev \
pkg-config \
xz-utils \
clang \
&& rm -rf /var/lib/apt/lists/*



COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh

Expand Down
1 change: 1 addition & 0 deletions src/ci/docker/host-x86_64/x86_64-gnu-llvm-21/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
gdb \
llvm-21-tools \
llvm-21-dev \
clang \
libedit-dev \
libssl-dev \
pkg-config \
Expand Down
1 change: 1 addition & 0 deletions src/ci/docker/host-x86_64/x86_64-gnu-llvm-22/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
gdb \
llvm-22-tools \
llvm-22-dev \
clang \
libedit-dev \
libssl-dev \
pkg-config \
Expand Down
7 changes: 7 additions & 0 deletions src/ci/docker/host-x86_64/x86_64-gnu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
mingw-w64 \
zlib1g-dev \
libzstd-dev \
clang \
&& rm -rf /var/lib/apt/lists/*

# Install Intel SDE for AVX-512 emulation
RUN curl -L http://ci-mirrors.rust-lang.org/sde-external-10.8.0-2026-03-15-lin.tar.xz -o /tmp/sde.tar.xz \
&& mkdir -p /intel-sde \
&& tar -xJf /tmp/sde.tar.xz --strip-components=1 -C /intel-sde \
&& rm /tmp/sde.tar.xz
Comment on lines +26 to +29
Copy link
Copy Markdown
Contributor

@folkertdev folkertdev May 10, 2026

Choose a reason for hiding this comment

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

this doesn't need an instant fix, but we bump the version of this tool occasionally, so ideally we'd sync that version between the repositories.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, noted.


COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh

Expand Down
Loading