Skip to content

Commit c06efa3

Browse files
committed
Build aarch64-apple-darwin binaries on CI
1 parent b98ee07 commit c06efa3

File tree

2 files changed

+154
-32
lines changed

2 files changed

+154
-32
lines changed

.github/workflows/release.yaml

Lines changed: 96 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ env:
1515
RUSTUP_MAX_RETRIES: 10
1616

1717
jobs:
18-
dist:
19-
name: dist
20-
runs-on: ${{ matrix.os }}
21-
strategy:
22-
matrix:
23-
os: [ubuntu-16.04, windows-latest, macos-latest]
18+
dist-windows:
19+
name: dist (Windows)
20+
runs-on: windows-latest
2421

2522
steps:
2623
- name: Checkout repository
@@ -30,8 +27,7 @@ jobs:
3027
# which takes a long time. The fastest way to do this is to rename the
3128
# existing folder, as deleting it takes about as much time as not doing
3229
# anything and just updating rust-docs.
33-
- name: Rename existing rust toolchain (Windows)
34-
if: matrix.os == 'windows-latest'
30+
- name: Rename existing rust toolchain
3531
run: Rename-Item C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc.old
3632

3733
- name: Install Rust toolchain
@@ -41,38 +37,116 @@ jobs:
4137
profile: minimal
4238
override: true
4339

40+
- name: Dist
41+
run: cargo xtask dist
42+
env:
43+
RA_TARGET: x86_64-pc-windows-msvc
44+
45+
- name: Upload artifacts
46+
uses: actions/upload-artifact@v1
47+
with:
48+
name: dist-windows-latest
49+
path: ./dist
50+
51+
dist-ubuntu:
52+
name: dist (Ubuntu 16.04)
53+
runs-on: ubuntu-16.04
54+
55+
steps:
56+
- name: Checkout repository
57+
uses: actions/checkout@v2
58+
59+
- name: Install Rust toolchain
60+
uses: actions-rs/toolchain@v1
61+
with:
62+
toolchain: stable
63+
profile: minimal
64+
override: true
65+
4466
- name: Install Nodejs
45-
if: matrix.os == 'ubuntu-16.04'
4667
uses: actions/setup-node@v1
4768
with:
4869
node-version: 12.x
4970

5071
- name: Dist
51-
if: matrix.os == 'ubuntu-16.04' && github.ref == 'refs/heads/release'
72+
if: github.ref == 'refs/heads/release'
5273
run: cargo xtask dist --client 0.2.$GITHUB_RUN_NUMBER
74+
env:
75+
RA_TARGET: x86_64-unknown-linux-gnu
5376

5477
- name: Dist
55-
if: matrix.os == 'ubuntu-16.04' && github.ref != 'refs/heads/release'
78+
if: github.ref != 'refs/heads/release'
5679
run: cargo xtask dist --nightly --client 0.3.$GITHUB_RUN_NUMBER-nightly
80+
env:
81+
RA_TARGET: x86_64-unknown-linux-gnu
82+
83+
- name: Nightly analysis-stats check
84+
if: github.ref != 'refs/heads/release'
85+
run: ./dist/rust-analyzer-x86_64-unknown-linux-gnu analysis-stats .
86+
87+
- name: Upload artifacts
88+
uses: actions/upload-artifact@v1
89+
with:
90+
name: dist-ubuntu-16.04
91+
path: ./dist
92+
93+
dist-macos-latest:
94+
name: dist (MacOS latest)
95+
runs-on: macos-latest
96+
97+
steps:
98+
- name: Checkout repository
99+
uses: actions/checkout@v2
100+
101+
- name: Install Rust toolchain
102+
uses: actions-rs/toolchain@v1
103+
with:
104+
toolchain: stable
105+
profile: minimal
106+
override: true
57107

58108
- name: Dist
59-
if: matrix.os != 'ubuntu-16.04'
60109
run: cargo xtask dist
110+
env:
111+
RA_TARGET: x86_64-apple-darwin
61112

62-
- name: Nightly analysis-stats check
63-
if: matrix.os == 'ubuntu-16.04' && github.ref != 'refs/heads/release'
64-
run: ./dist/rust-analyzer-linux analysis-stats .
113+
- name: Upload artifacts
114+
uses: actions/upload-artifact@v1
115+
with:
116+
name: dist-macos-latest
117+
path: ./dist
118+
119+
dist-macos-11:
120+
name: dist (MacOS 11.0)
121+
runs-on: macos-11.0
122+
123+
steps:
124+
- name: Checkout repository
125+
uses: actions/checkout@v2
126+
127+
- name: Install Rust toolchain (beta)
128+
uses: actions-rs/toolchain@v1
129+
with:
130+
toolchain: beta
131+
target: aarch64-apple-darwin
132+
profile: minimal
133+
override: true
134+
135+
- name: Dist
136+
run: cargo xtask dist
137+
env:
138+
RA_TARGET: aarch64-apple-darwin
65139

