Skip to content

Commit b65d9c3

Browse files
bors[bot]lnicola
andauthored
Merge #11053
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 <[email protected]>
2 parents 0dbbf14 + 9c74f64 commit b65d9c3

File tree

4 files changed

+104
-59
lines changed

4 files changed

+104
-59
lines changed

.github/workflows/release.yaml

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ env:
1717
RUSTUP_MAX_RETRIES: 10
1818
FETCH_DEPTH: 0 # pull in the tags for the version string
1919
MACOSX_DEPLOYMENT_TARGET: 10.15
20+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
2021

2122
jobs:
2223
dist:
@@ -25,24 +26,28 @@ jobs:
2526
include:
2627
- os: windows-latest
2728
target: x86_64-pc-windows-msvc
29+
code-target: win32-x64
2830
- os: windows-latest
2931
target: aarch64-pc-windows-msvc
32+
code-target: win32-arm64
3033
- os: ubuntu-20.04
3134
target: x86_64-unknown-linux-gnu
35+
code-target: linux-x64
3236
- os: ubuntu-20.04
3337
target: aarch64-unknown-linux-gnu
34-
cross_linker: aarch64-linux-gnu-gcc
38+
code-target: linux-arm64
3539
- os: macos-11
3640
target: x86_64-apple-darwin
41+
code-target: darwin-x64
3742
- os: macos-11
3843
target: aarch64-apple-darwin
44+
code-target: darwin-arm64
3945

4046
name: dist (${{ matrix.target }})
4147
runs-on: ${{ matrix.os }}
4248

4349
env:
4450
RA_TARGET: ${{ matrix.target }}
45-
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: ${{ matrix.cross_linker }}
4651

4752
steps:
4853
- name: Checkout repository
@@ -77,7 +82,6 @@ jobs:
7782
components: rust-src
7883

7984
- name: Install Node.js
80-
if: matrix.target == 'x86_64-unknown-linux-gnu'
8185
uses: actions/setup-node@v1
8286
with:
8387
node-version: 14.x
@@ -90,13 +94,21 @@ jobs:
9094
if: matrix.target == 'aarch64-unknown-linux-gnu'
9195
run: sudo apt-get install gcc-aarch64-linux-gnu
9296

93-
- name: Dist (generic)
94-
if: matrix.target != 'x86_64-unknown-linux-gnu'
95-
run: cargo xtask dist
97+
- name: Dist
98+
run: cargo xtask dist --client-patch-version ${{ github.run_number }}
9699

97-
- name: Dist (Linux)
98-
if: matrix.target == 'x86_64-unknown-linux-gnu'
99-
run: cargo xtask dist --client-patch-version $GITHUB_RUN_NUMBER
100+
- run: npm ci
101+
working-directory: editors/code
102+
103+
- run: npx vsce package -o "../../dist/rust-analyzer-${{ matrix.code-target }}.vsix" --target ${{ matrix.code-target }}
104+
working-directory: editors/code
105+
106+
- if: matrix.target == 'x86_64-unknown-linux-gnu'
107+
run: rm -rf editors/code/server
108+
109+
- if: matrix.target == 'x86_64-unknown-linux-gnu'
110+
run: npx vsce package -o ../../dist/rust-analyzer.vsix
111+
working-directory: editors/code
100112

101113
- name: Run analysis-stats on rust-analyzer
102114
if: matrix.target == 'x86_64-unknown-linux-gnu'
@@ -126,15 +138,23 @@ jobs:
126138

127139
steps:
128140
- name: Install dependencies
129-
run: apk add --no-cache git clang lld musl-dev
141+
run: apk add --no-cache git clang lld musl-dev nodejs npm
130142

131143
- name: Checkout repository
132144
uses: actions/checkout@v2
133145
with:
134146
fetch-depth: ${{ env.FETCH_DEPTH }}
135147

136148
- name: Dist
137-
run: cargo xtask dist
149+
run: cargo xtask dist --client-patch-version ${{ github.run_number }}
150+
151+
- run: npm ci
152+
working-directory: editors/code
153+
154+
- run: npx vsce package -o "../../dist/rust-analyzer-alpine-x64.vsix" --target alpine-x64
155+
working-directory: editors/code
156+
157+
- run: rm -rf editors/code/server
138158

