Skip to content

Commit 359beb5

Browse files
committed
Build aarch64-apple-darwin binaries on CI
1 parent e4f922a commit 359beb5

File tree

2 files changed

+142
-32
lines changed

2 files changed

+142
-32
lines changed

.github/workflows/release.yaml

Lines changed: 90 additions & 17 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,111 @@ jobs:
4137
profile: minimal
4238
override: true
4339

40+
- name: Dist
41+
if: matrix.os != 'ubuntu-16.04'
42+
run: cargo xtask dist
43+
44+
- name: Upload artifacts
45+
uses: actions/upload-artifact@v1
46+
with:
47+
name: dist-windows-latest
48+
path: ./dist
49+
50+
dist-ubuntu-16.04:
51+
name: dist (Ubuntu 16.04)
52+
runs-on: ubuntu-16.04
53+
54+
steps:
55+
- name: Checkout repository
56+
uses: actions/checkout@v2
57+
58+
- name: Install Rust toolchain
59+
uses: actions-rs/toolchain@v1
60+
with:
61+
toolchain: stable
62+
profile: minimal
63+
override: true
64+
4465
- name: Install Nodejs
4566
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
5374

5475
- name: Dist
55-
if: matrix.os == 'ubuntu-16.04' && github.ref != 'refs/heads/release'
76+
if: github.ref != 'refs/heads/release'
5677
run: cargo xtask dist --nightly --client 0.3.$GITHUB_RUN_NUMBER-nightly
5778

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

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

66135
- name: Upload artifacts
67136
uses: actions/upload-artifact@v1
68137
with:
69-
name: dist-${{ matrix.os }}
138+
name: dist-macos-11.0
70139
path: ./dist
71140

72141
publish:
73142
name: publish
74143
runs-on: ubuntu-16.04
75-
needs: ['dist']
144+
needs: ['dist-windows', 'dist-ubuntu-16.04', 'dist-macos-latest', 'dist-macos-11.0']
76145
steps:
77146
- name: Install Nodejs
78147
uses: actions/setup-node@v1
@@ -91,6 +160,10 @@ jobs:
91160
- run: echo "HEAD_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
92161
- run: 'echo "HEAD_SHA: $HEAD_SHA"'
93162

163+
- uses: actions/download-artifact@v1
164+
with:
165+
name: dist-macos-11.0
166+
path: dist
94167
- uses: actions/download-artifact@v1
95168
with:
96169
name: dist-macos-latest
@@ -103,7 +176,7 @@ jobs:
103176
with:
104177
name: dist-windows-latest
105178
path: dist
106-
- run: ls -all ./dist
179+
- run: ls -al ./dist
107180

108181
- name: Publish Release
109182
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)