66140
- name: Upload artifacts
67141
uses: actions/upload-artifact@v1
68142
with:
69-
name: dist-${{ matrix.os }}
143+
name: dist-macos-11.0
70144
path: ./dist
71145

72146
publish:
73147
name: publish
74148
runs-on: ubuntu-16.04
75-
needs: ['dist']
149+
needs: ['dist-windows', 'dist-ubuntu', 'dist-macos-latest', 'dist-macos-11']
76150
steps:
77151
- name: Install Nodejs
78152
uses: actions/setup-node@v1
@@ -91,6 +165,10 @@ jobs:
91165
- run: echo "HEAD_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
92166
- run: 'echo "HEAD_SHA: $HEAD_SHA"'
93167

168+
- uses: actions/download-artifact@v1
169+
with:
170+
name: dist-macos-11.0
171+
path: dist
94172
- uses: actions/download-artifact@v1
95173
with:
96174
name: dist-macos-latest
@@ -103,7 +181,7 @@ jobs:
103181
with:
104182
name: dist-windows-latest
105183
path: dist
106-
- run: ls -all ./dist
184+
- run: ls -al ./dist
107185

108186
- name: Publish Release
109187
uses: ./.github/actions/github-release

xtask/src/dist.rs

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,74 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> {
5858
}
5959

6060
fn dist_server() -> Result<()> {
61-
if cfg!(target_os = "linux") {
61+
let target = get_target();
62+
if target.contains("-linux-gnu") {
6263
env::set_var("CC", "clang");
6364
}
64-
cmd!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release").run()?;
65-
66-
let (src, dst) = if cfg!(target_os = "linux") {
67-
("./target/release/rust-analyzer", "./dist/rust-analyzer-linux")
68-
} else if cfg!(target_os = "windows") {
69-
("./target/release/rust-analyzer.exe", "./dist/rust-analyzer-windows.exe")
70-
} else if cfg!(target_os = "macos") {
71-
("./target/release/rust-analyzer", "./dist/rust-analyzer-mac")
72-
} else {
73-
panic!("Unsupported OS")
74-
};
7565

76-
let src = Path::new(src);
77-
let dst = Path::new(dst);
66+
let toolchain = toolchain(&target);
67+
cmd!("cargo +{toolchain} build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target} --release").run()?;
7868

69+
let suffix = exe_suffix(&target);
70+
let src =
71+
Path::new("target").join(&target).join("release").join(format!("rust-analyzer{}", suffix));
72+
let dst = Path::new("dist").join(format!("rust-analyzer-{}{}", target, suffix));
7973
cp(&src, &dst)?;
8074
gzip(&src, &dst.with_extension("gz"))?;
8175

76+
// FIXME: the old names are temporarily kept for client compatibility, but they should be removed
77+
// Remove this block after a couple of releases
78+
match target.as_ref() {
79+
"x86_64-unknown-linux-gnu" => {
80+
cp(&src, "dist/rust-analyzer-linux")?;
81+
gzip(&src, Path::new("dist/rust-analyzer-linux.gz"))?;
82+
}
83+
"x86_64-pc-windows-msvc" => {
84+
cp(&src, "dist/rust-analyzer-windows.exe")?;
85+
gzip(&src, Path::new("dist/rust-analyzer-windows.gz"))?;
86+
}
87+
"x86_64-apple-darwin" => {
88+
cp(&src, "dist/rust-analyzer-mac")?;
89+
gzip(&src, Path::new("dist/rust-analyzer-mac.gz"))?;
90+
}
91+
_ => {}
92+
}
93+
8294
Ok(())
8395
}
8496

97+
fn get_target() -> String {
98+
match env::var("RA_TARGET") {
99+
Ok(target) => target,
100+
_ => {
101+
if cfg!(target_os = "linux") {
102+
"x86_64-unknown-linux-gnu".to_string()
103+
} else if cfg!(target_os = "windows") {
104+
"x86_64-pc-windows-msvc".to_string()
105+
} else if cfg!(target_os = "macos") {
106+
"x86_64-apple-darwin".to_string()
107+
} else {
108+
panic!("Unsupported OS, maybe try setting RA_TARGET")
109+
}
110+
}
111+
}
112+
}
113+
114+
fn exe_suffix(target: &str) -> String {
115+
if target.contains("-windows-") {
116+
".exe".into()
117+
} else {
118+
"".into()
119+
}
120+
}
121+
122+
fn toolchain(target: &str) -> String {
123+
match target {
124+
"aarch64-apple-darwin" => "beta".to_string(),
125+
_ => "stable".to_string(),
126+
}
127+
}
128+
85129
fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> {
86130
let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best());
87131
let mut input = io::BufReader::new(File::open(src_path)?);

0 commit comments

Comments
 (0)