/
main.rs
237 lines (200 loc) · 6.02 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
fn main() {
test_yml();
build_yml();
}
fn test_yml() {
let root = std::path::PathBuf::from(metadata::workspace_dir());
let mut yml = r#"name: Test
on:
pull_request:
push:
branches:
- master
env:
RUSTFLAGS: -Dwarnings
jobs:
test:
name: Test
runs-on: windows-latest
strategy:
matrix:
include:
- version: stable
target: x86_64-pc-windows-msvc
- version: nightly
target: i686-pc-windows-msvc
- version: nightly
target: x86_64-pc-windows-gnu
- version: stable
target: i686-pc-windows-gnu
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update toolchain
run: rustup update --no-self-update ${{ matrix.version }} && rustup default ${{ matrix.version }}
- name: Add toolchain target
run: rustup target add ${{ matrix.target }}
- name: Install clippy
run: rustup component add clippy
- name: Configure Cargo for GNU toolchain
shell: pwsh
run: |
Add-Content $env:USERPROFILE\.cargo\config @"
[target.x86_64-pc-windows-gnu]
linker = `"C:\\msys64\\mingw64\\bin\\x86_64-w64-mingw32-gcc.exe`"
ar = `"C:\\msys64\\mingw64\\bin\\ar.exe`"
[target.i686-pc-windows-gnu]
linker = `"C:\\msys64\\mingw32\\bin\\i686-w64-mingw32-gcc.exe`"
ar = `"C:\\msys64\\mingw32\\bin\\ar.exe`"
"@
if: contains(matrix.target, 'windows-gnu')
- name: Configure environment for GNU toolchain
shell: pwsh
run: |
if("${{ matrix.target }}" -eq "i686-pc-windows-gnu") {
$MingwPath = "C:\msys64\mingw32\bin"
} else {
$MingwPath = "C:\msys64\mingw64\bin"
}
$MingwPath | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
if: contains(matrix.target, 'windows-gnu')
- name: Test stable
run: |"#
.to_string();
for name in crates(&root) {
if !requires_nightly(&name) {
yml.push_str(&format!("\n cargo test --target ${{{{ matrix.target }}}} -p {} &&", name));
}
}
yml.truncate(yml.len() - 2);
yml.push_str(
r#"
if: matrix.version == 'stable'
- name: Test nightly
run: |"#,
);
for name in crates(&root) {
if requires_nightly(&name) {
yml.push_str(&format!("\n cargo test --target ${{{{ matrix.target }}}} -p {} &&", name));
}
}
yml.truncate(yml.len() - 2);
yml.push_str(
r#"
if: matrix.version == 'nightly'
"#,
);
std::fs::write(root.join(".github/workflows/test.yml"), yml.as_bytes()).unwrap();
}
fn build_yml() {
let root = std::path::PathBuf::from(metadata::workspace_dir());
let mut yml = r#"name: Build
on:
pull_request:
push:
branches:
- master
env:
RUSTFLAGS: -Dwarnings
jobs:
cargo_fmt:
name: Check cargo formatting
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run cargo fmt
run: cargo fmt --all -- --check
cargo_doc:
name: Check cargo docs
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run cargo doc
run: cargo doc --no-deps -p windows
generation:
name: Check generation of `tool_${{ matrix.generator }}`
runs-on: windows-latest
strategy:
matrix:
generator: [bindings, windows, sys, yml]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run tool_${{ matrix.generator }}
run: cargo run -p tool_${{ matrix.generator }}
- name: Compare
shell: bash
run: git diff --exit-code || (echo '::error::Generated `tool_${{ matrix.generator }}` are out-of-date. Please run `cargo run -p tool_${{ matrix.generator }}`'; exit 1)
cargo_sys:
name: Check windows-sys
runs-on: windows-latest
strategy:
matrix:
rust: [1.46.0, stable, nightly]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update toolchain
run: rustup update --no-self-update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
- name: Run cargo check
run: cargo check -p windows-sys --all-features
cargo_clippy:
name: Check clippy
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update toolchain
run: rustup update --no-self-update nightly && rustup default nightly
- name: Install clippy
run: rustup component add clippy
- name: Run cargo clippy
run: |"#
.to_string();
for name in crates(&root) {
yml.push_str(&format!("\n cargo clippy -p {} &&", name));
}
yml.truncate(yml.len() - 2);
std::fs::write(root.join(".github/workflows/build.yml"), yml.as_bytes()).unwrap();
}
fn crates(root: &std::path::Path) -> Vec<String> {
let mut crates = vec![];
for dir in dirs(root, "crates/libs") {
if dir == "windows" {
crates.push("windows".to_string());
} else {
crates.push(format!("windows-{}", dir));
}
}
for dir in dirs(root, "crates/samples") {
crates.push(format!("sample_{}", dir));
}
for dir in dirs(root, "crates/targets") {
crates.push(format!("windows_{}", dir));
}
for dir in dirs(root, "crates/tests") {
crates.push(format!("test_{}", dir));
}
for dir in dirs(root, "crates/tools") {
crates.push(format!("tool_{}", dir));
}
crates
}
fn requires_nightly(name: &str) -> bool {
name.contains("implement") || name.starts_with("sample")
}
fn dirs(root: &std::path::Path, path: &str) -> Vec<String> {
let mut dirs = vec![];
if let Ok(files) = std::fs::read_dir(root.join(path)) {
for file in files.filter_map(|file| file.ok()) {
if let Ok(file_type) = file.file_type() {
if file_type.is_dir() {
dirs.push(file.file_name().to_str().unwrap().to_string());
}
}
}
}
dirs
}