Skip to content

Commit d6d0634

Browse files
authored
Merge pull request #865 from wesleywiser/windows_support
Add support for building rustc-perf and running the collector on Windows
2 parents fb20070 + 557ac4f commit d6d0634

File tree

10 files changed

+402
-112
lines changed

10 files changed

+402
-112
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ jobs:
3333
aws_secret_access_key: "${{ secrets.AWS_SECRET_ACCESS_KEY }}"
3434
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/deploy'
3535

36+
test_on_windows:
37+
name: Test on Windows
38+
runs-on: windows-latest
39+
steps:
40+
- name: Checkout the source code
41+
uses: actions/checkout@v2
42+
with:
43+
fetch-depth: 1
44+
45+
- name: Install latest beta
46+
uses: actions-rs/toolchain@v1
47+
with:
48+
toolchain: beta
49+
override: true
50+
51+
- name: cargo check
52+
run: cargo check
53+
3654
test_benchmarks:
3755
strategy:
3856
matrix:

Cargo.lock

Lines changed: 52 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collector/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ num_cpus = "1.13"
2929
jobserver = "0.1.21"
3030
crossbeam-utils = "0.7"
3131
snap = "1"
32+
filetime = "0.2.14"
33+
walkdir = "2"
34+
35+
[target.'cfg(windows)'.dependencies]
36+
miow = "0.3"
37+
winapi = { version = "0.3", features = ["winerror"] }
3238

3339
[[bin]]
3440
name = "collector"

collector/benchmarks/coercions/1-add-static-arr-item.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ index 3fb7c5f..775773b 100644
1818
+ "",
1919
];
2020

21-
fn main() { }
21+
fn main() { println!("test"); }

collector/src/execute.rs

Lines changed: 78 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use collector::command_output;
66
use database::{PatchName, QueryLabel};
77
use futures::stream::FuturesUnordered;
88
use futures::stream::StreamExt;
9-
use std::cmp;
9+
use std::{cmp, ffi::OsStr, path::Component};
1010
use std::collections::HashMap;
1111
use std::env;
1212
use std::fmt;
@@ -23,6 +23,20 @@ use tokio::runtime::Runtime;
2323

2424
mod rustc;
2525

