Skip to content

Commit 505b52d

Browse files
authored
Merge pull request #19230 from lnicola/zig
internal: set up Zig on CI and start using it in rust-analyzer
2 parents e50bc18 + e039ae7 commit 505b52d

File tree

4 files changed

+49
-40
lines changed

4 files changed

+49
-40
lines changed

.github/workflows/release.yaml

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ env:
1717
RUSTUP_MAX_RETRIES: 10
1818
FETCH_DEPTH: 0 # pull in the tags for the version string
1919
MACOSX_DEPLOYMENT_TARGET: 13.0
20-
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
21-
CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc
20+
ZIG_VERSION: 0.13.0
21+
ZIGBUILD_VERSION: 0.19.8
2222

2323
jobs:
2424
dist:
@@ -36,13 +36,15 @@ jobs:
3636
code-target: win32-arm64
3737
- os: ubuntu-latest
3838
target: x86_64-unknown-linux-gnu
39+
zig_target: x86_64-unknown-linux-gnu.2.28
3940
code-target: linux-x64
40-
container: rockylinux:8
41-
- os: ubuntu-22.04
41+
- os: ubuntu-latest
4242
target: aarch64-unknown-linux-gnu
43+
zig_target: aarch64-unknown-linux-gnu.2.28
4344
code-target: linux-arm64
44-
- os: ubuntu-22.04
45+
- os: ubuntu-latest
4546
target: arm-unknown-linux-gnueabihf
47+
zig_target: arm-unknown-linux-gnueabihf.2.28
4648
code-target: linux-armhf
4749
- os: macos-13
4850
target: x86_64-apple-darwin
@@ -64,40 +66,33 @@ jobs:
6466
with:
6567
fetch-depth: ${{ env.FETCH_DEPTH }}
6668

67-
- name: Install toolchain dependencies
68-
if: matrix.container == 'rockylinux:8'
69-
shell: bash
70-
run: |
71-
dnf install -y gcc
72-
curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --profile minimal --default-toolchain none -y
73-
echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH
69+
- name: Install Node.js toolchain
70+
uses: actions/setup-node@v4
71+
with:
72+
node-version: 20
7473

7574
- name: Install Rust toolchain
7675
run: |
7776
rustup update --no-self-update stable
78-
rustup target add ${{ matrix.target }}
7977
rustup component add rust-src
78+
rustup target add ${{ matrix.target }}
8079
81-
- name: Install Node.js
82-
uses: actions/setup-node@v4
83-
with:
84-
node-version: 18
85-
86-
- name: Update apt repositories
87-
if: matrix.target == 'aarch64-unknown-linux-gnu' || matrix.target == 'arm-unknown-linux-gnueabihf'
88-
run: sudo apt-get update
89-
90-
- name: Install AArch64 target toolchain
91-
if: matrix.target == 'aarch64-unknown-linux-gnu'
92-
run: sudo apt-get install gcc-aarch64-linux-gnu
93-
94-
- name: Install ARM target toolchain
95-
if: matrix.target == 'arm-unknown-linux-gnueabihf'
96-
run: sudo apt-get install gcc-arm-linux-gnueabihf
80+
- name: Install Zig toolchain
81+
if: ${{ matrix.zig_target }}
82+
run: |
83+
which cargo
84+
curl -L "https://ziglang.org/download/${ZIG_VERSION}/zig-linux-$(uname -m)-${ZIG_VERSION}.tar.xz" | sudo tar JxC /usr/local
85+
sudo ln -s "/usr/local/zig-linux-$(uname -m)-${ZIG_VERSION}/zig" /usr/local/bin/zig
86+
curl -L "https://github.com/rust-cross/cargo-zigbuild/releases/download/v${ZIGBUILD_VERSION}/cargo-zigbuild-v${ZIGBUILD_VERSION}.x86_64-unknown-linux-musl.tar.gz" | tar zxC ~/.cargo/bin
9787
98-
- name: Dist
88+
- name: Dist (plain)
89+
if: ${{ !matrix.zig_target }}
9990
run: cargo xtask dist --client-patch-version ${{ github.run_number }}
10091

92+
- name: Dist (using zigbuild)
93+
if: ${{ matrix.zig_target }}
94+
run: RA_TARGET=${{ matrix.zig_target}} cargo xtask dist --client-patch-version ${{ github.run_number }} --zig
95+
10196
- run: npm ci
10297
working-directory: editors/code
10398

xtask/src/dist.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ impl flags::Dist {
3838
// A hack to make VS Code prefer nightly over stable.
3939
format!("{VERSION_NIGHTLY}.{patch_version}")
4040
};
41-
dist_server(sh, &format!("{version}-standalone"), &target, allocator)?;
41+
dist_server(sh, &format!("{version}-standalone"), &target, allocator, self.zig)?;
4242
let release_tag = if stable { date_iso(sh)? } else { "nightly".to_owned() };
4343
dist_client(sh, &version, &release_tag, &target)?;
4444
} else {
45-
dist_server(sh, "0.0.0-standalone", &target, allocator)?;
45+
dist_server(sh, "0.0.0-standalone", &target, allocator, self.zig)?;
4646
}
4747
Ok(())
4848
}
@@ -83,6 +83,7 @@ fn dist_server(
8383
release: &str,
8484
target: &Target,
8585
allocator: Malloc,
86+
zig: bool,
8687
) -> anyhow::Result<()> {
8788
let _e = sh.push_env("CFG_RELEASE", release);
8889
let _e = sh.push_env("CARGO_PROFILE_RELEASE_LTO", "thin");
@@ -92,13 +93,14 @@ fn dist_server(
9293
// * on Linux, this blows up the binary size from 8MB to 43MB, which is unreasonable.
9394
// let _e = sh.push_env("CARGO_PROFILE_RELEASE_DEBUG", "1");
9495

95-
if target.name.contains("-linux-") {
96-
env::set_var("CC", "clang");
97-
}
98-
99-
let target_name = &target.name;
96+
let linux_target = target.is_linux();
97+
let target_name = match &target.libc_suffix {
98+
Some(libc_suffix) if zig => format!("{}.{libc_suffix}", target.name),
99+
_ => target.name.to_owned(),
100+
};
100101
let features = allocator.to_features();
101-
cmd!(sh, "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} {features...} --release").run()?;
102+
let command = if linux_target && zig { "zigbuild" } else { "build" };
103+
cmd!(sh, "cargo {command} --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} {features...} --release").run()?;
102104

103105
let dst = Path::new("dist").join(&target.artifact_name);
104106
if target_name.contains("-windows-") {
@@ -156,6 +158,7 @@ fn zip(src_path: &Path, symbols_path: Option<&PathBuf>, dest_path: &Path) -> any
156158

157159
struct Target {
158160
name: String,
161+
libc_suffix: Option<String>,
159162
server_path: PathBuf,
160163
symbols_path: Option<PathBuf>,
161164
artifact_name: String,
@@ -177,6 +180,10 @@ impl Target {
177180
}
178181
}
179182
};
183+
let (name, libc_suffix) = match name.split_once('.') {
184+
Some((l, r)) => (l.to_owned(), Some(r.to_owned())),
185+
None => (name, None),
186+
};
180187
let out_path = project_root.join("target").join(&name).join("release");
181188
let (exe_suffix, symbols_path) = if name.contains("-windows-") {
182189
(".exe".into(), Some(out_path.join("rust_analyzer.pdb")))
@@ -185,7 +192,11 @@ impl Target {
185192
};
186193
let server_path = out_path.join(format!("rust-analyzer{exe_suffix}"));
187194
let artifact_name = format!("rust-analyzer-{name}{exe_suffix}");
188-
Self { name, server_path, symbols_path, artifact_name }
195+
Self { name, libc_suffix, server_path, symbols_path, artifact_name }
196+
}
197+
198+
fn is_linux(&self) -> bool {
199+
self.name.contains("-linux-")
189200
}
190201
}
191202

xtask/src/flags.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ xflags::xflags! {
5757
/// Use jemalloc allocator for server
5858
optional --jemalloc
5959
optional --client-patch-version version: String
60+
/// Use cargo-zigbuild
61+
optional --zig
6062
}
6163
/// Read a changelog AsciiDoc file and update the GitHub Releases entry in Markdown.
6264
cmd publish-release-notes {
@@ -144,6 +146,7 @@ pub struct Dist {
144146
pub mimalloc: bool,
145147
pub jemalloc: bool,
146148
pub client_patch_version: Option<String>,
149+
pub zig: bool,
147150
}
148151

149152
#[derive(Debug)]

xtask/src/release.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl flags::Release {
5050
.unwrap_or_default();
5151

5252
let tags = cmd!(sh, "git tag --list").read()?;
53-
let prev_tag = tags.lines().filter(|line| is_release_tag(line)).last().unwrap();
53+
let prev_tag = tags.lines().filter(|line| is_release_tag(line)).next_back().unwrap();
5454

5555
let contents = changelog::get_changelog(sh, changelog_n, &commit, prev_tag, &today)?;
5656
let path = changelog_dir.join(format!("{today}-changelog-{changelog_n}.adoc"));

0 commit comments

Comments
 (0)