139159
- name: Upload artifacts
140160
uses: actions/upload-artifact@v1
@@ -210,4 +230,4 @@ jobs:
210230
if: github.ref == 'refs/heads/release'
211231
working-directory: ./editors/code
212232
# token from https://dev.azure.com/rust-analyzer/
213-
run: npx vsce publish --pat ${{ secrets.MARKETPLACE_TOKEN }} --packagePath ../../dist/rust-analyzer.vsix
233+
run: npx vsce publish --pat ${{ secrets.MARKETPLACE_TOKEN }} --packagePath ../../dist/rust-analyzer-*.vsix

editors/code/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
out
22
node_modules
3+
server
34
.vscode-test/
45
*.vsix
5-
bundle

editors/code/src/main.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,18 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
221221
);
222222
if (userResponse !== "Update") return;
223223

224-
const artifact = latestNightlyRelease.assets.find(artifact => artifact.name === "rust-analyzer.vsix");
225-
assert(!!artifact, `Bad release: ${JSON.stringify(latestNightlyRelease)}`);
224+
let arch = process.arch;
225+
if (arch === "ia32") {
226+
arch = "x64";
227+
}
228+
let platform = process.platform as string;
229+
if (platform === "linux" && isMusl()) {
230+
platform = "alpine";
231+
}
232+
const artifactName = `rust-analyzer-${platform}-${arch}.vsix`;
226233

234+
const artifact = latestNightlyRelease.assets.find(artifact => artifact.name === artifactName);
235+
assert(!!artifact, `Bad release: ${JSON.stringify(latestNightlyRelease)}`);
227236
const dest = vscode.Uri.joinPath(config.globalStorageUri, "rust-analyzer.vsix");
228237

