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

Prevent rmake.rs from using unstable features, and fix 3 run-make tests that currently do #137537

Merged
merged 7 commits into from
Mar 8, 2025
11 changes: 11 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2526,6 +2526,16 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"

[[package]]
name = "os_pipe"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982"
dependencies = [
"libc",
"windows-sys 0.59.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

Remark [RAW_DYLIB 1/2]: os_pipe depends on windows-sys which tries to link in windows.0.52.0.lib unless you pass a --cfg windows_raw_dylib. This is already what rustc / rustc tool cargo uses. I.e. the comment

// By default, windows-rs depends on a native library that doesn't get copied into the
// sysroot. Passing this cfg enables raw-dylib support instead, which makes the native
// library unnecessary. This can be removed when windows-rs enables raw-dylib
// unconditionally.

applies here.

]

[[package]]
name = "overload"
version = "0.1.1"
Expand Down Expand Up @@ -3050,6 +3060,7 @@ dependencies = [
"gimli 0.31.1",
"libc",
"object 0.36.7",
"os_pipe",
"regex",
"serde_json",
"similar",
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ impl Builder<'_> {
// sysroot. Passing this cfg enables raw-dylib support instead, which makes the native
// library unnecessary. This can be removed when windows-rs enables raw-dylib
// unconditionally.
if let Mode::Rustc | Mode::ToolRustc = mode {
if let Mode::Rustc | Mode::ToolRustc | Mode::ToolBootstrap = mode {
rustflags.arg("--cfg=windows_raw_dylib");
}
Comment on lines +600 to 602
Copy link
Member Author

Choose a reason for hiding this comment

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

Remark [RAW_DYLIB 2/2]: here.


Expand Down
4 changes: 4 additions & 0 deletions src/doc/rustc-dev-guide/src/tests/compiletest.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ Compiletest directives like `//@ only-<target>` or `//@ ignore-<target>` are
supported in `rmake.rs`, like in UI tests. However, revisions or building
auxiliary via directives are not currently supported.

`rmake.rs` and `run-make-support` may *not* use any nightly/unstable features,
as they must be compilable by a stage 0 rustc that may be a beta or even stable
rustc.
Comment on lines +418 to +420
Copy link
Member Author

Choose a reason for hiding this comment

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

Remark: adjusted this to also say that run-make-support may not depend on nightly/unstable features.


#### Quickly check if `rmake.rs` tests can be compiled

You can quickly check if `rmake.rs` tests can be compiled without having to
Expand Down
5 changes: 5 additions & 0 deletions src/tools/compiletest/src/runtest/run_make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ impl TestCx<'_> {
.expect("stage0 rustc is required to run run-make tests");
let mut rustc = Command::new(&stage0_rustc);
rustc
// `rmake.rs` **must** be buildable by a stable compiler, it may not use *any* unstable
// library or compiler features. Here, we force the stage 0 rustc to consider itself as
// a stable-channel compiler via `RUSTC_BOOTSTRAP=-1` to prevent *any* unstable
// library/compiler usages, even if stage 0 rustc is *actually* a nightly rustc.
.env("RUSTC_BOOTSTRAP", "-1")
.arg("-o")
.arg(&recipe_bin)
// Specify library search paths for `run_make_support`.
Expand Down
4 changes: 4 additions & 0 deletions src/tools/run-make-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ build_helper = { path = "../../build_helper" }
serde_json = "1.0"
libc = "0.2"

# FIXME(#137532): replace `os_pipe` with `anonymous_pipe` once it stabilizes and
# reaches beta.
os_pipe = "1.2.1"

[lib]
crate-type = ["lib", "dylib"]
2 changes: 2 additions & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub use bstr;
pub use gimli;
pub use libc;
pub use object;
// FIXME(#137532): replace with std `anonymous_pipe` once it stabilizes and reaches beta.
pub use os_pipe;
pub use regex;
pub use serde_json;
pub use similar;
Expand Down
8 changes: 4 additions & 4 deletions tests/run-make/broken-pipe-no-ice/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
// Internal Compiler Error strangely, but it doesn't even go through normal diagnostic infra. Very
// strange.

#![feature(anonymous_pipe)]

use std::io::Read;
use std::process::{Command, Stdio};

use run_make_support::env_var;
// FIXME(#137532): replace `os_pipe` dependency with std `anonymous_pipe` once that stabilizes and
// reaches beta.
use run_make_support::{env_var, os_pipe};

#[derive(Debug, PartialEq)]
enum Binary {
Expand All @@ -25,7 +25,7 @@ enum Binary {
}

fn check_broken_pipe_handled_gracefully(bin: Binary, mut cmd: Command) {
let (reader, writer) = std::io::pipe().unwrap();
let (reader, writer) = os_pipe::pipe().unwrap();
drop(reader); // close read-end
cmd.stdout(writer).stderr(Stdio::piped());

Expand Down
15 changes: 10 additions & 5 deletions tests/run-make/cross-lang-lto/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// -Clinker-plugin-lto.
// See https://github.com/rust-lang/rust/pull/50000

#![feature(path_file_prefix)]

use std::path::PathBuf;

use run_make_support::{
Expand Down Expand Up @@ -92,10 +90,17 @@ fn check_bitcode(instructions: LibBuild) {
llvm_ar().extract().arg(&instructions.output).run();
}

for object in shallow_find_files(cwd(), |path| {
has_prefix(path, instructions.output.file_prefix().unwrap().to_str().unwrap())
let objects = shallow_find_files(cwd(), |path| {
let mut output_path = instructions.output.clone();
output_path.set_extension("");
has_prefix(path, output_path.file_name().unwrap().to_str().unwrap())
&& has_extension(path, "o")
}) {
});
assert!(!objects.is_empty());
println!("objects: {:#?}", objects);

for object in objects {
println!("reading bitcode: {}", object.display());
// All generated object files should be LLVM bitcode files - this will fail otherwise.
llvm_bcanalyzer().input(object).run();
}
Expand Down
7 changes: 2 additions & 5 deletions tests/run-make/issue-107495-archive-permissions/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#![feature(rustc_private)]

#[cfg(unix)]
extern crate libc;

#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
use std::path::Path;

#[cfg(unix)]
use run_make_support::libc;
use run_make_support::{aux_build, rfs};

fn main() {
Expand Down
Loading