Skip to content

Commit d6677c4

Browse files
committed
Implement vendoring
1 parent 7095783 commit d6677c4

File tree

5 files changed

+52
-23
lines changed

5 files changed

+52
-23
lines changed

build_system/mod.rs

+11-3
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

+39-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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 crate::build_system::rustc_info::get_default_sysroot;
77

@@ -10,28 +10,57 @@ use super::path::{Dirs, RelPath};
1010
use super::rustc_info::get_rustc_version;
1111
use super::utils::{copy_dir_recursively, git_command, retry_spawn_and_wait, spawn_and_wait};
1212

13-
pub(crate) fn prepare(dirs: &Dirs) {
13+
pub(crate) fn prepare(dirs: &Dirs, vendor: bool) {
1414
if RelPath::DOWNLOAD.to_path(dirs).exists() {
1515
std::fs::remove_dir_all(RelPath::DOWNLOAD.to_path(dirs)).unwrap();
1616
}
1717
std::fs::create_dir_all(RelPath::DOWNLOAD.to_path(dirs)).unwrap();
1818

19-
spawn_and_wait(super::build_backend::CG_CLIF.fetch("cargo", dirs));
19+
if Path::new(".cargo/config.toml").exists() {
20+
std::fs::remove_file(".cargo/config.toml").unwrap();
21+
}
22+
23+
let mut cargo_workspaces = vec![super::build_backend::CG_CLIF.manifest_path(dirs)];
2024

2125
prepare_sysroot(dirs);
22-
spawn_and_wait(super::build_sysroot::STANDARD_LIBRARY.fetch("cargo", dirs));
23-
spawn_and_wait(super::tests::LIBCORE_TESTS.fetch("cargo", dirs));
26+
cargo_workspaces.push(super::build_sysroot::STANDARD_LIBRARY.manifest_path(dirs));
27+
cargo_workspaces.push(super::tests::LIBCORE_TESTS.manifest_path(dirs));
2428

2529
super::abi_cafe::ABI_CAFE_REPO.fetch(dirs);
26-
spawn_and_wait(super::abi_cafe::ABI_CAFE.fetch("cargo", dirs));
30+
cargo_workspaces.push(super::abi_cafe::ABI_CAFE.manifest_path(dirs));
2731
super::tests::RAND_REPO.fetch(dirs);
28-
spawn_and_wait(super::tests::RAND.fetch("cargo", dirs));
32+
cargo_workspaces.push(super::tests::RAND.manifest_path(dirs));
2933
super::tests::REGEX_REPO.fetch(dirs);
30-
spawn_and_wait(super::tests::REGEX.fetch("cargo", dirs));
34+
cargo_workspaces.push(super::tests::REGEX.manifest_path(dirs));
3135
super::tests::PORTABLE_SIMD_REPO.fetch(dirs);
32-
spawn_and_wait(super::tests::PORTABLE_SIMD.fetch("cargo", dirs));
36+
cargo_workspaces.push(super::tests::PORTABLE_SIMD.manifest_path(dirs));
3337
super::bench::SIMPLE_RAYTRACER_REPO.fetch(dirs);
34-
spawn_and_wait(super::bench::SIMPLE_RAYTRACER.fetch("cargo", dirs));
38+
cargo_workspaces.push(super::bench::SIMPLE_RAYTRACER.manifest_path(dirs));
39+
40+
if vendor {
41+
let mut vendor_cmd = Command::new("cargo");
42+
43+
vendor_cmd.arg("vendor").arg("--manifest-path").arg(&cargo_workspaces[0]);
44+
45+
for workspace in cargo_workspaces.iter().skip(1) {
46+
vendor_cmd.arg("--sync").arg(workspace);
47+
}
48+
49+
vendor_cmd.arg("download/vendor");
50+
51+
let vendor_output = vendor_cmd.stderr(Stdio::inherit()).output().unwrap();
52+
assert!(vendor_output.status.success());
53+
let replacement_config = String::from_utf8(vendor_output.stdout).unwrap();
54+
55+
std::fs::create_dir(".cargo").unwrap();
56+
std::fs::write(".cargo/config.toml", replacement_config).unwrap();
57+
} else {
58+
for workspace in &cargo_workspaces {
59+
let mut fetch_cmd = Command::new("cargo");
60+
fetch_cmd.arg("fetch").arg("--manifest-path").arg(workspace);
61+
spawn_and_wait(fetch_cmd)
62+
}
63+
}
3564
}
3665

3766
fn prepare_sysroot(dirs: &Dirs) {

build_system/usage.txt

+1
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

-9
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

+1-1
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)