26+
#[cfg(windows)]
27+
fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> anyhow::Result<()> {
28+
let (from, to) = (from.as_ref(), to.as_ref());
29+
30+
let ctx = format!("renaming file {:?} to {:?}", from, to);
31+
32+
if fs::metadata(from)?.is_file() {
33+
return Ok(fs::rename(from, to).with_context(|| ctx.clone())?);
34+
}
35+
36+
collector::robocopy(from, to, &[&"/move"]).with_context(|| ctx.clone())
37+
}
38+
39+
#[cfg(unix)]
2640
fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> anyhow::Result<()> {
2741
let (from, to) = (from.as_ref(), to.as_ref());
2842
if fs::rename(from, to).is_err() {
@@ -44,26 +58,48 @@ fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> anyhow::Result<()>
4458
Ok(())
4559
}
4660

47-
fn touch(root: &Path, path: &Path) -> anyhow::Result<()> {
48-
let mut cmd = Command::new("touch");
49-
cmd.current_dir(root).arg(path);
50-
command_output(&mut cmd).with_context(|| format!("touching {:?} in {:?}", path, root))?;
61+
fn touch(path: &Path) -> anyhow::Result<()> {
62+
log::trace!("touching file {:?}", path);
63+
64+
filetime::set_file_mtime(path, filetime::FileTime::now()).with_context(|| format!("touching file {:?}", path))?;
65+
5166
Ok(())
5267
}
5368

5469
fn touch_all(path: &Path) -> anyhow::Result<()> {
55-
let mut cmd = Command::new("bash");
56-
// Don't touch files in `target/`, since they're likely generated by build scripts and might be from a dependency.
57-
// Don't touch build scripts, which confuses the wrapped rustc.
58-
cmd.current_dir(path)
59-
.args(&["-c", "find . -path ./target -prune -false -o -name '*.rs' | grep -v '^./build.rs$' | xargs touch"]);
60-
command_output(&mut cmd).with_context(|| format!("touching all .rs in {:?}", path))?;
61-
// We also delete the cmake caches to avoid errors when moving directories around.
62-
// This might be a bit slower but at least things build
63-
let mut cmd = Command::new("bash");
64-
cmd.current_dir(path)
65-
.args(&["-c", "find . -name 'CMakeCache.txt' -delete"]);
66-
command_output(&mut cmd).with_context(|| format!("deleting cmake caches in {:?}", path))?;
70+
fn is_valid(path: &Path) -> bool {
71+
let target_dir = Component::Normal(OsStr::new("target"));
72+
73+
// Don't touch files in `target/`, since they're likely generated by build scripts and might be from a dependency.
74+
if path.components().any(|component| component == target_dir) {
75+
return false;
76+
}
77+
78+
if let Some(extn) = path.extension() {
79+
if extn.to_str() == Some("rs") {
80+
// Don't touch build scripts, which confuses the wrapped rustc.
81+
return path.file_name() != Some(OsStr::new("build.rs"));
82+
}
83+
}
84+
85+
false
86+
}
87+
88+
for entry in walkdir::WalkDir::new(path) {
89+
let entry = entry?;
90+
let path = entry.path();
91+
92+
// We also delete the cmake caches to avoid errors when moving directories around.
93+
// This might be a bit slower but at least things build
94+
if path.file_name() == Some(OsStr::new("CMakeCache.txt")) {
95+
fs::remove_file(path).with_context(|| format!("deleting cmake caches in {:?}", path))?;
96+
}
97+
98+
if is_valid(path) {
99+
touch(path)?;
100+
}
101+
}
102+
67103
Ok(())
68104
}
69105

@@ -380,7 +416,7 @@ impl<'a> CargoProcess<'a> {
380416
// in-tree (e.g., in the case of the servo crates there are a lot of
381417
// other components).
382418
if let Some(file) = &self.touch_file {
383-
touch(&self.cwd, Path::new(&file))?;
419+
touch(&self.cwd.join(Path::new(&file)))?;
384420
} else {
385421
touch_all(
386422
&self.cwd.join(
@@ -880,11 +916,13 @@ impl<'a> Processor for ProfileProcessor<'a> {
880916
rename(path, filepath(&zsp_dir, "Zsp.string_data"))?;
881917
} else if filename_str.ends_with(".string_index") {
882918
rename(path, filepath(&zsp_dir, "Zsp.string_index"))?;
919+
} else if filename_str.ends_with(".mm_profdata") {
920+
rename(path, filepath(&zsp_dir, "Zsp.mm_profdata"))?;
883921
} else {
884922
panic!("unexpected file {:?}", path);
885923
}
886924
}
887-
assert_eq!(num_files, 3);
925+
assert!(num_files == 3 || num_files == 1);
888926

889927
// Run `summarize`.
890928
let mut summarize_cmd = Command::new("summarize");
@@ -1095,15 +1133,26 @@ impl Benchmark {
10951133
self.config.supports_stable
10961134
}
10971135

1136+
#[cfg(windows)]
1137+
fn copy(from: &Path, to: &Path) -> anyhow::Result<()> {
1138+
collector::robocopy(from, to, &[])
1139+
}
1140+
1141+
#[cfg(unix)]
1142+
fn copy(from: &Path, to: &Path) -> anyhow::Result<()> {
1143+
let mut cmd = Command::new("cp");
1144+
cmd.arg("-pLR").arg(from).arg(to);
1145+
command_output(&mut cmd)?;
1146+
Ok(())
1147+
}
1148+
10981149
fn make_temp_dir(&self, base: &Path) -> anyhow::Result<TempDir> {
10991150
// Appending `.` means we copy just the contents of `base` into
11001151
// `tmp_dir`, rather than `base` itself.
11011152
let mut base_dot = base.to_path_buf();
11021153
base_dot.push(".");
11031154
let tmp_dir = TempDir::new()?;
1104-
let mut cmd = Command::new("cp");
1105-
cmd.arg("-pLR").arg(base_dot).arg(tmp_dir.path());
1106-
command_output(&mut cmd).with_context(|| format!("copying {} to tmp dir", self.name))?;
1155+
Self::copy(&base_dot, tmp_dir.path()).with_context(|| format!("copying {} to tmp dir", self.name))?;
11071156
Ok(tmp_dir)
11081157
}
11091158

@@ -1497,14 +1546,14 @@ impl Patch {
14971546
}
14981547
}
14991548

1500-
pub fn apply(&self, dir: &Path) -> Result<(), String> {
1549+
pub fn apply(&self, dir: &Path) -> anyhow::Result<()> {
15011550
log::debug!("applying {} to {:?}", self.name, dir);
1502-
let mut cmd = Command::new("patch");
1503-
cmd.current_dir(dir).args(&["-Np1", "-i"]).arg(&*self.path);
1504-
cmd.stdout(Stdio::null());
1505-
if cmd.status().map(|s| !s.success()).unwrap_or(false) {
1506-
return Err(format!("could not execute {:?}.", cmd));
1507-
}
1551+
1552+
let mut cmd = Command::new("git");
1553+
cmd.current_dir(dir).args(&["apply"]).args(&["-Np1"]).arg(&*self.path);
1554+
1555+
command_output(&mut cmd)?;
1556+
15081557
Ok(())
15091558
}
15101559
}

0 commit comments

Comments
 (0)