Skip to content

Commit 45e4f25

Browse files
committed
Build aarch64-apple-darwin binaries on CI
1 parent e4f922a commit 45e4f25

File tree

2 files changed

+140
-33
lines changed

2 files changed

+140
-33
lines changed

.github/workflows/release.yaml

Lines changed: 88 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,108 @@ jobs:
4137
profile: minimal
4238
override: true
4339

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

5069
- name: Dist
51-
if: matrix.os == 'ubuntu-16.04' && github.ref == 'refs/heads/release'
70+
if: github.ref == 'refs/heads/release'
5271
run: cargo xtask dist --client 0.2.$GITHUB_RUN_NUMBER
5372

5473
- name: Dist
55-
if: matrix.os == 'ubuntu-16.04' && github.ref != 'refs/heads/release'
74+
if: github.ref != 'refs/heads/release'
5675
run: cargo xtask dist --nightly --client 0.3.$GITHUB_RUN_NUMBER-nightly
5776

77+
- name: Nightly analysis-stats check
78+
if: github.ref != 'refs/heads/release'
79+
run: ./dist/rust-analyzer-linux analysis-stats .
80+
81+
- name: Upload artifacts
82+
uses: actions/upload-artifact@v1
83+
with:
84+
name: dist-ubuntu-16.04
85+
path: ./dist
86+
87+
dist-macos-latest:
88+
name: dist (MacOS latest)
89+
runs-on: macos-latest
90+
91+
steps:
92+
- name: Checkout repository
93+
uses: actions/checkout@v2
94+
95+
- name: Install Rust toolchain
96+
uses: actions-rs/toolchain@v1
97+
with:
98+
toolchain: stable
99+
profile: minimal
100+
override: true
101+
58102
- name: Dist
59-
if: matrix.os != 'ubuntu-16.04'
60103
run: cargo xtask dist
61104

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 .
105+
- name: Upload artifacts
106+
uses: actions/upload-artifact@v1
107+
with:
108+
name: dist-macos-latest
109+
path: ./dist
110+
111+
dist-macos-11.0:
112+
name: dist (MacOS 11.0)
113+
runs-on: macos-11.0
114+
115+
steps:
116+
- name: Checkout repository
117+
uses: actions/checkout@v2
118+
119+
- name: Install Rust toolchain (beta)
120+
uses: actions-rs/toolchain@v1
121+
with:
122+
toolchain: beta
123+
target: aarch64-apple-darwin
124+
profile: minimal
125+
override: true
126+
127+
- name: Dist
128+
run: cargo xtask dist
129+
env:
130+
RA_TARGET: aarch64-apple-darwin
65131

66132
- name: Upload artifacts
67133
uses: actions/upload-artifact@v1
68134
with:
69-
name: dist-${{ matrix.os }}
135+
name: dist-macos-11.0
70136
path: ./dist
71137

72138
publish:
73139
name: publish
74140
runs-on: ubuntu-16.04
75-
needs: ['dist']
141+
needs: ['dist-windows', 'dist-ubuntu-16.04', 'dist-macos-latest', 'dist-macos-11.0']
76142
steps:
77143
- name: Install Nodejs
78144
uses: actions/setup-node@v1
@@ -91,6 +157,10 @@ jobs:
91157
- run: echo "HEAD_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
92158
- run: 'echo "HEAD_SHA: $HEAD_SHA"'
93159

160+
- uses: actions/download-artifact@v1
161+
with:
162+
name: dist-macos-11.0
163+
path: dist
94164
- uses: actions/download-artifact@v1
95165
with:
96166
name: dist-macos-latest
@@ -103,7 +173,7 @@ jobs:
103173
with:
104174
name: dist-windows-latest
105175
path: dist
106-
- run: ls -all ./dist
176+
- run: ls -al ./dist
107177

108178
- name: Publish Release
109179
uses: ./.github/actions/github-release

xtask/src/dist.rs

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,67 @@ 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-
};
75-
76-
let src = Path::new(src);
77-
let dst = Path::new(dst);
7865

66+
let toolchain = get_toolchain(&target);
67+
cmd!("cargo +{toolchain} build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target} --release").run()?;
68+
let src =
69+
Path::new("target").join(format!("rust-analyzer{}", get_executable_extension(&target)));
70+
let dst = Path::new("dist").join(get_release_artifact_name(&target));
7971
cp(&src, &dst)?;
8072
gzip(&src, &dst.with_extension("gz"))?;
8173

8274
Ok(())
8375
}
8476

77+
fn get_target() -> String {
78+
match env::var("RA_TARGET") {
79+
Ok(target) => target,
80+
_ => {
81+
if cfg!(target_os = "linux") {
82+
"x86_64-unknown-linux-gnu".to_string()
83+
} else if cfg!(target_os = "windows") {
84+
"x86_64-pc-windows-msvc".to_string()
85+
} else if cfg!(target_os = "macos") {
86+
"x86_64-apple-darwin".to_string()
87+
} else {
88+
panic!("Unsupported OS")
89+
}
90+
}
91+
}
92+
}
93+
94+
fn get_executable_extension(target: &str) -> String {
95+
if target.contains("-windows-") {
96+
".exe".into()
97+
} else {
98+
"".into()
99+
}
100+
}
101+
102+
fn get_toolchain(target: &str) -> String {
103+
match target {
104+
"aarch64-apple-darwin" => "beta".to_string(),
105+
_ => "stable".to_string(),
106+
}
107+
}
108+
109+
fn get_release_artifact_name(target: &str) -> String {
110+
// FIXME: we kept the old names for compatibility, but we should remove the special cases
111+
match target {
112+
"x86_64-unknown-linux-gnu" => "rust-analyzer-linux".to_string(),
113+
"x86_64-pc-windows-msvc" => "rust-analyzer-windows.exe".to_string(),
114+
"x86_64-apple-darwin" => "rust-analyzer-mac".to_string(),
115+
_ => {
116+
let extension = get_executable_extension(target);
117+
format!("rust-analyzer-{}{}", target, extension)
118+
}
119+
}
120+
}
121+
85122
fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> {
86123
let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best());
87124
let mut input = io::BufReader::new(File::open(src_path)?);

0 commit comments

Comments
 (0)