Skip to content

Commit 08d00b4

Browse files
committed
Auto merge of rust-lang#114666 - bjorn3:sync_cg_clif-2023-08-09, r=bjorn3
Sync rustc_codegen_cranelift A couple of small bug fixes this time. In addition I fixed the test suite after the introduction of `#![deny(internal_feature)]` broke it. r? `@ghost` `@rustbot` label +A-codegen +A-cranelift +T-compiler
2 parents 27a43f0 + 3775189 commit 08d00b4

20 files changed

+194
-110
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Security audit
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: '0 10 * * 1' # every monday at 10:00 UTC
6+
permissions:
7+
issues: write
8+
checks: write
9+
jobs:
10+
audit:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- run: |
15+
sed -i 's/components.*/components = []/' rust-toolchain
16+
echo 'profile = "minimal"' >> rust-toolchain
17+
- uses: rustsec/audit-check@v1.4.1
18+
with:
19+
token: ${{ secrets.GITHUB_TOKEN }}

compiler/rustc_codegen_cranelift/build_system/abi_cafe.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::build_sysroot;
2-
use super::path::Dirs;
3-
use super::prepare::GitRepo;
4-
use super::utils::{spawn_and_wait, CargoProject, Compiler};
5-
use super::{CodegenBackend, SysrootKind};
1+
use crate::build_sysroot;
2+
use crate::path::Dirs;
3+
use crate::prepare::GitRepo;
4+
use crate::utils::{spawn_and_wait, CargoProject, Compiler};
5+
use crate::{CodegenBackend, SysrootKind};
66

77
static ABI_CAFE_REPO: GitRepo = GitRepo::github(
88
"Gankra",

compiler/rustc_codegen_cranelift/build_system/bench.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use std::env;
22
use std::io::Write;
33
use std::path::Path;
44

5-
use super::path::{Dirs, RelPath};
6-
use super::prepare::GitRepo;
7-
use super::rustc_info::get_file_name;
8-
use super::utils::{hyperfine_command, spawn_and_wait, Compiler};
5+
use crate::path::{Dirs, RelPath};
6+
use crate::prepare::GitRepo;
7+
use crate::rustc_info::get_file_name;
8+
use crate::utils::{hyperfine_command, spawn_and_wait, Compiler};
99

1010
static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
1111
"ebobby",

compiler/rustc_codegen_cranelift/build_system/build_backend.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use std::env;
21
use std::path::PathBuf;
32

4-
use super::path::{Dirs, RelPath};
5-
use super::rustc_info::get_file_name;
6-
use super::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler, LogGroup};
3+
use crate::path::{Dirs, RelPath};
4+
use crate::rustc_info::get_file_name;
5+
use crate::shared_utils::{rustflags_from_env, rustflags_to_cmd_env};
6+
use crate::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler, LogGroup};
77

88
pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif");
99

@@ -18,11 +18,11 @@ pub(crate) fn build_backend(
1818
let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs);
1919
maybe_incremental(&mut cmd);
2020

21-
let mut rustflags = env::var("RUSTFLAGS").unwrap_or_default();
21+
let mut rustflags = rustflags_from_env("RUSTFLAGS");
2222

