about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorWeihang Lo <me@weihanglo.tw>2023-03-15 12:50:04 +0000
committerWeihang Lo <me@weihanglo.tw>2023-04-16 19:32:12 +0100
commitf795a150fe01b68bdd62503c39fbdc9ed04a5219 (patch)
tree90800391f33f44db6099cb110acfb7a2540bbe82 /src
parent8a778ca1e35e4a8df95c00d800100d95e63e7722 (diff)
chore: allow `cargo` to have its own workspace
This also

* bumps cargo to the latest in rust-lang/cargo.
* adds 0BSD to allowed list of licenses

Co-authored-by: Scott Schafer <schaferjscott@gmail.com>
Co-authored-by: Eric Huss <eric@huss.org>
Diffstat (limited to 'src')
-rw-r--r--src/bootstrap/bootstrap.py3
-rw-r--r--src/bootstrap/dist.rs3
-rw-r--r--src/bootstrap/tool.rs5
m---------src/tools/cargo0
-rw-r--r--src/tools/tidy/src/deps.rs68
5 files changed, 49 insertions, 30 deletions
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index 025145244c4..0f3a9f96826 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -822,7 +822,8 @@ class RustBuild(object):
         if self.use_vendored_sources:
             vendor_dir = os.path.join(self.rust_root, 'vendor')
             if not os.path.exists(vendor_dir):
-                sync_dirs = "--sync ./src/tools/rust-analyzer/Cargo.toml " \
+                sync_dirs = "--sync ./src/tools/cargo/Cargo.toml " \
+                            "--sync ./src/tools/rust-analyzer/Cargo.toml " \
                             "--sync ./compiler/rustc_codegen_cranelift/Cargo.toml " \
                             "--sync ./src/bootstrap/Cargo.toml "
                 print('error: vendoring required, but vendor directory does not exist.')
diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs
index 9498b772f58..372d0708c5b 100644
--- a/src/bootstrap/dist.rs
+++ b/src/bootstrap/dist.rs
@@ -996,12 +996,15 @@ impl Step for PlainSourceTarball {
         // If we're building from git sources, we need to vendor a complete distribution.
         if builder.rust_info().is_managed_git_subrepository() {
             // Ensure we have the submodules checked out.
+            builder.update_submodule(Path::new("src/tools/cargo"));
             builder.update_submodule(Path::new("src/tools/rust-analyzer"));
 
             // Vendor all Cargo dependencies
             let mut cmd = Command::new(&builder.initial_cargo);
             cmd.arg("vendor")
                 .arg("--sync")
+                .arg(builder.src.join("./src/tools/cargo/Cargo.toml"))
+                .arg("--sync")
                 .arg(builder.src.join("./src/tools/rust-analyzer/Cargo.toml"))
                 .arg("--sync")
                 .arg(builder.src.join("./compiler/rustc_codegen_cranelift/Cargo.toml"))
diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs
index d1fd2e8c42c..1cea3495ade 100644
--- a/src/bootstrap/tool.rs
+++ b/src/bootstrap/tool.rs
@@ -124,7 +124,7 @@ impl Step for ToolBuild {
         let is_expected = compile::stream_cargo(builder, cargo, vec![], &mut |msg| {
             // Only care about big things like the RLS/Cargo for now
             match tool {
-                "rls" | "cargo" | "clippy-driver" | "miri" | "rustfmt" => {}
+                "rls" | "clippy-driver" | "miri" | "rustfmt" => {}
 
                 _ => return,
             }
@@ -301,6 +301,9 @@ pub fn prepare_tool_cargo(
             cargo.env("LIBZ_SYS_STATIC", "1");
             features.push("rustc-workspace-hack/all-static".to_string());
         }
+        if path.ends_with("cargo") {
+            features.push("all-static".to_string());
+        }
     }
 
     // clippy tests need to know about the stage sysroot. Set them consistently while building to
diff --git a/src/tools/cargo b/src/tools/cargo
-Subproject 84b7041fd2745ee6b3b4a150314f81aabb78e6b
+Subproject d0a4cbcee614fdb7ba66e860e603a00a644d71f
diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs
index a9eb6c8d03f..c80557fb757 100644
--- a/src/tools/tidy/src/deps.rs
+++ b/src/tools/tidy/src/deps.rs
@@ -18,6 +18,7 @@ const LICENSES: &[&str] = &[
     "ISC",
     "Unlicense/MIT",
     "Unlicense OR MIT",
+    "0BSD",
     "0BSD OR MIT OR Apache-2.0",                // adler license
     "Zlib OR Apache-2.0 OR MIT",                // tinyvec
     "MIT OR Apache-2.0 OR Zlib",                // tinyvec_macros
@@ -33,30 +34,35 @@ const LICENSES: &[&str] = &[
 const EXCEPTIONS: &[(&str, &str)] = &[
     ("ar_archive_writer", "Apache-2.0 WITH LLVM-exception"), // rustc
     ("mdbook", "MPL-2.0"),                                   // mdbook
-    ("openssl", "Apache-2.0"),                               // cargo, mdbook
     ("colored", "MPL-2.0"),                                  // rustfmt
     ("ryu", "Apache-2.0 OR BSL-1.0"),                        // cargo/... (because of serde)
-    ("bytesize", "Apache-2.0"),                              // cargo
-    ("im-rc", "MPL-2.0+"),                                   // cargo
-    ("sized-chunks", "MPL-2.0+"),                            // cargo via im-rc
-    ("bitmaps", "MPL-2.0+"),                                 // cargo via im-rc
-    ("fiat-crypto", "MIT OR Apache-2.0 OR BSD-1-Clause"),    // cargo via pasetors
-    ("subtle", "BSD-3-Clause"),                              // cargo via pasetors
-    ("dunce", "CC0-1.0 OR MIT-0"),                           // cargo via gix (and dev dependency)
-    ("imara-diff", "Apache-2.0"),                            // cargo via gix
-    ("sha1_smol", "BSD-3-Clause"),                           // cargo via gix
-    ("unicode-bom", "Apache-2.0"),                           // cargo via gix
     ("instant", "BSD-3-Clause"), // rustc_driver/tracing-subscriber/parking_lot
     ("snap", "BSD-3-Clause"),    // rustc
     ("fluent-langneg", "Apache-2.0"), // rustc (fluent translations)
     ("self_cell", "Apache-2.0"), // rustc (fluent translations)
     // FIXME: this dependency violates the documentation comment above:
     ("fortanix-sgx-abi", "MPL-2.0"), // libstd but only for `sgx` target
-    ("similar", "Apache-2.0"),       // cargo (dev dependency)
-    ("normalize-line-endings", "Apache-2.0"), // cargo (dev dependency)
     ("dissimilar", "Apache-2.0"),    // rustdoc, rustc_lexer (few tests) via expect-test, (dev deps)
 ];
 
+const EXCEPTIONS_CARGO: &[(&str, &str)] = &[
+    ("bitmaps", "MPL-2.0+"),
+    ("bytesize", "Apache-2.0"),
+    ("dunce", "CC0-1.0 OR MIT-0"),
+    ("fiat-crypto", "MIT OR Apache-2.0 OR BSD-1-Clause"),
+    ("im-rc", "MPL-2.0+"),
+    ("imara-diff", "Apache-2.0"),
+    ("instant", "BSD-3-Clause"),
+    ("normalize-line-endings", "Apache-2.0"),
+    ("openssl", "Apache-2.0"),
+    ("ryu", "Apache-2.0 OR BSL-1.0"),
+    ("sha1_smol", "BSD-3-Clause"),
+    ("similar", "Apache-2.0"),
+    ("sized-chunks", "MPL-2.0+"),
+    ("subtle", "BSD-3-Clause"),
+    ("unicode-bom", "Apache-2.0"),
+];
+
 const EXCEPTIONS_CRANELIFT: &[(&str, &str)] = &[
     ("cranelift-bforest", "Apache-2.0 WITH LLVM-exception"),
     ("cranelift-codegen", "Apache-2.0 WITH LLVM-exception"),
@@ -156,7 +162,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
     "lazy_static",
     "libc",
     "libloading",
-    "libz-sys",
     "litemap",
     "lock_api",
     "log",
@@ -177,7 +182,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
     "perf-event-open-sys",
     "petgraph",
     "pin-project-lite",
-    "pkg-config",
     "polonius-engine",
     "ppv-lite86",
     "proc-macro-hack",
@@ -217,7 +221,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
     "stable_deref_trait",
     "stacker",
     "static_assertions",
-    "subtle", // dependency of cargo (via pasetors)
     "syn",
     "synstructure",
     "tempfile",
@@ -256,7 +259,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
     "unicode-security",
     "unicode-width",
     "unicode-xid",
-    "vcpkg",
     "valuable",
     "version_check",
     "wasi",
@@ -359,8 +361,18 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
         &["rustc_driver", "rustc_codegen_llvm"],
         bad,
     );
-    check_crate_duplicate(&metadata, FORBIDDEN_TO_HAVE_DUPLICATES, bad);
-    check_rustfix(&metadata, bad);
+    check_crate_duplicate(&metadata, &[], bad);
+
+    // Check cargo independently as it has it's own workspace.
+    let mut cmd = cargo_metadata::MetadataCommand::new();
+    cmd.cargo_path(cargo)
+        .manifest_path(root.join("src/tools/cargo/Cargo.toml"))
+        .features(cargo_metadata::CargoOpt::AllFeatures);
+    let cargo_metadata = t!(cmd.exec());
+    let runtime_ids = HashSet::new();
+    check_license_exceptions(&cargo_metadata, EXCEPTIONS_CARGO, runtime_ids, bad);
+    check_crate_duplicate(&cargo_metadata, FORBIDDEN_TO_HAVE_DUPLICATES, bad);
+    check_rustfix(&metadata, &cargo_metadata, bad);
 
     // Check rustc_codegen_cranelift independently as it has it's own workspace.
     let mut cmd = cargo_metadata::MetadataCommand::new();
@@ -606,19 +618,19 @@ fn deps_of_filtered<'a>(
     }
 }
 
-fn direct_deps_of<'a>(metadata: &'a Metadata, pkg_id: &'a PackageId) -> Vec<&'a Package> {
+fn direct_deps_of<'a>(metadata: &'a Metadata, pkg_id: &'a PackageId) -> impl Iterator<Item = &'a Package> {
     let resolve = metadata.resolve.as_ref().unwrap();
     let node = resolve.nodes.iter().find(|n| &n.id == pkg_id).unwrap();
-    node.deps.iter().map(|dep| pkg_from_id(metadata, &dep.pkg)).collect()
+    node.deps.iter().map(|dep| pkg_from_id(metadata, &dep.pkg))
 }
 
-fn check_rustfix(metadata: &Metadata, bad: &mut bool) {
-    let cargo = pkg_from_name(metadata, "cargo");
-    let compiletest = pkg_from_name(metadata, "compiletest");
-    let cargo_deps = direct_deps_of(metadata, &cargo.id);
-    let compiletest_deps = direct_deps_of(metadata, &compiletest.id);
-    let cargo_rustfix = cargo_deps.iter().find(|p| p.name == "rustfix").unwrap();
-    let compiletest_rustfix = compiletest_deps.iter().find(|p| p.name == "rustfix").unwrap();
+fn check_rustfix(rust_metadata: &Metadata, cargo_metadata: &Metadata, bad: &mut bool) {
+    let cargo = pkg_from_name(cargo_metadata, "cargo");
+    let cargo_rustfix = direct_deps_of(cargo_metadata, &cargo.id).find(|p| p.name == "rustfix").unwrap();
+
+    let compiletest = pkg_from_name(rust_metadata, "compiletest");
+    let compiletest_rustfix = direct_deps_of(rust_metadata, &compiletest.id).find(|p| p.name == "rustfix").unwrap();
+
     if cargo_rustfix.version != compiletest_rustfix.version {
         tidy_error!(
             bad,