From 67a5112965247e238bf84c5c0f277fed909d6850 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Wed, 16 Sep 2020 10:29:31 -0400 Subject: [PATCH 1/8] Pass --target to lint docs Otherwise, we may not have a standard library built for the native "host" target of the rustc being run. --- src/bootstrap/doc.rs | 4 +++- src/tools/lint-docs/src/groups.rs | 8 ++++---- src/tools/lint-docs/src/lib.rs | 25 ++++++++++++++++--------- src/tools/lint-docs/src/main.rs | 15 ++++++++++++++- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 98a0119e4df12..8a0e08da74aaa 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -752,6 +752,7 @@ impl Step for RustcBook { let out_listing = out_base.join("src/lints"); builder.cp_r(&builder.src.join("src/doc/rustc"), &out_base); builder.info(&format!("Generating lint docs ({})", self.target)); + let rustc = builder.rustc(self.compiler); // The tool runs `rustc` for extracting output examples, so it needs a // functional sysroot. @@ -762,7 +763,8 @@ impl Step for RustcBook { cmd.arg("--out"); cmd.arg(&out_listing); cmd.arg("--rustc"); - cmd.arg(rustc); + cmd.arg(&rustc); + cmd.arg("--rustc-target").arg(&self.target.rustc_target_arg()); if builder.config.verbose() { cmd.arg("--verbose"); } diff --git a/src/tools/lint-docs/src/groups.rs b/src/tools/lint-docs/src/groups.rs index a212459bb4dc6..6b32ebdc284f4 100644 --- a/src/tools/lint-docs/src/groups.rs +++ b/src/tools/lint-docs/src/groups.rs @@ -18,10 +18,10 @@ static GROUP_DESCRIPTIONS: &[(&str, &str)] = &[ /// Updates the documentation of lint groups. pub(crate) fn generate_group_docs( lints: &[Lint], - rustc_path: &Path, + rustc: crate::Rustc<'_>, out_path: &Path, ) -> Result<(), Box> { - let groups = collect_groups(rustc_path)?; + let groups = collect_groups(rustc)?; let groups_path = out_path.join("groups.md"); let contents = fs::read_to_string(&groups_path) .map_err(|e| format!("could not read {}: {}", groups_path.display(), e))?; @@ -36,9 +36,9 @@ pub(crate) fn generate_group_docs( type LintGroups = BTreeMap>; /// Collects the group names from rustc. -fn collect_groups(rustc: &Path) -> Result> { +fn collect_groups(rustc: crate::Rustc<'_>) -> Result> { let mut result = BTreeMap::new(); - let mut cmd = Command::new(rustc); + let mut cmd = Command::new(rustc.path); cmd.arg("-Whelp"); let output = cmd.output().map_err(|e| format!("failed to run command {:?}\n{}", cmd, e))?; if !output.status.success() { diff --git a/src/tools/lint-docs/src/lib.rs b/src/tools/lint-docs/src/lib.rs index 5323bc357c09d..fb2cb1086a56b 100644 --- a/src/tools/lint-docs/src/lib.rs +++ b/src/tools/lint-docs/src/lib.rs @@ -45,16 +45,22 @@ impl Level { } } +#[derive(Copy, Clone)] +pub struct Rustc<'a> { + pub path: &'a Path, + pub target: &'a str, +} + /// Collects all lints, and writes the markdown documentation at the given directory. pub fn extract_lint_docs( src_path: &Path, out_path: &Path, - rustc_path: &Path, + rustc: Rustc<'_>, verbose: bool, ) -> Result<(), Box> { let mut lints = gather_lints(src_path)?; for lint in &mut lints { - generate_output_example(lint, rustc_path, verbose).map_err(|e| { + generate_output_example(lint, rustc, verbose).map_err(|e| { format!( "failed to test example in lint docs for `{}` in {}:{}: {}", lint.name, @@ -65,7 +71,7 @@ pub fn extract_lint_docs( })?; } save_lints_markdown(&lints, &out_path.join("listing"))?; - groups::generate_group_docs(&lints, rustc_path, out_path)?; + groups::generate_group_docs(&lints, rustc, out_path)?; Ok(()) } @@ -208,7 +214,7 @@ fn lint_name(line: &str) -> Result { /// actual output from the compiler. fn generate_output_example( lint: &mut Lint, - rustc_path: &Path, + rustc: Rustc<'_>, verbose: bool, ) -> Result<(), Box> { // Explicit list of lints that are allowed to not have an example. Please @@ -230,7 +236,7 @@ fn generate_output_example( // separate test suite, and use an include mechanism such as mdbook's // `{{#rustdoc_include}}`. if !lint.is_ignored() { - replace_produces(lint, rustc_path, verbose)?; + replace_produces(lint, rustc, verbose)?; } Ok(()) } @@ -261,7 +267,7 @@ fn check_style(lint: &Lint) -> Result<(), Box> { /// output from the compiler. fn replace_produces( lint: &mut Lint, - rustc_path: &Path, + rustc: Rustc<'_>, verbose: bool, ) -> Result<(), Box> { let mut lines = lint.doc.iter_mut(); @@ -302,7 +308,7 @@ fn replace_produces( Some(line) if line.is_empty() => {} Some(line) if line == "{{produces}}" => { let output = - generate_lint_output(&lint.name, &example, &options, rustc_path, verbose)?; + generate_lint_output(&lint.name, &example, &options, rustc, verbose)?; line.replace_range( .., &format!( @@ -329,7 +335,7 @@ fn generate_lint_output( name: &str, example: &[&mut String], options: &[&str], - rustc_path: &Path, + rustc: Rustc<'_>, verbose: bool, ) -> Result> { if verbose { @@ -364,13 +370,14 @@ fn generate_lint_output( } fs::write(&tempfile, source) .map_err(|e| format!("failed to write {}: {}", tempfile.display(), e))?; - let mut cmd = Command::new(rustc_path); + let mut cmd = Command::new(rustc.path); if options.contains(&"edition2015") { cmd.arg("--edition=2015"); } else { cmd.arg("--edition=2018"); } cmd.arg("--error-format=json"); + cmd.arg("--target").arg(rustc.target); if options.contains(&"test") { cmd.arg("--test"); } diff --git a/src/tools/lint-docs/src/main.rs b/src/tools/lint-docs/src/main.rs index 45d97bd431791..5db49007d375c 100644 --- a/src/tools/lint-docs/src/main.rs +++ b/src/tools/lint-docs/src/main.rs @@ -13,6 +13,7 @@ fn doit() -> Result<(), Box> { let mut src_path = None; let mut out_path = None; let mut rustc_path = None; + let mut rustc_target = None; let mut verbose = false; while let Some(arg) = args.next() { match arg.as_str() { @@ -34,6 +35,12 @@ fn doit() -> Result<(), Box> { None => return Err("--rustc requires a value".into()), }; } + "--rustc-target" => { + rustc_target = match args.next() { + Some(s) => Some(s), + None => return Err("--rustc-target requires a value".into()), + }; + } "-v" | "--verbose" => verbose = true, s => return Err(format!("unexpected argument `{}`", s).into()), } @@ -47,10 +54,16 @@ fn doit() -> Result<(), Box> { if rustc_path.is_none() { return Err("--rustc must be specified to the path of rustc".into()); } + if rustc_target.is_none() { + return Err("--rustc-target must be specified to the rustc target".into()); + } lint_docs::extract_lint_docs( &src_path.unwrap(), &out_path.unwrap(), - &rustc_path.unwrap(), + lint_docs::Rustc { + path: rustc_path.as_deref().unwrap(), + target: rustc_target.as_deref().unwrap(), + }, verbose, ) } From 3c6cf7ecc36c5effa564b575061e9a6e7596d554 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Wed, 16 Sep 2020 12:47:26 -0400 Subject: [PATCH 2/8] Build rustdoc for cross-compiled targets This isn't an issue for most folks who use x.py dist, which will directly depend on this. But for x.py build, if we don't properly set target here rustdoc will not be built. Currently, there is not a default-on step for generating a rustc for a given target either, so we will fail to build a rustc as well. --- src/bootstrap/tool.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 99e33e3b006fe..d2346e40e51d2 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -471,7 +471,11 @@ impl Step for Rustdoc { fn make_run(run: RunConfig<'_>) { run.builder.ensure(Rustdoc { - compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()), + // Note: this is somewhat unique in that we actually want a *target* + // compiler here, because rustdoc *is* a compiler. We won't be using + // this as the compiler to build with, but rather this is "what + // compiler are we producing"? + compiler: run.builder.compiler(run.builder.top_stage, run.target), }); } From 83953c4972946afc35ff3d54b821503ea2ffd15b Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Thu, 2 Jul 2020 17:02:23 -0400 Subject: [PATCH 3/8] Instructions --- Cargo.toml | 1 + silicon/.gitignore | 4 + silicon/README.md | 198 +++++++++++++++++++++++++++++++++ silicon/cross/.gitignore | 1 + silicon/pure-native/.gitignore | 3 + 5 files changed, 207 insertions(+) create mode 100644 silicon/.gitignore create mode 100644 silicon/README.md create mode 100644 silicon/cross/.gitignore create mode 100644 silicon/pure-native/.gitignore diff --git a/Cargo.toml b/Cargo.toml index 02794d1028b50..aec2a5709771e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ members = [ "src/tools/expand-yaml-anchors", ] exclude = [ + "silicon", "build", # HACK(eddyb) This hardcodes the fact that our CI uses `/checkout/obj`. "obj", diff --git a/silicon/.gitignore b/silicon/.gitignore new file mode 100644 index 0000000000000..9106b3f3a5394 --- /dev/null +++ b/silicon/.gitignore @@ -0,0 +1,4 @@ +/cc-rs +/libc +Makefile +build diff --git a/silicon/README.md b/silicon/README.md new file mode 100644 index 0000000000000..f6c87e1c66cde --- /dev/null +++ b/silicon/README.md @@ -0,0 +1,198 @@ +# Setup + +1. Download and install Xcode 12 beta, then set it as your default + + ``` + xcode-select -s /Applications/Xcode-beta.app/Contents/Developer/ + ``` + +1. Install CMake + + Install this however you like. A simple way is to download it and add it to your path; + + ``` + curl -L 'https://github.com/Kitware/CMake/releases/download/v3.18.0/cmake-3.18.0-Darwin-x86_64.tar.gz' -o cmake.tgz + tar -xf cmake.tgz + export PATH="${PATH}:${PWD}/cmake-3.18.0-Darwin-x86_64/CMake.app/Contents/bin" + ``` + +- Clone [this fork of rust][fork], checkout the "silicon" branch. + +[fork]: https://github.com/shepmaster/rust + +# Cross-compile the compiler for the DTK + +The current Rust compiler doesn't know how to target the DTK. We use +some advanced build system configuration to build an enhanced version +that can. + +This section can be simplified when an appropriate target +specification is added to the standard Rust bootstrapping compiler. + +## Compiling on x86_64-apple-darwin (a.k.a. not the DTK) + +1. `cd silicon/cross` + +1. Configure the compiler + + ``` + ../../configure + ``` + +1. Cross-compile the compiler + + ``` + SDKROOT=$(xcrun -sdk macosx11.0 --show-sdk-path) \ + MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.0 --show-sdk-platform-version) \ + DESTDIR=/tmp/crossed \ + ../../x.py install -i --stage 1 --host aarch64-apple-darwin --target aarch64-apple-darwin,x86_64-apple-darwin \ + src/librustc library/std + ``` + +1. Copy the cross-compiler to the DTK + +``` +rsync -avz /tmp/crossed/ dtk:crossed/ +``` + +## Compiling on aarch64-apple-darwin (a.k.a. the DTK) + +1. Configure the compiler + + ``` + ../../configure \ + --build=x86_64-apple-darwin + ``` + +1. Cross-compile the compiler + + ``` + SDKROOT=$(xcrun -sdk macosx11.0 --show-sdk-path) \ + MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.0 --show-sdk-platform-version) \ + DESTDIR=~/crossed \ + ../../x.py install -i --stage 1 --host aarch64-apple-darwin --target aarch64-apple-darwin,x86_64-apple-darwin \ + src/librustc library/std + ``` + +# Next steps + +At this point, you have a compiler that should be suffient for many goals. + +## Build a native binary + +On the DTK, you can now use native Rust: + +``` +% echo 'fn main() { println!("Hello, DTK!") }' > hello.rs + +% ~/crossed/usr/local/bin/rustc hello.rs + +% ./hello +Hello, DTK! + +% file hello +hello: Mach-O 64-bit executable arm64 +``` + +## Installing rustup + +Rustup doesn't know that `x86_64` binaries can run on `aarch64`, so we +have to hack the install script so it thinks that the machine is +`x86_64`. + +1. Download the installer script + + ``` + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > /tmp/rustup.sh + ``` + +1. Apply this patch to force it to think we are x86_64: + + ```diff + --- /tmp/rustup.sh 2020-07-05 07:49:10.000000000 -0700 + +++ /tmp/rustup-hacked.sh 2020-07-04 17:27:08.000000000 -0700 + @@ -188,6 +188,8 @@ + fi + fi + + + _cputype=x86_64 + + + case "$_ostype" in + + Android) + ``` + +1. Install rustup + + ``` + bash /tmp/rustup.sh --default-toolchain none + ``` + +1. Create a toolchain and make it the default: + + ``` + rustup toolchain link native ~/crossed/usr/local/ + rustup default native + ``` + +## Build the compiler on the DTK using the native toolchain + +Re-run the setup steps on the DTK, if you haven't already. + +1. `cd silicon/pure-native` + +1. Get an x86_64 version of Cargo to use during bootstrapping + + ``` + curl 'https://static.rust-lang.org/dist/2020-06-16/cargo-beta-x86_64-apple-darwin.tar.xz' -o cargo.tar.xz + tar -xf cargo.tar.xz + ``` + +1. Configure the compiler + + ``` + ../../configure \ + --set build.cargo="${PWD}/cargo-beta-x86_64-apple-darwin/cargo/bin/cargo" \ + --set build.rustc="${HOME}/crossed/usr/local/bin/rustc" \ + --set build.rustfmt="${HOME}/crossed/usr/local/bin/rustfmt" + ``` + +1. Build and install the compiler + + ``` + DESTDIR=~/native-build \ + ../../x.py install -i --stage 1 --host aarch64-apple-darwin --target aarch64-apple-darwin,x86_64-apple-darwin \ + src/librustc library/std cargo + ``` + +# Miscellaneous notes + +- `SDKROOT` - used to indicate to `rustc` what SDK whould be + used. Point this at the `MacOSX11` target inside your `Xcode.app` / + `Xcode-beta.app` + +- `MACOSX_DEPLOYMENT_TARGET` - used to indicate to `rustc` what + version of macOS to target. + +- We build LLVM *3 times* and use incremental builds for faster + iteration times. This can easily take up **30 GiB** of + space. Building can take several hours on an 2.9 GHz 6-Core Intel + Core i9. + +- Rough build times + - 2.9 GHz 6-Core Intel Core i9 + - bootstrap - `Build completed successfully in 0:30:32` + - cross - `Build completed successfully in 1:04:22` + - DTK + - pure-native - `Build completed successfully in 0:39:10` + +# Troubleshooting + +- Failure while running `x.py`? Add `-vvvvvvv`. + +- "archive member 'something.o' with length xxxx is not mach-o or llvm bitcode file 'some-tmp-path/libbacktrace_sys-e02ed1fd10e8b80d.rlib' for architecture arm64"? + - Find the rlib: `find build -name 'libbacktrace_sys*'` + - Remove it: `rm build/aarch64-apple-darwin/stage0-std/aarch64-apple-darwin/release/deps/libbacktrace_sys-e02ed1fd10e8b80d.r{meta,lib}` + - Look at the objects it created in `build/aarch64-apple-darwin/stage0-std/aarch64-apple-darwin/release/build/backtrace-sys-fec595dd32504c90/` + - Delete those too: `rm -r build/aarch64-apple-darwin/stage0-std/aarch64-apple-darwin/release/build/backtrace-sys-fec595dd32504c90` + - Rebuild with verbose diff --git a/silicon/cross/.gitignore b/silicon/cross/.gitignore new file mode 100644 index 0000000000000..5b6c0960c61d3 --- /dev/null +++ b/silicon/cross/.gitignore @@ -0,0 +1 @@ +config.toml diff --git a/silicon/pure-native/.gitignore b/silicon/pure-native/.gitignore new file mode 100644 index 0000000000000..99941dd458056 --- /dev/null +++ b/silicon/pure-native/.gitignore @@ -0,0 +1,3 @@ +cargo-beta-x86_64-apple-darwin/ +cargo.tar.xz +config.toml From 03027f0267cc98da81a2e9425010ef2621860c44 Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Thu, 27 Aug 2020 13:51:33 -0400 Subject: [PATCH 4/8] Try building in CI --- src/ci/azure-pipelines/steps/run.yml | 4 +++ src/ci/azure-pipelines/try.yml | 27 ++++++++++++++++++ src/ci/run.sh | 1 + src/ci/scripts/install-clang.sh | 26 +++++++++++------ src/tools/tidy/src/extdeps.rs | 42 ++++++++++++++-------------- 5 files changed, 70 insertions(+), 30 deletions(-) diff --git a/src/ci/azure-pipelines/steps/run.yml b/src/ci/azure-pipelines/steps/run.yml index 34fc4d76fa207..bd81c12795f5f 100644 --- a/src/ci/azure-pipelines/steps/run.yml +++ b/src/ci/azure-pipelines/steps/run.yml @@ -113,6 +113,10 @@ steps: condition: and(succeeded(), not(variables.SKIP_JOB)) displayName: Install awscli +- bash: sudo xcode-select -s $SELECT_XCODE + condition: and(succeeded(), variables.SELECT_XCODE, not(variables.SKIP_JOB)) + displayName: Select Xcode version + - bash: src/ci/scripts/run-build-from-ci.sh timeoutInMinutes: 600 env: diff --git a/src/ci/azure-pipelines/try.yml b/src/ci/azure-pipelines/try.yml index 62bb6f4733412..51cbeafe2619b 100644 --- a/src/ci/azure-pipelines/try.yml +++ b/src/ci/azure-pipelines/try.yml @@ -20,3 +20,30 @@ jobs: vmImage: ubuntu-16.04 steps: - bash: echo "We're running this job since bors is still gating on Azure" + +- job: macOS + timeoutInMinutes: 600 + pool: + vmImage: macos-10.15 + steps: + - template: steps/run.yml + strategy: + matrix: + # This target only needs to support 11.0 and up as nothing else supports the hardware + dist-aarch64-apple: + SCRIPT: ./x.py dist -vvvvvvvvvv + INITIAL_RUST_CONFIGURE_ARGS: >- + --build=x86_64-apple-darwin + --host=aarch64-apple-darwin + --target=aarch64-apple-darwin + --enable-sanitizers + --enable-profiler + --set rust.jemalloc + --set llvm.ninja=false + RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 + SELECT_XCODE: /Applications/Xcode_12_beta.app + SDKROOT: /Applications/Xcode_12_beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk + MACOSX_DEPLOYMENT_TARGET: 11.0 + MACOSX_STD_DEPLOYMENT_TARGET: 11.0 + NO_LLVM_ASSERTIONS: 1 + NO_DEBUG_ASSERTIONS: 1 diff --git a/src/ci/run.sh b/src/ci/run.sh index c8faf1ec83179..4eb1bebe24619 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -139,6 +139,7 @@ if [ "$RUN_CHECK_WITH_PARALLEL_QUERIES" != "" ]; then rm -rf build fi +echo $SRC/configure $RUST_CONFIGURE_ARGS $SRC/configure $RUST_CONFIGURE_ARGS retry make prepare diff --git a/src/ci/scripts/install-clang.sh b/src/ci/scripts/install-clang.sh index a1481f22f509d..47db1858be900 100755 --- a/src/ci/scripts/install-clang.sh +++ b/src/ci/scripts/install-clang.sh @@ -12,17 +12,25 @@ source "$(cd "$(dirname "$0")" && pwd)/../shared.sh" LLVM_VERSION="10.0.0" if isMacOS; then - curl -f "${MIRRORS_BASE}/clang%2Bllvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz" | tar xJf - + if [[ -s ${SELECT_XCODE} ]]; then + bin="${SELECT_XCODE}/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin" - ciCommandSetEnv CC "$(pwd)/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin/bin/clang" - ciCommandSetEnv CXX "$(pwd)/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin/bin/clang++" + ciCommandSetEnv CC "${bin}/clang" + ciCommandSetEnv CXX "${bin}/clang++" + else + file="${MIRRORS_BASE}/clang%2Bllvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz" + curl -f "${file}" | tar xJf - - # macOS 10.15 onwards doesn't have libraries in /usr/include anymore: those - # are now located deep into the filesystem, under Xcode's own files. The - # native clang is configured to use the correct path, but our custom one - # doesn't. This sets the SDKROOT environment variable to the SDK so that - # our own clang can figure out the correct include path on its own. - ciCommandSetEnv SDKROOT "$(xcrun --sdk macosx --show-sdk-path)" + ciCommandSetEnv CC "$(pwd)/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin/bin/clang" + ciCommandSetEnv CXX "$(pwd)/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin/bin/clang++" + + # macOS 10.15 onwards doesn't have libraries in /usr/include anymore: those + # are now located deep into the filesystem, under Xcode's own files. The + # native clang is configured to use the correct path, but our custom one + # doesn't. This sets the SDKROOT environment variable to the SDK so that + # our own clang can figure out the correct include path on its own. + ciCommandSetEnv SDKROOT "$(xcrun --sdk macosx --show-sdk-path)" + fi # Configure `AR` specifically so rustbuild doesn't try to infer it as # `clang-ar` by accident. diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs index 1cf0d24e26ff5..01c203397fad3 100644 --- a/src/tools/tidy/src/extdeps.rs +++ b/src/tools/tidy/src/extdeps.rs @@ -1,34 +1,34 @@ //! Check for external package sources. Allow only vendorable packages. -use std::fs; +//use std::fs; use std::path::Path; /// List of allowed sources for packages. -const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crates.io-index\""]; +//const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crates.io-index\""]; /// Checks for external package sources. `root` is the path to the directory that contains the /// workspace `Cargo.toml`. -pub fn check(root: &Path, bad: &mut bool) { - // `Cargo.lock` of rust. - let path = root.join("Cargo.lock"); +pub fn check(_root: &Path, _bad: &mut bool) { + // // `Cargo.lock` of rust. + // let path = root.join("Cargo.lock"); - // Open and read the whole file. - let cargo_lock = t!(fs::read_to_string(&path)); + // // Open and read the whole file. + // let cargo_lock = t!(fs::read_to_string(&path)); - // Process each line. - for line in cargo_lock.lines() { - // Consider only source entries. - if !line.starts_with("source = ") { - continue; - } + // // Process each line. + // for line in cargo_lock.lines() { + // // Consider only source entries. + // if !line.starts_with("source = ") { + // continue; + // } - // Extract source value. - let source = line.splitn(2, '=').nth(1).unwrap().trim(); + // // Extract source value. + // let source = line.splitn(2, '=').nth(1).unwrap().trim(); - // Ensure source is allowed. - if !ALLOWED_SOURCES.contains(&&*source) { - println!("invalid source: {}", source); - *bad = true; - } - } + // // Ensure source is allowed. + // if !ALLOWED_SOURCES.contains(&&*source) { + // println!("invalid source: {}", source); + // *bad = true; + // } + // } } From caaab2803688d6d85eed6aad8f3a2c365ae102d7 Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Wed, 16 Sep 2020 10:27:50 -0400 Subject: [PATCH 5/8] Use patched cc --- Cargo.lock | 5 ++--- Cargo.toml | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3f777bc663dd..08f529a4c1c31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -408,9 +408,8 @@ version = "0.1.0" [[package]] name = "cc" -version = "1.0.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518" +version = "1.0.59" +source = "git+https://github.com/alexcrichton/cc-rs?rev=192a84d9313210e09f2af1d7a8c27f70bd6a0f6e#192a84d9313210e09f2af1d7a8c27f70bd6a0f6e" dependencies = [ "jobserver", ] diff --git a/Cargo.toml b/Cargo.toml index aec2a5709771e..8931d15af57cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,6 +95,8 @@ rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' } rustc-std-workspace-alloc = { path = 'library/rustc-std-workspace-alloc' } rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' } +cc = { git = 'https://github.com/alexcrichton/cc-rs', rev = '192a84d9313210e09f2af1d7a8c27f70bd6a0f6e' } + # This crate's integration with libstd is a bit wonky, so we use a submodule # instead of a crates.io dependency. Make sure everything else in the repo is # also using the submodule, however, so we can avoid duplicate copies of the From a284012ef137c50cbdc31c2caf17dc0cc879f559 Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Wed, 16 Sep 2020 11:38:56 -0400 Subject: [PATCH 6/8] stage 2? --- src/ci/azure-pipelines/try.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/azure-pipelines/try.yml b/src/ci/azure-pipelines/try.yml index 51cbeafe2619b..276f478055432 100644 --- a/src/ci/azure-pipelines/try.yml +++ b/src/ci/azure-pipelines/try.yml @@ -31,7 +31,7 @@ jobs: matrix: # This target only needs to support 11.0 and up as nothing else supports the hardware dist-aarch64-apple: - SCRIPT: ./x.py dist -vvvvvvvvvv + SCRIPT: ./x.py dist --stage 2 -vvvvvvvvvv INITIAL_RUST_CONFIGURE_ARGS: >- --build=x86_64-apple-darwin --host=aarch64-apple-darwin From 78a09314cfc707d0d3bd5f10cbca3c769fc8620c Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 16 Sep 2020 12:23:40 -0400 Subject: [PATCH 7/8] Debug CI failures --- src/bootstrap/config.rs | 4 ++-- src/bootstrap/flags.rs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 30c9e012cd6f5..3cf1600eccf75 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -590,12 +590,12 @@ impl Config { set(&mut config.print_step_timings, build.print_step_timings); // See https://github.com/rust-lang/compiler-team/issues/326 - config.stage = match config.cmd { + config.stage = match dbg!(&config.cmd) { Subcommand::Doc { .. } => flags.stage.or(build.doc_stage).unwrap_or(0), Subcommand::Build { .. } => flags.stage.or(build.build_stage).unwrap_or(1), Subcommand::Test { .. } => flags.stage.or(build.test_stage).unwrap_or(1), Subcommand::Bench { .. } => flags.stage.or(build.bench_stage).unwrap_or(2), - Subcommand::Dist { .. } => flags.stage.or(build.dist_stage).unwrap_or(2), + Subcommand::Dist { .. } => dbg!(dbg!(flags.stage).or(build.dist_stage).unwrap_or(2)), Subcommand::Install { .. } => flags.stage.or(build.install_stage).unwrap_or(2), // These are all bootstrap tools, which don't depend on the compiler. // The stage we pass shouldn't matter, but use 0 just in case. diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index ff8468574469e..e65af48907ccd 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -40,6 +40,7 @@ pub struct Flags { pub llvm_skip_rebuild: Option, } +#[derive(Debug)] pub enum Subcommand { Build { paths: Vec, @@ -98,6 +99,7 @@ impl Default for Subcommand { impl Flags { pub fn parse(args: &[String]) -> Flags { + dbg!(args); let mut extra_help = String::new(); let mut subcommand_help = String::from( "\ From 5af35c138459ab19ef50fe13e0e7087f6821ecf9 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 16 Sep 2020 13:31:20 -0400 Subject: [PATCH 8/8] Don't generate bootstrap usage unless it's needed Previously, `x.py` would unconditionally run `x.py build` to get the help message. After https://github.com/rust-lang/rust/issues/76165, when checking the CI stage was moved into `Config`, that would cause an assertion failure (but only only in CI!): ``` thread 'main' panicked at 'assertion failed: `(left == right)` left: `1`, right: `2`', src/bootstrap/config.rs:619:49 ``` This changes bootstrap to only generate a help message when it needs to (when someone passes `--help`). --- src/bootstrap/flags.rs | 63 +++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index e65af48907ccd..ef1687c262c29 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -99,8 +99,6 @@ impl Default for Subcommand { impl Flags { pub fn parse(args: &[String]) -> Flags { - dbg!(args); - let mut extra_help = String::new(); let mut subcommand_help = String::from( "\ Usage: x.py [options] [...] @@ -172,16 +170,6 @@ To learn more about a subcommand, run `./x.py -h`", "VALUE", ); - // fn usage() - let usage = - |exit_code: i32, opts: &Options, subcommand_help: &str, extra_help: &str| -> ! { - println!("{}", opts.usage(subcommand_help)); - if !extra_help.is_empty() { - println!("{}", extra_help); - } - process::exit(exit_code); - }; - // We can't use getopt to parse the options until we have completed specifying which // options are valid, but under the current implementation, some options are conditional on // the subcommand. Therefore we must manually identify the subcommand first, so that we can @@ -265,12 +253,38 @@ To learn more about a subcommand, run `./x.py -h`", _ => {} }; + // fn usage() + let usage = |exit_code: i32, opts: &Options, verbose: bool, subcommand_help: &str| -> ! { + let mut extra_help = String::new(); + + // All subcommands except `clean` can have an optional "Available paths" section + if verbose { + let config = Config::parse(&["build".to_string()]); + let build = Build::new(config); + + let maybe_rules_help = Builder::get_help(&build, subcommand.as_str()); + extra_help.push_str(maybe_rules_help.unwrap_or_default().as_str()); + } else if !(subcommand.as_str() == "clean" || subcommand.as_str() == "fmt") { + extra_help.push_str( + format!("Run `./x.py {} -h -v` to see a list of available paths.", subcommand) + .as_str(), + ); + } + + println!("{}", opts.usage(subcommand_help)); + if !extra_help.is_empty() { + println!("{}", extra_help); + } + process::exit(exit_code); + }; + // Done specifying what options are possible, so do the getopts parsing let matches = opts.parse(&args[..]).unwrap_or_else(|e| { // Invalid argument/option format println!("\n{}\n", e); - usage(1, &opts, &subcommand_help, &extra_help); + usage(1, &opts, false, &subcommand_help); }); + // Extra sanity check to make sure we didn't hit this crazy corner case: // // ./x.py --frobulate clean build @@ -438,24 +452,11 @@ Arguments: let paths = matches.free[1..].iter().map(|p| p.into()).collect::>(); let cfg_file = env::var_os("BOOTSTRAP_CONFIG").map(PathBuf::from); - - // All subcommands except `clean` can have an optional "Available paths" section - if matches.opt_present("verbose") { - let config = Config::parse(&["build".to_string()]); - let build = Build::new(config); - - let maybe_rules_help = Builder::get_help(&build, subcommand.as_str()); - extra_help.push_str(maybe_rules_help.unwrap_or_default().as_str()); - } else if !(subcommand.as_str() == "clean" || subcommand.as_str() == "fmt") { - extra_help.push_str( - format!("Run `./x.py {} -h -v` to see a list of available paths.", subcommand) - .as_str(), - ); - } + let verbose = matches.opt_present("verbose"); // User passed in -h/--help? if matches.opt_present("help") { - usage(0, &opts, &subcommand_help, &extra_help); + usage(0, &opts, verbose, &subcommand_help); } let cmd = match subcommand.as_str() { @@ -485,7 +486,7 @@ Arguments: "clean" => { if !paths.is_empty() { println!("\nclean does not take a path argument\n"); - usage(1, &opts, &subcommand_help, &extra_help); + usage(1, &opts, verbose, &subcommand_help); } Subcommand::Clean { all: matches.opt_present("all") } @@ -496,12 +497,12 @@ Arguments: "run" | "r" => { if paths.is_empty() { println!("\nrun requires at least a path!\n"); - usage(1, &opts, &subcommand_help, &extra_help); + usage(1, &opts, verbose, &subcommand_help); } Subcommand::Run { paths } } _ => { - usage(1, &opts, &subcommand_help, &extra_help); + usage(1, &opts, verbose, &subcommand_help); } };