2323
if is_ci() {
2424
// Deny warnings on CI
25-
rustflags += " -Dwarnings";
25+
rustflags.push("-Dwarnings".to_owned());
2626

2727
if !is_ci_opt() {
2828
cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true");
@@ -42,10 +42,10 @@ pub(crate) fn build_backend(
4242
_ => unreachable!(),
4343
}
4444

45-
cmd.env("RUSTFLAGS", rustflags);
45+
rustflags_to_cmd_env(&mut cmd, "RUSTFLAGS", &rustflags);
4646

4747
eprintln!("[BUILD] rustc_codegen_cranelift");
48-
super::utils::spawn_and_wait(cmd);
48+
crate::utils::spawn_and_wait(cmd);
4949

5050
CG_CLIF
5151
.target_dir(dirs)

compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use std::fs;
22
use std::path::{Path, PathBuf};
33
use std::process::Command;
44

5-
use super::path::{Dirs, RelPath};
6-
use super::rustc_info::get_file_name;
7-
use super::utils::{
5+
use crate::path::{Dirs, RelPath};
6+
use crate::rustc_info::get_file_name;
7+
use crate::utils::{
88
maybe_incremental, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler,
99
LogGroup,
1010
};
11-
use super::{CodegenBackend, SysrootKind};
11+
use crate::{config, CodegenBackend, SysrootKind};
1212

1313
static DIST_DIR: RelPath = RelPath::DIST;
1414
static BIN_DIR: RelPath = RelPath::DIST.join("bin");
@@ -128,8 +128,8 @@ pub(crate) fn build_sysroot(
128128
cargo: bootstrap_host_compiler.cargo.clone(),
129129
rustc: rustc_clif.clone(),
130130
rustdoc: rustdoc_clif.clone(),
131-
rustflags: String::new(),
132-
rustdocflags: String::new(),
131+
rustflags: vec![],
132+
rustdocflags: vec![],
133133
triple: target_triple,
134134
runner: vec![],
135135
}
@@ -185,7 +185,7 @@ fn build_sysroot_for_triple(
185185

186186
#[must_use]
187187
fn build_llvm_sysroot_for_triple(compiler: Compiler) -> SysrootTarget {
188-
let default_sysroot = super::rustc_info::get_default_sysroot(&compiler.rustc);
188+
let default_sysroot = crate::rustc_info::get_default_sysroot(&compiler.rustc);
189189

190190
let mut target_libs = SysrootTarget { triple: compiler.triple, libs: vec![] };
191191

@@ -234,32 +234,32 @@ fn build_clif_sysroot_for_triple(
234234

235235
let build_dir = STANDARD_LIBRARY.target_dir(dirs).join(&compiler.triple).join(channel);
236236

237-
if !super::config::get_bool("keep_sysroot") {
237+
if !config::get_bool("keep_sysroot") {
238238
// Cleanup the deps dir, but keep build scripts and the incremental cache for faster
239239
// recompilation as they are not affected by changes in cg_clif.
240240
remove_dir_if_exists(&build_dir.join("deps"));
241241
}
242242

243243
// Build sysroot
244-
let mut rustflags = " -Zforce-unstable-if-unmarked -Cpanic=abort".to_string();
244+
let mut rustflags = vec!["-Zforce-unstable-if-unmarked".to_owned(), "-Cpanic=abort".to_owned()];
245245
match cg_clif_dylib_path {
246246
CodegenBackend::Local(path) => {
247-
rustflags.push_str(&format!(" -Zcodegen-backend={}", path.to_str().unwrap()));
247+
rustflags.push(format!("-Zcodegen-backend={}", path.to_str().unwrap()));
248248
}
249249
CodegenBackend::Builtin(name) => {
250-
rustflags.push_str(&format!(" -Zcodegen-backend={name}"));
250+
rustflags.push(format!("-Zcodegen-backend={name}"));
251251
}
252252
};
253253
// Necessary for MinGW to find rsbegin.o and rsend.o
254-
rustflags
255-
.push_str(&format!(" --sysroot {}", RTSTARTUP_SYSROOT.to_path(dirs).to_str().unwrap()));
254+
rustflags.push("--sysroot".to_owned());
255+
rustflags.push(RTSTARTUP_SYSROOT.to_path(dirs).to_str().unwrap().to_owned());
256256
if channel == "release" {
257257
// Incremental compilation by default disables mir inlining. This leads to both a decent
258258
// compile perf and a significant runtime perf regression. As such forcefully enable mir
259259
// inlining.
260-
rustflags.push_str(" -Zinline-mir");
260+
rustflags.push("-Zinline-mir".to_owned());
261261
}
262-
compiler.rustflags += &rustflags;
262+
compiler.rustflags.extend(rustflags);
263263
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
264264
maybe_incremental(&mut build_cmd);
265265
if channel == "release" {
@@ -289,8 +289,8 @@ fn build_clif_sysroot_for_triple(
289289
}
290290

291291
fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {
292-
if !super::config::get_bool("keep_sysroot") {
293-
super::prepare::prepare_stdlib(dirs, &compiler.rustc);
292+
if !config::get_bool("keep_sysroot") {
293+
crate::prepare::prepare_stdlib(dirs, &compiler.rustc);
294294
}
295295

296296
if !compiler.triple.ends_with("windows-gnu") {
@@ -306,6 +306,7 @@ fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {
306306
let obj = RTSTARTUP_SYSROOT.to_path(dirs).join(format!("{file}.o"));
307307
let mut build_rtstartup_cmd = Command::new(&compiler.rustc);
308308
build_rtstartup_cmd
309+
.arg("-Ainternal_features") // Missing #[allow(internal_features)]
309310
.arg("--target")
310311
.arg(&compiler.triple)
311312
.arg("--emit=obj")

compiler/rustc_codegen_cranelift/build_system/main.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ mod config;
1616
mod path;
1717
mod prepare;
1818
mod rustc_info;
19+
mod shared_utils;
1920
mod tests;
2021
mod utils;
2122

@@ -169,8 +170,8 @@ fn main() {
169170
cargo,
170171
rustc,
171172
rustdoc,
172-
rustflags: String::new(),
173-
rustdocflags: String::new(),
173+
rustflags: vec![],
174+
rustdocflags: vec![],
174175
triple,
175176
runner: vec![],
176177
}

compiler/rustc_codegen_cranelift/build_system/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fs;
22
use std::path::PathBuf;
33

4-
use super::utils::remove_dir_if_exists;
4+
use crate::utils::remove_dir_if_exists;
55

66
#[derive(Debug, Clone)]
77
pub(crate) struct Dirs {

compiler/rustc_codegen_cranelift/build_system/prepare.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ use std::fs;
33
use std::path::{Path, PathBuf};
44
use std::process::Command;
55

6-
use super::build_sysroot::STDLIB_SRC;
7-
use super::path::{Dirs, RelPath};
8-
use super::rustc_info::get_default_sysroot;
9-
use super::utils::{
6+
use crate::build_sysroot::STDLIB_SRC;
7+
use crate::path::{Dirs, RelPath};
8+
use crate::rustc_info::get_default_sysroot;
9+
use crate::utils::{
1010
copy_dir_recursively, git_command, remove_dir_if_exists, retry_spawn_and_wait, spawn_and_wait,
1111
};
1212

1313
pub(crate) fn prepare(dirs: &Dirs) {
1414
RelPath::DOWNLOAD.ensure_exists(dirs);
15-
super::tests::RAND_REPO.fetch(dirs);
16-
super::tests::REGEX_REPO.fetch(dirs);
17-
super::tests::PORTABLE_SIMD_REPO.fetch(dirs);
15+
crate::tests::RAND_REPO.fetch(dirs);
16+
crate::tests::REGEX_REPO.fetch(dirs);
17+
crate::tests::PORTABLE_SIMD_REPO.fetch(dirs);
1818
}
1919

2020
pub(crate) fn prepare_stdlib(dirs: &Dirs, rustc: &Path) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This file is used by both the build system as well as cargo-clif.rs
2+
3+
// Adapted from https://github.com/rust-lang/cargo/blob/6dc1deaddf62c7748c9097c7ea88e9ec77ff1a1a/src/cargo/core/compiler/build_context/target_info.rs#L750-L77
4+
pub(crate) fn rustflags_from_env(kind: &str) -> Vec<String> {
5+
// First try CARGO_ENCODED_RUSTFLAGS from the environment.
6+
// Prefer this over RUSTFLAGS since it's less prone to encoding errors.
7+
if let Ok(a) = std::env::var(format!("CARGO_ENCODED_{}", kind)) {
8+
if a.is_empty() {
9+
return Vec::new();
10+
}
11+
return a.split('\x1f').map(str::to_string).collect();
12+
}
13+
14+
// Then try RUSTFLAGS from the environment
15+
if let Ok(a) = std::env::var(kind) {
16+
let args = a.split(' ').map(str::trim).filter(|s| !s.is_empty()).map(str::to_string);
17+
return args.collect();
18+
}
19+
20+
// No rustflags to be collected from the environment
21+
Vec::new()
22+
}
23+
24+
pub(crate) fn rustflags_to_cmd_env(cmd: &mut std::process::Command, kind: &str, flags: &[String]) {
25+
cmd.env(format!("CARGO_ENCODED_{}", kind), flags.join("\x1f"));
26+
}

compiler/rustc_codegen_cranelift/build_system/tests.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
use super::build_sysroot;
2-
use super::config;
3-
use super::path::{Dirs, RelPath};
4-
use super::prepare::{apply_patches, GitRepo};
5-
use super::rustc_info::get_default_sysroot;
6-
use super::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler, LogGroup};
7-
use super::{CodegenBackend, SysrootKind};
8-
use std::env;
91
use std::ffi::OsStr;
102
use std::fs;
113
use std::path::PathBuf;
124
use std::process::Command;
135

6+
use crate::build_sysroot;
7+
use crate::config;
8+
use crate::path::{Dirs, RelPath};
9+
use crate::prepare::{apply_patches, GitRepo};
10+
use crate::rustc_info::get_default_sysroot;
11+
use crate::shared_utils::rustflags_from_env;
12+
use crate::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler, LogGroup};
13+
use crate::{CodegenBackend, SysrootKind};
14+
1415
static BUILD_EXAMPLE_OUT_DIR: RelPath = RelPath::BUILD.join("example");
1516

1617
struct TestCase {
@@ -306,7 +307,7 @@ pub(crate) fn run_tests(
306307
);
307308
// Rust's build system denies a couple of lints that trigger on several of the test
308309
// projects. Changing the code to fix them is not worth it, so just silence all lints.
309-
target_compiler.rustflags += " --cap-lints=allow";
310+
target_compiler.rustflags.push("--cap-lints=allow".to_owned());
310311

311312
let runner = TestRunner::new(
312313
dirs.clone(),
@@ -350,18 +351,15 @@ impl<'a> TestRunner<'a> {
350351
is_native: bool,
351352
stdlib_source: PathBuf,
352353
) -> Self {
353-
if let Ok(rustflags) = env::var("RUSTFLAGS") {
354-
target_compiler.rustflags.push(' ');
355-
target_compiler.rustflags.push_str(&rustflags);
356-
}
357-
if let Ok(rustdocflags) = env::var("RUSTDOCFLAGS") {
358-
target_compiler.rustdocflags.push(' ');
359-
target_compiler.rustdocflags.push_str(&rustdocflags);
360-
}
354+
target_compiler.rustflags.extend(rustflags_from_env("RUSTFLAGS"));
355+
target_compiler.rustdocflags.extend(rustflags_from_env("RUSTDOCFLAGS"));
361356

362357
// FIXME fix `#[linkage = "extern_weak"]` without this
363358
if target_compiler.triple.contains("darwin") {
364-
target_compiler.rustflags.push_str(" -Clink-arg=-undefined -Clink-arg=dynamic_lookup");
359+
target_compiler.rustflags.extend([
360+
"-Clink-arg=-undefined".to_owned(),
361+
"-Clink-arg=dynamic_lookup".to_owned(),
362+
]);
365363
}
366364

367365
let jit_supported = use_unstable_features
@@ -470,7 +468,7 @@ impl<'a> TestRunner<'a> {
470468
S: AsRef<OsStr>,
471469
{
472470
let mut cmd = Command::new(&self.target_compiler.rustc);
473-
cmd.args(self.target_compiler.rustflags.split_whitespace());
471+
cmd.args(&self.target_compiler.rustflags);
474472
cmd.arg("-L");
475473
cmd.arg(format!("crate={}", BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).display()));
476474
cmd.arg("--out-dir");

compiler/rustc_codegen_cranelift/build_system/usage.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ REQUIREMENTS:
4343
* Rustup: By default rustup is used to install the right nightly version. If you don't want to
4444
use rustup, you can manually install the nightly version indicated by rust-toolchain.toml and
4545
point the CARGO, RUSTC and RUSTDOC env vars to the right executables.
46-
* Git: `./y.sh prepare` uses git for applying patches and on Windows for downloading test repos.
46+
* Git: Git is used for applying patches and on Windows for downloading test repos.
4747
* Curl and tar (non-Windows only): Used by `./y.sh prepare` to download a single commit for
4848
repos. Git will be used to clone the whole repo when using Windows.
4949
* [Hyperfine](https://github.com/sharkdp/hyperfine/): Used for benchmarking with `./y.sh bench`.

compiler/rustc_codegen_cranelift/build_system/utils.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ use std::path::{Path, PathBuf};
55
use std::process::{self, Command, Stdio};
66
use std::sync::atomic::{AtomicBool, Ordering};
77

8-
use super::path::{Dirs, RelPath};
8+
use crate::path::{Dirs, RelPath};
9+
use crate::shared_utils::rustflags_to_cmd_env;
910

1011
#[derive(Clone, Debug)]
1112
pub(crate) struct Compiler {
1213
pub(crate) cargo: PathBuf,
1314
pub(crate) rustc: PathBuf,
1415
pub(crate) rustdoc: PathBuf,
15-
pub(crate) rustflags: String,
16-
pub(crate) rustdocflags: String,
16+
pub(crate) rustflags: Vec<String>,
17+
pub(crate) rustdocflags: Vec<String>,
1718
pub(crate) triple: String,
1819
pub(crate) runner: Vec<String>,
1920
}
@@ -23,8 +24,8 @@ impl Compiler {
2324
match self.triple.as_str() {
2425
"aarch64-unknown-linux-gnu" => {
2526
// We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
26-
self.rustflags += " -Clinker=aarch64-linux-gnu-gcc";
27-
self.rustdocflags += " -Clinker=aarch64-linux-gnu-gcc";
27+
self.rustflags.push("-Clinker=aarch64-linux-gnu-gcc".to_owned());
28+
self.rustdocflags.push("-Clinker=aarch64-linux-gnu-gcc".to_owned());
2829
self.runner = vec![
2930
"qemu-aarch64".to_owned(),
3031
"-L".to_owned(),
@@ -33,8 +34,8 @@ impl Compiler {
3334
}
3435
"s390x-unknown-linux-gnu" => {
3536
// We are cross-compiling for s390x. Use the correct linker and run tests in qemu.
36-
self.rustflags += " -Clinker=s390x-linux-gnu-gcc";
37-
self.rustdocflags += " -Clinker=s390x-linux-gnu-gcc";
37+
self.rustflags.push("-Clinker=s390x-linux-gnu-gcc".to_owned());
38+
self.rustdocflags.push("-Clinker=s390x-linux-gnu-gcc".to_owned());
3839
self.runner = vec![
3940
"qemu-s390x".to_owned(),
4041
"-L".to_owned(),
@@ -100,8 +101,8 @@ impl CargoProject {
100101

101102
cmd.env("RUSTC", &compiler.rustc);
102103
cmd.env("RUSTDOC", &compiler.rustdoc);
103-
cmd.env("RUSTFLAGS", &compiler.rustflags);
104-
cmd.env("RUSTDOCFLAGS", &compiler.rustdocflags);
104+
rustflags_to_cmd_env(&mut cmd, "RUSTFLAGS", &compiler.rustflags);
105+
rustflags_to_cmd_env(&mut cmd, "RUSTDOCFLAGS", &compiler.rustdocflags);
105106
if !compiler.runner.is_empty() {
106107
cmd.env(
107108
format!("CARGO_TARGET_{}_RUNNER", compiler.triple.to_uppercase().replace('-', "_")),

0 commit comments

Comments
 (0)