Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 3 deletions src/tools/run-make-support/src/cc.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::path::Path;
use std::process::Command;

use crate::{
bin_name, cygpath_windows, env_var, handle_failed_output, is_msvc, is_windows, tmp_dir, uname,
};
use crate::{bin_name, cygpath_windows, env_var, handle_failed_output, is_msvc, is_windows, uname};

/// Construct a new platform-specific C compiler invocation.
///
Expand Down
2 changes: 1 addition & 1 deletion src/tools/run-make-support/src/clang.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::Path;
use std::process::Command;

use crate::{bin_name, env_var, handle_failed_output, tmp_dir};
use crate::{bin_name, env_var, handle_failed_output};

/// Construct a new `clang` invocation. `clang` is not always available for all targets.
pub fn clang() -> Clang {
Expand Down
5 changes: 5 additions & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ pub fn bin_name(name: &str) -> String {
if is_windows() { format!("{name}.exe") } else { name.to_string() }
}

/// Return the current working directory.
pub fn cwd() -> PathBuf {
env::current_dir().unwrap()
}

/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
/// available on the platform!
#[track_caller]
Expand Down
10 changes: 5 additions & 5 deletions tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use run_make_support::{aux_build, rustc};
fn main() {
aux_build().input("stable.rs").emit("metadata").run();

let mut stable_path = PathBuf::from(env!("TMPDIR"));
stable_path.push("libstable.rmeta");

let output =
rustc().input("main.rs").emit("metadata").extern_("stable", &stable_path).command_output();
let output = rustc()
.input("main.rs")
.emit("metadata")
.extern_("stable", "libstable.rmeta")
.command_output();

let stderr = String::from_utf8_lossy(&output.stderr);
let version = include_str!(concat!(env!("S"), "/src/version"));
Expand Down
6 changes: 2 additions & 4 deletions tests/run-make/artifact-incr-cache-no-obj/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
//
// Fixes: rust-lang/rust#123234

use run_make_support::{rustc, tmp_dir};
use run_make_support::rustc;

fn main() {
let inc_dir = tmp_dir();

for _ in 0..=1 {
rustc()
.input("lib.rs")
.crate_type("lib")
.emit("asm,dep-info,link,mir,llvm-ir,llvm-bc")
.incremental(&inc_dir)
.incremental("incremental")
.run();
}
}
6 changes: 2 additions & 4 deletions tests/run-make/artifact-incr-cache/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
// Also see discussion at
// <https://internals.rust-lang.org/t/interaction-between-incremental-compilation-and-emit/20551>

use run_make_support::{rustc, tmp_dir};
use run_make_support::rustc;

fn main() {
let inc_dir = tmp_dir();

for _ in 0..=1 {
rustc()
.input("lib.rs")
.crate_type("lib")
.emit("obj,asm,dep-info,link,mir,llvm-ir,llvm-bc")
.incremental(&inc_dir)
.incremental("incremental")
.run();
}
}
4 changes: 2 additions & 2 deletions tests/run-make/box-struct-no-segfault/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// This test checks that this bug does not resurface.
// See https://github.com/rust-lang/rust/issues/28766

use run_make_support::{rustc, tmp_dir};
use run_make_support::rustc;

fn main() {
rustc().opt().input("foo.rs").run();
rustc().opt().library_search_path(tmp_dir()).input("main.rs").run();
rustc().opt().input("main.rs").run();
}
14 changes: 4 additions & 10 deletions tests/run-make/c-link-to-rust-dylib/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,23 @@

use std::fs::remove_file;

use run_make_support::{
cc, dynamic_lib_extension, is_msvc, read_dir, run, run_fail, rustc, tmp_dir,
};
use run_make_support::{cc, cwd, dynamic_lib_extension, is_msvc, read_dir, run, run_fail, rustc};

fn main() {
rustc().input("foo.rs").run();

if is_msvc() {
let lib = tmp_dir().join("foo.dll.lib");
let lib = "foo.dll.lib";

cc().input("bar.c").arg(lib).out_exe("bar").run();
} else {
cc().input("bar.c")
.arg("-lfoo")
.output(tmp_dir().join("bar"))
.library_search_path(tmp_dir())
.run();
cc().input("bar.c").arg("-lfoo").output("bar").library_search_path(cwd()).run();
}

run("bar");

let expected_extension = dynamic_lib_extension();
read_dir(tmp_dir(), |path| {
read_dir(std::env::current_dir().unwrap(), |path| {
if path.is_file()
&& path.extension().is_some_and(|ext| ext == expected_extension)
&& path.file_name().and_then(|name| name.to_str()).is_some_and(|name| {
Expand Down
10 changes: 3 additions & 7 deletions tests/run-make/cdylib/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@

use std::fs::remove_file;

use run_make_support::{cc, dynamic_lib, is_msvc, run, rustc, tmp_dir};
use run_make_support::{cc, cwd, dynamic_lib, is_msvc, run, rustc};

fn main() {
rustc().input("bar.rs").run();
rustc().input("foo.rs").run();

if is_msvc() {
cc().input("foo.c").arg(tmp_dir().join("foo.dll.lib")).out_exe("foo").run();
cc().input("foo.c").arg("foo.dll.lib").out_exe("foo").run();
} else {
cc().input("foo.c")
.arg("-lfoo")
.output(tmp_dir().join("foo"))
.library_search_path(tmp_dir())
.run();
cc().input("foo.c").arg("-lfoo").library_search_path(cwd()).output("foo").run();
}

run("foo");
Expand Down
7 changes: 7 additions & 0 deletions tests/run-make/compiler-builtins/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "scratch"
version = "0.1.0"
edition = "2021"

[lib]
path = "lib.rs"
1 change: 1 addition & 0 deletions tests/run-make/compiler-builtins/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#![no_std]
18 changes: 3 additions & 15 deletions tests/run-make/compiler-builtins/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,17 @@ use run_make_support::object::ObjectSection;
use run_make_support::object::ObjectSymbol;
use run_make_support::object::RelocationTarget;
use run_make_support::set_host_rpath;
use run_make_support::tmp_dir;
use run_make_support::{env_var, object};
use std::collections::HashSet;

const MANIFEST: &str = r#"
[package]
name = "scratch"
version = "0.1.0"
edition = "2021"

[lib]
path = "lib.rs""#;
use std::path::PathBuf;

fn main() {
let target_dir = tmp_dir().join("target");
let target_dir = PathBuf::from("target");
let target = env_var("TARGET");

println!("Testing compiler_builtins for {}", target);

// Set up the tiniest Cargo project: An empty no_std library. Just enough to run -Zbuild-std.
let manifest_path = tmp_dir().join("Cargo.toml");
std::fs::write(&manifest_path, MANIFEST.as_bytes()).unwrap();
std::fs::write(tmp_dir().join("lib.rs"), b"#![no_std]").unwrap();
let manifest_path = PathBuf::from("Cargo.toml");

let path = env_var("PATH");
let rustc = env_var("RUSTC");
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/const-prop-lint/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

use std::fs;

use run_make_support::{rustc, tmp_dir};
use run_make_support::rustc;

fn main() {
rustc().input("input.rs").run_fail_assert_exit_code(1);

for entry in fs::read_dir(tmp_dir()).unwrap() {
for entry in fs::read_dir(std::env::current_dir().unwrap()).unwrap() {
let entry = entry.unwrap();
let path = entry.path();

Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/core-no-oom-handling/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// when the no_global_oom_handling feature is turned on.
// See https://github.com/rust-lang/rust/pull/110649

use run_make_support::{rustc, source_root, tmp_dir};
use run_make_support::{rustc, source_root};

fn main() {
rustc()
.edition("2021")
.arg("-Dwarnings")
.crate_type("rlib")
.input(source_root().join("library/core/src/lib.rs"))
.sysroot(tmp_dir().join("fakeroot"))
.sysroot("fakeroot")
.cfg("no_global_oom_handling")
.run();
}
6 changes: 3 additions & 3 deletions tests/run-make/cross-lang-lto-riscv-abi/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//@ needs-matching-clang
//@ needs-llvm-components riscv

use run_make_support::{bin_name, clang, llvm_readobj, rustc, tmp_dir};
use run_make_support::{bin_name, clang, llvm_readobj, rustc};
use std::{
env,
path::PathBuf,
Expand All @@ -30,11 +30,11 @@ fn check_target(target: &str, clang_target: &str, carch: &str, is_double_float:
.no_stdlib()
.out_exe("riscv-xlto")
.input("cstart.c")
.input(tmp_dir().join("libriscv_xlto.rlib"))
.input("libriscv_xlto.rlib")
.run();

// Check that the built binary has correct float abi
let executable = tmp_dir().join(bin_name("riscv-xlto"));
let executable = bin_name("riscv-xlto");
let output = llvm_readobj().input(&executable).file_header().run();
let stdout = String::from_utf8_lossy(&output.stdout);
eprintln!("obj:\n{}", stdout);
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/deref-impl-rustdoc-ice/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

//@ ignore-cross-compile

use run_make_support::{rustc, rustdoc, tmp_dir};
use run_make_support::{cwd, rustc, rustdoc};

fn main() {
rustc().input("foo.rs").run();
rustc().input("bar.rs").run();
rustdoc().input("baz.rs").library_search_path(tmp_dir()).output(tmp_dir()).run();
rustdoc().input("baz.rs").library_search_path(cwd()).output(cwd()).run();
}
14 changes: 6 additions & 8 deletions tests/run-make/doctests-keep-binaries/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Check that valid binaries are persisted by running them, regardless of whether the
// --run or --no-run option is used.

use run_make_support::{run, rustc, rustdoc, tmp_dir};
use run_make_support::{run, rustc, rustdoc};
use std::fs::{create_dir, remove_dir_all};
use std::path::Path;

fn setup_test_env<F: FnOnce(&Path, &Path)>(callback: F) {
let out_dir = tmp_dir().join("doctests");
let out_dir = Path::new("doctests");
create_dir(&out_dir).expect("failed to create doctests folder");
rustc().input("t.rs").crate_type("rlib").run();
callback(&out_dir, &tmp_dir().join("libt.rlib"));
callback(&out_dir, Path::new("libt.rlib"));
remove_dir_all(out_dir);
}

Expand Down Expand Up @@ -44,19 +44,17 @@ fn main() {
});
// Behavior with --test-run-directory with relative paths.
setup_test_env(|_out_dir, extern_path| {
let run_dir = "rundir";
let run_dir_path = tmp_dir().join("rundir");
let run_dir_path = Path::new("rundir");
create_dir(&run_dir_path).expect("failed to create rundir folder");

rustdoc()
.current_dir(tmp_dir())
.input(std::env::current_dir().unwrap().join("t.rs"))
.input("t.rs")
.arg("-Zunstable-options")
.arg("--test")
.arg("--persist-doctests")
.arg("doctests")
.arg("--test-run-directory")
.arg(run_dir)
.arg(run_dir_path)
.extern_("t", "libt.rlib")
.run();

Expand Down
8 changes: 3 additions & 5 deletions tests/run-make/doctests-runtool/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Tests behavior of rustdoc `--runtool`.

use run_make_support::{rustc, rustdoc, tmp_dir};
use std::env::current_dir;
use run_make_support::{rustc, rustdoc};
use std::fs::{create_dir, remove_dir_all};
use std::path::PathBuf;

fn mkdir(name: &str) -> PathBuf {
let dir = tmp_dir().join(name);
let dir = PathBuf::from(name);
create_dir(&dir).expect("failed to create doctests folder");
dir
}
Expand All @@ -22,15 +21,14 @@ fn main() {
rustc().input("runtool.rs").output(&run_tool_binary).run();

rustdoc()
.input(current_dir().unwrap().join("t.rs"))
.input("t.rs")
.arg("-Zunstable-options")
.arg("--test")
.arg("--test-run-directory")
.arg(run_dir_name)
.arg("--runtool")
.arg(&run_tool_binary)
.extern_("t", "libt.rlib")
.current_dir(tmp_dir())
.run();

remove_dir_all(run_dir);
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/emit-named-files/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::create_dir;
use std::path::Path;

use run_make_support::{rustc, tmp_dir};
use run_make_support::rustc;

fn emit_and_check(out_dir: &Path, out_file: &str, format: &str) {
let out_file = out_dir.join(out_file);
Expand All @@ -10,7 +10,7 @@ fn emit_and_check(out_dir: &Path, out_file: &str, format: &str) {
}

fn main() {
let out_dir = tmp_dir().join("emit");
let out_dir = Path::new("emit");

create_dir(&out_dir).unwrap();

Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/exit-code/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Test that we exit with the correct exit code for successful / unsuccessful / ICE compilations

use run_make_support::{rustc, rustdoc, tmp_dir};
use run_make_support::{rustc, rustdoc};

fn main() {
rustc().arg("success.rs").run();
Expand All @@ -15,7 +15,7 @@ fn main() {
.arg("compile-error.rs")
.run_fail_assert_exit_code(101);

rustdoc().arg("success.rs").output(tmp_dir().join("exit-code")).run();
rustdoc().arg("success.rs").output("exit-code").run();

rustdoc().arg("--invalid-arg-foo").run_fail_assert_exit_code(1);

Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/external-crate-panic-handle-no-lint/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// and cause the test to fail.
// See https://github.com/rust-lang/rust/issues/53964

use run_make_support::{rustc, tmp_dir};
use run_make_support::rustc;

fn main() {
rustc().input("panic.rs").run();
rustc().input("app.rs").panic("abort").emit("obj").library_search_path(tmp_dir()).run();
rustc().input("app.rs").panic("abort").emit("obj").run();
}
Loading