mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Publish platform-specific Code VSIXes
This commit is contained in:
parent
4c686721c0
commit
9c74f646f4
4 changed files with 104 additions and 59 deletions
44
.github/workflows/release.yaml
vendored
44
.github/workflows/release.yaml
vendored
|
@ -17,6 +17,7 @@ env:
|
|||
RUSTUP_MAX_RETRIES: 10
|
||||
FETCH_DEPTH: 0 # pull in the tags for the version string
|
||||
MACOSX_DEPLOYMENT_TARGET: 10.15
|
||||
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
|
||||
|
||||
jobs:
|
||||
dist:
|
||||
|
@ -25,24 +26,28 @@ jobs:
|
|||
include:
|
||||
- os: windows-latest
|
||||
target: x86_64-pc-windows-msvc
|
||||
code-target: win32-x64
|
||||
- os: windows-latest
|
||||
target: aarch64-pc-windows-msvc
|
||||
code-target: win32-arm64
|
||||
- os: ubuntu-20.04
|
||||
target: x86_64-unknown-linux-gnu
|
||||
code-target: linux-x64
|
||||
- os: ubuntu-20.04
|
||||
target: aarch64-unknown-linux-gnu
|
||||
cross_linker: aarch64-linux-gnu-gcc
|
||||
code-target: linux-arm64
|
||||
- os: macos-11
|
||||
target: x86_64-apple-darwin
|
||||
code-target: darwin-x64
|
||||
- os: macos-11
|
||||
target: aarch64-apple-darwin
|
||||
code-target: darwin-arm64
|
||||
|
||||
name: dist (${{ matrix.target }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
env:
|
||||
RA_TARGET: ${{ matrix.target }}
|
||||
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: ${{ matrix.cross_linker }}
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
|
@ -77,7 +82,6 @@ jobs:
|
|||
components: rust-src
|
||||
|
||||
- name: Install Node.js
|
||||
if: matrix.target == 'x86_64-unknown-linux-gnu'
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 14.x
|
||||
|
@ -90,13 +94,21 @@ jobs:
|
|||
if: matrix.target == 'aarch64-unknown-linux-gnu'
|
||||
run: sudo apt-get install gcc-aarch64-linux-gnu
|
||||
|
||||
- name: Dist (generic)
|
||||
if: matrix.target != 'x86_64-unknown-linux-gnu'
|
||||
run: cargo xtask dist
|
||||
- name: Dist
|
||||
run: cargo xtask dist --client-patch-version ${{ github.run_number }}
|
||||
|
||||
- name: Dist (Linux)
|
||||
if: matrix.target == 'x86_64-unknown-linux-gnu'
|
||||
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-${{ 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
|
||||
if: matrix.target == 'x86_64-unknown-linux-gnu'
|
||||
|
@ -126,7 +138,7 @@ jobs:
|
|||
|
||||
steps:
|
||||
- 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
|
||||
uses: actions/checkout@v2
|
||||
|
@ -134,7 +146,15 @@ jobs:
|
|||
fetch-depth: ${{ env.FETCH_DEPTH }}
|
||||
|
||||
- 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
|
||||
uses: actions/upload-artifact@v1
|
||||
|
@ -210,4 +230,4 @@ jobs:
|
|||
if: github.ref == 'refs/heads/release'
|
||||
working-directory: ./editors/code
|
||||
# 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
|
||||
|
|
2
editors/code/.gitignore
vendored
2
editors/code/.gitignore
vendored
|
@ -1,5 +1,5 @@
|
|||
out
|
||||
node_modules
|
||||
server
|
||||
.vscode-test/
|
||||
*.vsix
|
||||
bundle
|
||||
|
|
|
@ -221,9 +221,18 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
|
|||
);
|
||||
if (userResponse !== "Update") return;
|
||||
|
||||
const artifact = latestNightlyRelease.assets.find(artifact => artifact.name === "rust-analyzer.vsix");
|
||||
assert(!!artifact, `Bad release: ${JSON.stringify(latestNightlyRelease)}`);
|
||||
let arch = process.arch;
|
||||
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");
|
||||
|
||||
await downloadWithRetryDialog(state, async () => {
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::{
|
|||
|
||||
use anyhow::Result;
|
||||
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};
|
||||
|
||||
|
@ -16,10 +16,15 @@ impl flags::Dist {
|
|||
let stable =
|
||||
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)?;
|
||||
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 {
|
||||
let version = if stable {
|
||||
format!("0.2.{}", patch_version)
|
||||
|
@ -28,20 +33,24 @@ impl flags::Dist {
|
|||
format!("0.3.{}", patch_version)
|
||||
};
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
||||
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 nightly = release_tag == "nightly";
|
||||
|
||||
let mut patch = Patch::new("./package.json")?;
|
||||
|
||||
patch
|
||||
.replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version))
|
||||
.replace(r#""releaseTag": null"#, &format!(r#""releaseTag": "{}""#, release_tag))
|
||||
|
@ -59,12 +68,10 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> {
|
|||
}
|
||||
patch.commit()?;
|
||||
|
||||
cmd!("npm ci").run()?;
|
||||
cmd!("npx vsce package -o ../../dist/rust-analyzer.vsix").run()?;
|
||||
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("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.
|
||||
// let _e = pushenv("CARGO_PROFILE_RELEASE_DEBUG", "1");
|
||||
|
||||
let target = get_target();
|
||||
if target.contains("-linux-gnu") || target.contains("-linux-musl") {
|
||||
if target.name.contains("-linux-") {
|
||||
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 src =
|
||||
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"))?;
|
||||
let dst = Path::new("dist").join(&target.artifact_name);
|
||||
gzip(&target.server_path, &dst.with_extension("gz"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_target() -> String {
|
||||
match env::var("RA_TARGET") {
|
||||
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 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,
|
||||
_ => {
|
||||
if cfg!(target_os = "linux") {
|
||||
|
@ -103,25 +123,19 @@ fn get_target() -> String {
|
|||
panic!("Unsupported OS, maybe try setting RA_TARGET")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn exe_suffix(target: &str) -> String {
|
||||
if target.contains("-windows-") {
|
||||
".exe".into()
|
||||
};
|
||||
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")))
|
||||
} 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 {
|
||||
path: PathBuf,
|
||||
original_contents: String,
|
||||
|
@ -149,6 +163,8 @@ impl Patch {
|
|||
|
||||
impl Drop for Patch {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue