Use cargo zigbuild for releases

This commit is contained in:
Laurențiu Nicola 2025-02-26 12:35:48 +02:00
parent 3b4e268d81
commit fae88f2ab5
4 changed files with 49 additions and 40 deletions

View file

@ -17,8 +17,8 @@ env:
RUSTUP_MAX_RETRIES: 10
FETCH_DEPTH: 0 # pull in the tags for the version string
MACOSX_DEPLOYMENT_TARGET: 13.0
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc
ZIG_VERSION: 0.13.0
ZIGBUILD_VERSION: 0.19.8
jobs:
dist:
@ -36,13 +36,15 @@ jobs:
code-target: win32-arm64
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
zig_target: x86_64-unknown-linux-gnu.2.28
code-target: linux-x64
container: rockylinux:8
- os: ubuntu-22.04
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
zig_target: aarch64-unknown-linux-gnu.2.28
code-target: linux-arm64
- os: ubuntu-22.04
- os: ubuntu-latest
target: arm-unknown-linux-gnueabihf
zig_target: arm-unknown-linux-gnueabihf.2.28
code-target: linux-armhf
- os: macos-13
target: x86_64-apple-darwin
@ -64,40 +66,33 @@ jobs:
with:
fetch-depth: ${{ env.FETCH_DEPTH }}
- name: Install toolchain dependencies
if: matrix.container == 'rockylinux:8'
shell: bash
run: |
dnf install -y gcc
curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --profile minimal --default-toolchain none -y
echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH
- name: Install Node.js toolchain
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Rust toolchain
run: |
rustup update --no-self-update stable
rustup target add ${{ matrix.target }}
rustup component add rust-src
rustup target add ${{ matrix.target }}
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install Zig toolchain
if: ${{ matrix.zig_target }}
run: |
which cargo
curl -L "https://ziglang.org/download/${ZIG_VERSION}/zig-linux-$(uname -m)-${ZIG_VERSION}.tar.xz" | sudo tar JxC /usr/local
sudo ln -s "/usr/local/zig-linux-$(uname -m)-${ZIG_VERSION}/zig" /usr/local/bin/zig
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
- name: Update apt repositories
if: matrix.target == 'aarch64-unknown-linux-gnu' || matrix.target == 'arm-unknown-linux-gnueabihf'
run: sudo apt-get update
- name: Install AArch64 target toolchain
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: sudo apt-get install gcc-aarch64-linux-gnu
- name: Install ARM target toolchain
if: matrix.target == 'arm-unknown-linux-gnueabihf'
run: sudo apt-get install gcc-arm-linux-gnueabihf
- name: Dist
- name: Dist (plain)
if: ${{ !matrix.zig_target }}
run: cargo xtask dist --client-patch-version ${{ github.run_number }}
- name: Dist (using zigbuild)
if: ${{ matrix.zig_target }}
run: RA_TARGET=${{ matrix.zig_target}} cargo xtask dist --client-patch-version ${{ github.run_number }} --zig
- run: npm ci
working-directory: editors/code

View file

@ -38,11 +38,11 @@ impl flags::Dist {
// A hack to make VS Code prefer nightly over stable.
format!("{VERSION_NIGHTLY}.{patch_version}")
};
dist_server(sh, &format!("{version}-standalone"), &target, allocator)?;
dist_server(sh, &format!("{version}-standalone"), &target, allocator, self.zig)?;
let release_tag = if stable { date_iso(sh)? } else { "nightly".to_owned() };
dist_client(sh, &version, &release_tag, &target)?;
} else {
dist_server(sh, "0.0.0-standalone", &target, allocator)?;
dist_server(sh, "0.0.0-standalone", &target, allocator, self.zig)?;
}
Ok(())
}
@ -83,6 +83,7 @@ fn dist_server(
release: &str,
target: &Target,
allocator: Malloc,
zig: bool,
) -> anyhow::Result<()> {
let _e = sh.push_env("CFG_RELEASE", release);
let _e = sh.push_env("CARGO_PROFILE_RELEASE_LTO", "thin");
@ -92,13 +93,14 @@ fn dist_server(
// * on Linux, this blows up the binary size from 8MB to 43MB, which is unreasonable.
// let _e = sh.push_env("CARGO_PROFILE_RELEASE_DEBUG", "1");
if target.name.contains("-linux-") {
env::set_var("CC", "clang");
}
let target_name = &target.name;
let linux_target = target.is_linux();
let target_name = match &target.libc_suffix {
Some(libc_suffix) if zig => format!("{}.{libc_suffix}", target.name),
_ => target.name.to_owned(),
};
let features = allocator.to_features();
cmd!(sh, "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} {features...} --release").run()?;
let command = if linux_target && zig { "zigbuild" } else { "build" };
cmd!(sh, "cargo {command} --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} {features...} --release").run()?;
let dst = Path::new("dist").join(&target.artifact_name);
if target_name.contains("-windows-") {
@ -156,6 +158,7 @@ fn zip(src_path: &Path, symbols_path: Option<&PathBuf>, dest_path: &Path) -> any
struct Target {
name: String,
libc_suffix: Option<String>,
server_path: PathBuf,
symbols_path: Option<PathBuf>,
artifact_name: String,
@ -177,6 +180,10 @@ impl Target {
}
}
};
let (name, libc_suffix) = match name.split_once('.') {
Some((l, r)) => (l.to_owned(), Some(r.to_owned())),
None => (name, None),
};
let out_path = project_root.join("target").join(&name).join("release");
let (exe_suffix, symbols_path) = if name.contains("-windows-") {
(".exe".into(), Some(out_path.join("rust_analyzer.pdb")))
@ -185,7 +192,11 @@ impl Target {
};
let server_path = out_path.join(format!("rust-analyzer{exe_suffix}"));
let artifact_name = format!("rust-analyzer-{name}{exe_suffix}");
Self { name, server_path, symbols_path, artifact_name }
Self { name, libc_suffix, server_path, symbols_path, artifact_name }
}
fn is_linux(&self) -> bool {
self.name.contains("-linux-")
}
}

View file

@ -57,6 +57,8 @@ xflags::xflags! {
/// Use jemalloc allocator for server
optional --jemalloc
optional --client-patch-version version: String
/// Use cargo-zigbuild
optional --zig
}
/// Read a changelog AsciiDoc file and update the GitHub Releases entry in Markdown.
cmd publish-release-notes {
@ -144,6 +146,7 @@ pub struct Dist {
pub mimalloc: bool,
pub jemalloc: bool,
pub client_patch_version: Option<String>,
pub zig: bool,
}
#[derive(Debug)]

View file

@ -50,7 +50,7 @@ impl flags::Release {
.unwrap_or_default();
let tags = cmd!(sh, "git tag --list").read()?;
let prev_tag = tags.lines().filter(|line| is_release_tag(line)).last().unwrap();
let prev_tag = tags.lines().filter(|line| is_release_tag(line)).next_back().unwrap();
let contents = changelog::get_changelog(sh, changelog_n, &commit, prev_tag, &today)?;
let path = changelog_dir.join(format!("{today}-changelog-{changelog_n}.adoc"));