Skip to content

Commit 031ca67

Browse files
committed
Implement vendoring
1 parent 4e87f13 commit 031ca67

File tree

5 files changed

+52
-23
lines changed

5 files changed

+52
-23
lines changed

build_system/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ macro_rules! arg_error {
2929

3030
#[derive(PartialEq, Debug)]
3131
enum Command {
32+
Vendor,
3233
Prepare,
3334
Build,
3435
Test,
@@ -59,6 +60,7 @@ pub fn main() {
5960

6061
let mut args = env::args().skip(1);
6162
let command = match args.next().as_deref() {
63+
Some("vendor") => Command::Vendor,
6264
Some("prepare") => Command::Prepare,
6365
Some("build") => Command::Build,
6466
Some("test") => Command::Test,
@@ -79,6 +81,9 @@ pub fn main() {
7981
while let Some(arg) = args.next().as_deref() {
8082
match arg {
8183
"--out-dir" => {
84+
if command == Command::Vendor {
85+
arg_error!("vendor command doesn't accept --out-dir argument");
86+
}
8287
out_dir = PathBuf::from(args.next().unwrap_or_else(|| {
8388
arg_error!("--out-dir requires argument");
8489
}))
@@ -131,8 +136,11 @@ pub fn main() {
131136
std::fs::File::create(target).unwrap();
132137
}
133138

134-
if command == Command::Prepare {
135-
prepare::prepare(&dirs);
139+
if command == Command::Vendor {
140+
prepare::prepare(&dirs, true);
141+
process::exit(0);
142+
} else if command == Command::Prepare {
143+
prepare::prepare(&dirs, false);
136144
process::exit(0);
137145
}
138146

@@ -146,7 +154,7 @@ pub fn main() {
146154
use_unstable_features,
147155
);
148156
match command {
149-
Command::Prepare => {
157+
Command::Vendor | Command::Prepare => {
150158
// Handled above
151159
}
152160
Command::Test => {

build_system/prepare.rs

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,61 @@
11
use std::ffi::OsStr;
22
use std::fs;
33
use std::path::{Path, PathBuf};
4-
use std::process::Command;
4+
use std::process::{Command, Stdio};
55

66
use super::build_sysroot::{BUILD_SYSROOT, ORIG_BUILD_SYSROOT, SYSROOT_RUSTC_VERSION, SYSROOT_SRC};
77
use super::path::{Dirs, RelPath};
88
use super::rustc_info::{get_default_sysroot, get_rustc_version};
99
use super::utils::{copy_dir_recursively, git_command, retry_spawn_and_wait, spawn_and_wait};
1010

11-
pub(crate) fn prepare(dirs: &Dirs) {
11+
pub(crate) fn prepare(dirs: &Dirs, vendor: bool) {
1212
RelPath::DOWNLOAD.ensure_fresh(dirs);
1313

14-
spawn_and_wait(super::build_backend::CG_CLIF.fetch("cargo", dirs));
14+
if Path::new(".cargo/config.toml").exists() {
15+
std::fs::remove_file(".cargo/config.toml").unwrap();
16+
}
17+
18+
let mut cargo_workspaces = vec![super::build_backend::CG_CLIF.manifest_path(dirs)];
1519

1620
prepare_sysroot(dirs);
17-
spawn_and_wait(super::build_sysroot::STANDARD_LIBRARY.fetch("cargo", dirs));
18-
spawn_and_wait(super::tests::LIBCORE_TESTS.fetch("cargo", dirs));
21+
cargo_workspaces.push(super::build_sysroot::STANDARD_LIBRARY.manifest_path(dirs));
22+
cargo_workspaces.push(super::tests::LIBCORE_TESTS.manifest_path(dirs));
1923

2024
super::abi_cafe::ABI_CAFE_REPO.fetch(dirs);
21-
spawn_and_wait(super::abi_cafe::ABI_CAFE.fetch("cargo", dirs));
25+
cargo_workspaces.push(super::abi_cafe::ABI_CAFE.manifest_path(dirs));
2226
super::tests::RAND_REPO.fetch(dirs);
23-
spawn_and_wait(super::tests::RAND.fetch("cargo", dirs));
27+
cargo_workspaces.push(super::tests::RAND.manifest_path(dirs));
2428
super::tests::REGEX_REPO.fetch(dirs);
25-
spawn_and_wait(super::tests::REGEX.fetch("cargo", dirs));
29+
cargo_workspaces.push(super::tests::REGEX.manifest_path(dirs));
2630
super::tests::PORTABLE_SIMD_REPO.fetch(dirs);
27-
spawn_and_wait(super::tests::PORTABLE_SIMD.fetch("cargo", dirs));
31+
cargo_workspaces.push(super::tests::PORTABLE_SIMD.manifest_path(dirs));
2832
super::bench::SIMPLE_RAYTRACER_REPO.fetch(dirs);
29-
spawn_and_wait(super::bench::SIMPLE_RAYTRACER.fetch("cargo", dirs));
33+
cargo_workspaces.push(super::bench::SIMPLE_RAYTRACER.manifest_path(dirs));
34+
35+
if vendor {
36+
let mut vendor_cmd = Command::new("cargo");
37+
38+
vendor_cmd.arg("vendor").arg("--manifest-path").arg(&cargo_workspaces[0]);
39+
40+
for workspace in cargo_workspaces.iter().skip(1) {
41+
vendor_cmd.arg("--sync").arg(workspace);
42+
}
43+
44+
vendor_cmd.arg("download/vendor");
45+
46+
let vendor_output = vendor_cmd.stderr(Stdio::inherit()).output().unwrap();
47+
assert!(vendor_output.status.success());
48+
let replacement_config = String::from_utf8(vendor_output.stdout).unwrap();
49+
50+
std::fs::create_dir_all(".cargo").unwrap();
51+
std::fs::write(".cargo/config.toml", replacement_config).unwrap();
52+
} else {
53+
for workspace in &cargo_workspaces {
54+
let mut fetch_cmd = Command::new("cargo");
55+
fetch_cmd.arg("fetch").arg("--manifest-path").arg(workspace);
56+
spawn_and_wait(fetch_cmd)
57+
}
58+
}
3059
}
3160

3261
fn prepare_sysroot(dirs: &Dirs) {

build_system/usage.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
The build system of cg_clif.
22

33
USAGE:
4+
./y.rs vendor
45
./y.rs prepare [--out-dir DIR]
56
./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features]
67
./y.rs test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features]

build_system/utils.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,6 @@ impl CargoProject {
120120
cmd
121121
}
122122

123-
#[must_use]
124-
pub(crate) fn fetch(&self, cargo: impl AsRef<Path>, dirs: &Dirs) -> Command {
125-
let mut cmd = Command::new(cargo.as_ref());
126-
127-
cmd.arg("fetch").arg("--manifest-path").arg(self.manifest_path(dirs));
128-
129-
cmd
130-
}
131-
132123
pub(crate) fn clean(&self, dirs: &Dirs) {
133124
let _ = fs::remove_dir_all(self.target_dir(dirs));
134125
}

clean_all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
rm -rf target/ download/ build/ dist/ y.bin y.bin.dSYM y.exe y.pdb
4+
rm -rf .cargo/config.toml target/ download/ build/ dist/ y.bin y.bin.dSYM y.exe y.pdb
55

66
# Kept for now in case someone updates their checkout of cg_clif before running clean_all.sh
77
# FIXME remove at some point in the future

0 commit comments

Comments
 (0)