Skip to content

Commit 991cf12

Browse files
committed
build: add target argument
1 parent 42bfbff commit 991cf12

File tree

2 files changed

+24
-76
lines changed

2 files changed

+24
-76
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717
runner: [ubuntu-latest, windows-latest, macos-latest]
1818
include:
1919
- runner: ubuntu-latest
20-
platform: linux
20+
target: x86_64-unknown-linux-musl
2121
- runner: windows-latest
22-
platform: windows
22+
target: x86_64-pc-windows-msvc
2323
- runner: macos-latest
24-
platform: macos
24+
target: x86_64-apple-darwin
2525

2626
steps:
2727
- uses: actions/checkout@v3
@@ -35,6 +35,6 @@ jobs:
3535
- name: Format
3636
run: cargo run --package tool-dev -- fmt
3737
- name: Build
38-
run: cargo run --package tool-dev -- build ${{ matrix.platform }}
38+
run: cargo run --package tool-dev -- build --target ${{ matrix.target }}
3939
- name: Test
40-
run: cargo run --package tool-dev -- test ${{ matrix.platform }}
40+
run: cargo run --package tool-dev -- test --target ${{ matrix.target }}

crates/tools/dev/src/main.rs

Lines changed: 19 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ enum Commands {
1616
Check,
1717
Clippy,
1818
Fmt,
19-
Build { platform: String },
20-
Test { platform: Option<String> },
19+
Build {
20+
#[arg(short, long)]
21+
target: String,
22+
},
23+
Test {
24+
#[arg(short, long)]
25+
target: Option<String>,
26+
},
2127
PrePush,
2228
}
2329

@@ -54,80 +60,22 @@ fn fmt() {
5460
run("cargo", &["fmt", "--", "--check"]);
5561
}
5662

57-
fn build(platform: &str) {
63+
fn build(target: &str) {
5864
env::set_var("RUSTFLAGS", "-C target-feature=+crt-static");
59-
if platform == "windows" {
60-
run("rustup", &["target", "add", "x86_64-pc-windows-msvc"]);
61-
run(
62-
"cargo",
63-
&[
64-
"build",
65-
"-p",
66-
"kill_tree_cli",
67-
"-r",
68-
"--target",
69-
"x86_64-pc-windows-msvc",
70-
],
71-
);
72-
} else if platform == "linux" {
73-
run("rustup", &["target", "add", "x86_64-unknown-linux-musl"]);
74-
run(
75-
"cargo",
76-
&[
77-
"build",
78-
"-p",
79-
"kill_tree_cli",
80-
"-r",
81-
"--target",
82-
"x86_64-unknown-linux-musl",
83-
],
84-
);
85-
} else if platform == "macos" {
86-
run("rustup", &["target", "add", "aarch64-apple-darwin"]);
87-
run("rustup", &["target", "add", "x86_64-apple-darwin"]);
88-
run(
89-
"cargo",
90-
&[
91-
"build",
92-
"-p",
93-
"kill_tree_cli",
94-
"-r",
95-
"--target",
96-
"aarch64-apple-darwin",
97-
],
98-
);
99-
run(
100-
"cargo",
101-
&[
102-
"build",
103-
"-p",
104-
"kill_tree_cli",
105-
"-r",
106-
"--target",
107-
"x86_64-apple-darwin",
108-
],
109-
);
110-
} else {
111-
panic!("Unsupported platform: {platform}");
112-
}
65+
run("rustup", &["target", "add", target]);
66+
run(
67+
"cargo",
68+
&["build", "-p", "kill_tree_cli", "-r", "--target", target],
69+
);
11370
}
11471

115-
fn test(platform: Option<String>) {
116-
let Some(platform) = platform else {
72+
fn test(target: Option<String>) {
73+
let Some(target) = target else {
11774
run("cargo", &["test", "--workspace"]);
11875
return;
11976
};
12077

121-
if platform == "windows" {
122-
run("cargo", &["test", "--target", "x86_64-pc-windows-msvc"]);
123-
} else if platform == "linux" {
124-
run("cargo", &["test", "--target", "x86_64-unknown-linux-musl"]);
125-
} else if platform == "macos" {
126-
run("cargo", &["test", "--target", "aarch64-apple-darwin"]);
127-
run("cargo", &["test", "--target", "x86_64-apple-darwin"]);
128-
} else {
129-
panic!("Unsupported platform: {platform}");
130-
}
78+
run("cargo", &["test", "--target", target.as_str()]);
13179
}
13280

13381
fn pre_push() {
@@ -143,8 +91,8 @@ fn main() {
14391
Some(Commands::Check) => check(),
14492
Some(Commands::Clippy) => clippy(),
14593
Some(Commands::Fmt) => fmt(),
146-
Some(Commands::Build { platform }) => build(&platform),
147-
Some(Commands::Test { platform }) => test(platform),
94+
Some(Commands::Build { target }) => build(&target),
95+
Some(Commands::Test { target }) => test(target),
14896
Some(Commands::PrePush) => pre_push(),
14997
None => {
15098
panic!("No command");

0 commit comments

Comments
 (0)