229238
await downloadWithRetryDialog(state, async () => {

xtask/src/dist.rs

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77

88
use anyhow::Result;
99
use flate2::{write::GzEncoder, Compression};
10-
use xshell::{cmd, mkdir_p, pushd, pushenv, read_file, rm_rf, write_file};
10+
use xshell::{cmd, cp, mkdir_p, pushd, pushenv, read_file, rm_rf, write_file};
1111

1212
use crate::{date_iso, flags, project_root};
1313

@@ -16,10 +16,15 @@ impl flags::Dist {
1616
let stable =
1717
std::env::var("GITHUB_REF").unwrap_or_default().as_str() == "refs/heads/release";
1818

19-
let dist = project_root().join("dist");
19+
let project_root = project_root();
20+
let target = Target::get(&project_root);
21+
let dist = project_root.join("dist");
2022
rm_rf(&dist)?;
2123
mkdir_p(&dist)?;
2224

25+
let release_channel = if stable { "stable" } else { "nightly" };
26+
dist_server(release_channel, &target)?;
27+
2328
if let Some(patch_version) = self.client_patch_version {
2429
let version = if stable {
2530
format!("0.2.{}", patch_version)
@@ -28,20 +33,24 @@ impl flags::Dist {
2833
format!("0.3.{}", patch_version)
2934
};
3035
let release_tag = if stable { date_iso()? } else { "nightly".to_string() };
31-
dist_client(&version, &release_tag)?;
36+
dist_client(&version, &release_tag, &target)?;
3237
}
33-
let release_channel = if stable { "stable" } else { "nightly" };
34-
dist_server(release_channel)?;
3538
Ok(())
3639
}
3740
}
3841

39-
fn dist_client(version: &str, release_tag: &str) -> Result<()> {
42+
fn dist_client(version: &str, release_tag: &str, target: &Target) -> Result<()> {
43+
let bundle_path = Path::new("editors").join("code").join("server");
44+
mkdir_p(&bundle_path)?;
45+
cp(&target.server_path, &bundle_path)?;
46+
if let Some(symbols_path) = &target.symbols_path {
47+
cp(symbols_path, &bundle_path)?;
48+
}
49+
4050
let _d = pushd("./editors/code")?;
4151
let nightly = release_tag == "nightly";
4252

4353
let mut patch = Patch::new("./package.json")?;
44-
4554
patch
4655
.replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version))
4756
.replace(r#""releaseTag": null"#, &format!(r#""releaseTag": "{}""#, release_tag))
@@ -59,12 +68,10 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> {
5968
}
6069
patch.commit()?;
6170

62-
cmd!("npm ci").run()?;
63-
cmd!("npx vsce package -o ../../dist/rust-analyzer.vsix").run()?;
6471
Ok(())
6572
}
6673

67-
fn dist_server(release_channel: &str) -> Result<()> {
74+
fn dist_server(release_channel: &str, target: &Target) -> Result<()> {
6875
let _e = pushenv("RUST_ANALYZER_CHANNEL", release_channel);
6976
let _e = pushenv("CARGO_PROFILE_RELEASE_LTO", "thin");
7077

@@ -73,47 +80,19 @@ fn dist_server(release_channel: &str) -> Result<()> {
7380
// * on Linux, this blows up the binary size from 8MB to 43MB, which is unreasonable.
7481
// let _e = pushenv("CARGO_PROFILE_RELEASE_DEBUG", "1");
7582

76-
let target = get_target();
77-
if target.contains("-linux-gnu") || target.contains("-linux-musl") {
83+
if target.name.contains("-linux-") {
7884
env::set_var("CC", "clang");
7985
}
8086

81-
cmd!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target} --release").run()?;
87+
let target_name = &target.name;
88+
cmd!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} --release").run()?;
8289

83-
let suffix = exe_suffix(&target);
84-
let src =
85-
Path::new("target").join(&target).join("release").join(format!("rust-analyzer{}", suffix));
86-
let dst = Path::new("dist").join(format!("rust-analyzer-{}{}", target, suffix));
87-
gzip(&src, &dst.with_extension("gz"))?;
90+
let dst = Path::new("dist").join(&target.artifact_name);
91+
gzip(&target.server_path, &dst.with_extension("gz"))?;
8892

8993
Ok(())
9094
}
9195

92-
fn get_target() -> String {
93-
match env::var("RA_TARGET") {
94-
Ok(target) => target,
95-
_ => {
96-
if cfg!(target_os = "linux") {
97-
"x86_64-unknown-linux-gnu".to_string()
98-
} else if cfg!(target_os = "windows") {
99-
"x86_64-pc-windows-msvc".to_string()
100-
} else if cfg!(target_os = "macos") {
101-
"x86_64-apple-darwin".to_string()
102-
} else {
103-
panic!("Unsupported OS, maybe try setting RA_TARGET")
104-
}
105-
}
106-
}
107-
}
108-
109-
fn exe_suffix(target: &str) -> String {
110-
if target.contains("-windows-") {
111-
".exe".into()
112-
} else {
113-
"".into()
114-
}
115-
}
116-
11796
fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> {
11897
let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best());
11998
let mut input = io::BufReader::new(File::open(src_path)?);
@@ -122,6 +101,41 @@ fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> {
122101
Ok(())
123102
}
124103

104+
struct Target {
105+
name: String,
106+
server_path: PathBuf,
107+
symbols_path: Option<PathBuf>,
108+
artifact_name: String,
109+
}
110+
111+
impl Target {
112+
fn get(project_root: &Path) -> Self {
113+
let name = match env::var("RA_TARGET") {
114+
Ok(target) => target,
115+
_ => {
116+
if cfg!(target_os = "linux") {
117+
"x86_64-unknown-linux-gnu".to_string()
118+
} else if cfg!(target_os = "windows") {
119+
"x86_64-pc-windows-msvc".to_string()
120+
} else if cfg!(target_os = "macos") {
121+
"x86_64-apple-darwin".to_string()
122+
} else {
123+
panic!("Unsupported OS, maybe try setting RA_TARGET")
124+
}
125+
}
126+
};
127+
let out_path = project_root.join("target").join(&name).join("release");
128+
let (exe_suffix, symbols_path) = if name.contains("-windows-") {
129+
(".exe".into(), Some(out_path.join("rust_analyzer.pdb")))
130+
} else {
131+
(String::new(), None)
132+
};
133+
let server_path = out_path.join(format!("rust-analyzer{}", exe_suffix));
134+
let artifact_name = format!("rust-analyzer-{}{}", name, exe_suffix);
135+
Self { name, server_path, symbols_path, artifact_name }
136+
}
137+
}
138+
125139
struct Patch {
126140
path: PathBuf,
127141
original_contents: String,
@@ -149,6 +163,8 @@ impl Patch {
149163

150164
impl Drop for Patch {
151165
fn drop(&mut self) {
152-
write_file(&self.path, &self.original_contents).unwrap();
166+
// FIXME: find a way to bring this back
167+
let _ = &self.original_contents;
168+
// write_file(&self.path, &self.original_contents).unwrap();
153169
}
154170
}

0 commit comments

Comments
 (0)