11053: feat: Publish platform-specific Code VSIXes r=me a=lnicola

Closes #10483
CC #10371

Some notes:

 - we still build a plain VSIX, just in case
 - we build the extension on every platform to make the release workflow arguably cleaner
 - the Windows VSIX includes the PDB (but let's leave  #10371 open until we change the Windows stand-alone release to a ZIP file)
 - `npm` doesn't run if started from `xtask`, possibly something related to path mapping; I moved the `npm` calls outside, but..
 - the `Patch` thingy doesn't work any more, so you'll end up with a dirty `package.json` of you run `cargo xtask --client-patch-version`; I don't think we should block on this
 - there's an untested Alpine build; for better or worse, we special-case `musl` distros as `alpine`
 - I tested this as much as I could, but not the publishing and nightly updates
 - you can find some sample artifacts under https://github.com/lnicola/rust-analyzer/releases
 - we can now run the server from the install location (is Code planning to switch to compressed extensions?), except on NixOS
 - Code lets you install a VSIX for the wrong platform (with the results one would expect)
 - I don't know what happens if we try to publish a VSIX without a target

This is a relatively risky, but we'll probably have to take our chances with it.

r? `@rust-analyzer/review`

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
bors[bot] 2021-12-18 21:16:19 +00:00 committed by GitHub
commit b65d9c3e62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 104 additions and 59 deletions

View file

@ -17,6 +17,7 @@ env:
RUSTUP_MAX_RETRIES: 10 RUSTUP_MAX_RETRIES: 10
FETCH_DEPTH: 0 # pull in the tags for the version string FETCH_DEPTH: 0 # pull in the tags for the version string
MACOSX_DEPLOYMENT_TARGET: 10.15 MACOSX_DEPLOYMENT_TARGET: 10.15
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
jobs: jobs:
dist: dist:
@ -25,24 +26,28 @@ jobs:
include: include:
- os: windows-latest - os: windows-latest
target: x86_64-pc-windows-msvc target: x86_64-pc-windows-msvc
code-target: win32-x64
- os: windows-latest - os: windows-latest
target: aarch64-pc-windows-msvc target: aarch64-pc-windows-msvc
code-target: win32-arm64
- os: ubuntu-20.04 - os: ubuntu-20.04
target: x86_64-unknown-linux-gnu target: x86_64-unknown-linux-gnu
code-target: linux-x64
- os: ubuntu-20.04 - os: ubuntu-20.04
target: aarch64-unknown-linux-gnu target: aarch64-unknown-linux-gnu
cross_linker: aarch64-linux-gnu-gcc code-target: linux-arm64
- os: macos-11 - os: macos-11
target: x86_64-apple-darwin target: x86_64-apple-darwin
code-target: darwin-x64
- os: macos-11 - os: macos-11
target: aarch64-apple-darwin target: aarch64-apple-darwin
code-target: darwin-arm64
name: dist (${{ matrix.target }}) name: dist (${{ matrix.target }})
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
env: env:
RA_TARGET: ${{ matrix.target }} RA_TARGET: ${{ matrix.target }}
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: ${{ matrix.cross_linker }}
steps: steps:
- name: Checkout repository - name: Checkout repository
@ -77,7 +82,6 @@ jobs:
components: rust-src components: rust-src
- name: Install Node.js - name: Install Node.js
if: matrix.target == 'x86_64-unknown-linux-gnu'
uses: actions/setup-node@v1 uses: actions/setup-node@v1
with: with:
node-version: 14.x node-version: 14.x
@ -90,13 +94,21 @@ jobs:
if: matrix.target == 'aarch64-unknown-linux-gnu' if: matrix.target == 'aarch64-unknown-linux-gnu'
run: sudo apt-get install gcc-aarch64-linux-gnu run: sudo apt-get install gcc-aarch64-linux-gnu
- name: Dist (generic) - name: Dist
if: matrix.target != 'x86_64-unknown-linux-gnu' run: cargo xtask dist --client-patch-version ${{ github.run_number }}
run: cargo xtask dist
- name: Dist (Linux) - run: npm ci
if: matrix.target == 'x86_64-unknown-linux-gnu' working-directory: editors/code
run: cargo xtask dist --client-patch-version $GITHUB_RUN_NUMBER
- run: npx vsce package -o "../../dist/rust-analyzer-${{ matrix.code-target }}.vsix" --target ${{ matrix.code-target }}
working-directory: editors/code
- if: matrix.target == 'x86_64-unknown-linux-gnu'
run: rm -rf editors/code/server
- if: matrix.target == 'x86_64-unknown-linux-gnu'
run: npx vsce package -o ../../dist/rust-analyzer.vsix
working-directory: editors/code
- name: Run analysis-stats on rust-analyzer - name: Run analysis-stats on rust-analyzer
if: matrix.target == 'x86_64-unknown-linux-gnu' if: matrix.target == 'x86_64-unknown-linux-gnu'
@ -126,7 +138,7 @@ jobs:
steps: steps:
- name: Install dependencies - name: Install dependencies
run: apk add --no-cache git clang lld musl-dev run: apk add --no-cache git clang lld musl-dev nodejs npm
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -134,7 +146,15 @@ jobs:
fetch-depth: ${{ env.FETCH_DEPTH }} fetch-depth: ${{ env.FETCH_DEPTH }}
- name: Dist - name: Dist
run: cargo xtask dist run: cargo xtask dist --client-patch-version ${{ github.run_number }}
- run: npm ci
working-directory: editors/code
- run: npx vsce package -o "../../dist/rust-analyzer-alpine-x64.vsix" --target alpine-x64
working-directory: editors/code
- run: rm -rf editors/code/server
- name: Upload artifacts - name: Upload artifacts
uses: actions/upload-artifact@v1 uses: actions/upload-artifact@v1
@ -210,4 +230,4 @@ jobs:
if: github.ref == 'refs/heads/release' if: github.ref == 'refs/heads/release'
working-directory: ./editors/code working-directory: ./editors/code
# token from https://dev.azure.com/rust-analyzer/ # token from https://dev.azure.com/rust-analyzer/
run: npx vsce publish --pat ${{ secrets.MARKETPLACE_TOKEN }} --packagePath ../../dist/rust-analyzer.vsix run: npx vsce publish --pat ${{ secrets.MARKETPLACE_TOKEN }} --packagePath ../../dist/rust-analyzer-*.vsix

View file

@ -1,5 +1,5 @@
out out
node_modules node_modules
server
.vscode-test/ .vscode-test/
*.vsix *.vsix
bundle

View file

@ -221,9 +221,18 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
); );
if (userResponse !== "Update") return; if (userResponse !== "Update") return;
const artifact = latestNightlyRelease.assets.find(artifact => artifact.name === "rust-analyzer.vsix"); let arch = process.arch;
assert(!!artifact, `Bad release: ${JSON.stringify(latestNightlyRelease)}`); if (arch === "ia32") {
arch = "x64";
}
let platform = process.platform as string;
if (platform === "linux" && isMusl()) {
platform = "alpine";
}
const artifactName = `rust-analyzer-${platform}-${arch}.vsix`;
const artifact = latestNightlyRelease.assets.find(artifact => artifact.name === artifactName);
assert(!!artifact, `Bad release: ${JSON.stringify(latestNightlyRelease)}`);
const dest = vscode.Uri.joinPath(config.globalStorageUri, "rust-analyzer.vsix"); const dest = vscode.Uri.joinPath(config.globalStorageUri, "rust-analyzer.vsix");
await downloadWithRetryDialog(state, async () => { await downloadWithRetryDialog(state, async () => {

View file

@ -7,7 +7,7 @@ use std::{
use anyhow::Result; use anyhow::Result;
use flate2::{write::GzEncoder, Compression}; use flate2::{write::GzEncoder, Compression};
use xshell::{cmd, mkdir_p, pushd, pushenv, read_file, rm_rf, write_file}; use xshell::{cmd, cp, mkdir_p, pushd, pushenv, read_file, rm_rf, write_file};
use crate::{date_iso, flags, project_root}; use crate::{date_iso, flags, project_root};
@ -16,10 +16,15 @@ impl flags::Dist {
let stable = let stable =
std::env::var("GITHUB_REF").unwrap_or_default().as_str() == "refs/heads/release"; std::env::var("GITHUB_REF").unwrap_or_default().as_str() == "refs/heads/release";
let dist = project_root().join("dist"); let project_root = project_root();
let target = Target::get(&project_root);
let dist = project_root.join("dist");
rm_rf(&dist)?; rm_rf(&dist)?;
mkdir_p(&dist)?; mkdir_p(&dist)?;
let release_channel = if stable { "stable" } else { "nightly" };
dist_server(release_channel, &target)?;
if let Some(patch_version) = self.client_patch_version { if let Some(patch_version) = self.client_patch_version {
let version = if stable { let version = if stable {
format!("0.2.{}", patch_version) format!("0.2.{}", patch_version)
@ -28,20 +33,24 @@ impl flags::Dist {
format!("0.3.{}", patch_version) format!("0.3.{}", patch_version)
}; };
let release_tag = if stable { date_iso()? } else { "nightly".to_string() }; let release_tag = if stable { date_iso()? } else { "nightly".to_string() };
dist_client(&version, &release_tag)?; dist_client(&version, &release_tag, &target)?;
} }
let release_channel = if stable { "stable" } else { "nightly" };
dist_server(release_channel)?;
Ok(()) Ok(())
} }
} }
fn dist_client(version: &str, release_tag: &str) -> Result<()> { fn dist_client(version: &str, release_tag: &str, target: &Target) -> Result<()> {
let bundle_path = Path::new("editors").join("code").join("server");
mkdir_p(&bundle_path)?;
cp(&target.server_path, &bundle_path)?;
if let Some(symbols_path) = &target.symbols_path {
cp(symbols_path, &bundle_path)?;
}
let _d = pushd("./editors/code")?; let _d = pushd("./editors/code")?;
let nightly = release_tag == "nightly"; let nightly = release_tag == "nightly";
let mut patch = Patch::new("./package.json")?; let mut patch = Patch::new("./package.json")?;
patch patch
.replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version)) .replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version))
.replace(r#""releaseTag": null"#, &format!(r#""releaseTag": "{}""#, release_tag)) .replace(r#""releaseTag": null"#, &format!(r#""releaseTag": "{}""#, release_tag))
@ -59,12 +68,10 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> {
} }
patch.commit()?; patch.commit()?;
cmd!("npm ci").run()?;
cmd!("npx vsce package -o ../../dist/rust-analyzer.vsix").run()?;
Ok(()) Ok(())
} }
fn dist_server(release_channel: &str) -> Result<()> { fn dist_server(release_channel: &str, target: &Target) -> Result<()> {
let _e = pushenv("RUST_ANALYZER_CHANNEL", release_channel); let _e = pushenv("RUST_ANALYZER_CHANNEL", release_channel);
let _e = pushenv("CARGO_PROFILE_RELEASE_LTO", "thin"); let _e = pushenv("CARGO_PROFILE_RELEASE_LTO", "thin");
@ -73,24 +80,37 @@ fn dist_server(release_channel: &str) -> Result<()> {
// * on Linux, this blows up the binary size from 8MB to 43MB, which is unreasonable. // * on Linux, this blows up the binary size from 8MB to 43MB, which is unreasonable.
// let _e = pushenv("CARGO_PROFILE_RELEASE_DEBUG", "1"); // let _e = pushenv("CARGO_PROFILE_RELEASE_DEBUG", "1");
let target = get_target(); if target.name.contains("-linux-") {
if target.contains("-linux-gnu") || target.contains("-linux-musl") {
env::set_var("CC", "clang"); env::set_var("CC", "clang");
} }
cmd!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target} --release").run()?; let target_name = &target.name;
cmd!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} --release").run()?;
let suffix = exe_suffix(&target); let dst = Path::new("dist").join(&target.artifact_name);
let src = gzip(&target.server_path, &dst.with_extension("gz"))?;
Path::new("target").join(&target).join("release").join(format!("rust-analyzer{}", suffix));
let dst = Path::new("dist").join(format!("rust-analyzer-{}{}", target, suffix));
gzip(&src, &dst.with_extension("gz"))?;
Ok(()) Ok(())
} }
fn get_target() -> String { fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> {
match env::var("RA_TARGET") { let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best());
let mut input = io::BufReader::new(File::open(src_path)?);
io::copy(&mut input, &mut encoder)?;
encoder.finish()?;
Ok(())
}
struct Target {
name: String,
server_path: PathBuf,
symbols_path: Option<PathBuf>,
artifact_name: String,
}
impl Target {
fn get(project_root: &Path) -> Self {
let name = match env::var("RA_TARGET") {
Ok(target) => target, Ok(target) => target,
_ => { _ => {
if cfg!(target_os = "linux") { if cfg!(target_os = "linux") {
@ -103,25 +123,19 @@ fn get_target() -> String {
panic!("Unsupported OS, maybe try setting RA_TARGET") panic!("Unsupported OS, maybe try setting RA_TARGET")
} }
} }
} };
} let out_path = project_root.join("target").join(&name).join("release");
let (exe_suffix, symbols_path) = if name.contains("-windows-") {
fn exe_suffix(target: &str) -> String { (".exe".into(), Some(out_path.join("rust_analyzer.pdb")))
if target.contains("-windows-") {
".exe".into()
} else { } else {
"".into() (String::new(), None)
};
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 }
} }
} }
fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> {
let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best());
let mut input = io::BufReader::new(File::open(src_path)?);
io::copy(&mut input, &mut encoder)?;
encoder.finish()?;
Ok(())
}
struct Patch { struct Patch {
path: PathBuf, path: PathBuf,
original_contents: String, original_contents: String,
@ -149,6 +163,8 @@ impl Patch {
impl Drop for Patch { impl Drop for Patch {
fn drop(&mut self) { fn drop(&mut self) {
write_file(&self.path, &self.original_contents).unwrap(); // FIXME: find a way to bring this back
let _ = &self.original_contents;
// write_file(&self.path, &self.original_contents).unwrap();
} }
} }