1 use std::path::PathBuf;
6 not_bash::{date_iso, fs2, pushd, rm_rf, run},
10 pub fn run_dist(nightly: bool, client_version: Option<String>) -> Result<()> {
11 let dist = project_root().join("dist");
13 fs2::create_dir_all(&dist)?;
15 if let Some(version) = client_version {
16 let release_tag = if nightly { "nightly".to_string() } else { date_iso()? };
17 dist_client(&version, &release_tag)?;
19 dist_server(nightly)?;
23 fn dist_client(version: &str, release_tag: &str) -> Result<()> {
24 let _d = pushd("./editors/code");
25 let nightly = release_tag == "nightly";
27 let mut patch = Patch::new("./package.json")?;
30 .replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version))
31 .replace(r#""releaseTag": null"#, &format!(r#""releaseTag": "{}""#, release_tag));
35 r#""displayName": "rust-analyzer""#,
36 r#""displayName": "rust-analyzer (nightly)""#,
40 patch.replace(r#""enableProposedApi": true,"#, r#""#);
45 run!("npx vsce package -o ../../dist/rust-analyzer.vsix")?;
49 fn dist_server(nightly: bool) -> Result<()> {
50 if cfg!(target_os = "linux") {
51 std::env::set_var("CC", "clang");
53 "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release
54 --target x86_64-unknown-linux-musl
56 // We'd want to add, but that requires setting the right linker somehow
57 // --features=jemalloc
60 run!("strip ./target/x86_64-unknown-linux-musl/release/rust-analyzer")?;
63 run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?;
66 let (src, dst) = if cfg!(target_os = "linux") {
67 ("./target/x86_64-unknown-linux-musl/release/rust-analyzer", "./dist/rust-analyzer-linux")
68 } else if cfg!(target_os = "windows") {
69 ("./target/release/rust-analyzer.exe", "./dist/rust-analyzer-windows.exe")
70 } else if cfg!(target_os = "macos") {
71 ("./target/release/rust-analyzer", "./dist/rust-analyzer-mac")
73 panic!("Unsupported OS")
83 original_contents: String,
88 fn new(path: impl Into<PathBuf>) -> Result<Patch> {
89 let path = path.into();
90 let contents = fs2::read_to_string(&path)?;
91 Ok(Patch { path, original_contents: contents.clone(), contents })
94 fn replace(&mut self, from: &str, to: &str) -> &mut Patch {
95 assert!(self.contents.contains(from));
96 self.contents = self.contents.replace(from, to);
100 fn commit(&self) -> Result<()> {
101 fs2::write(&self.path, &self.contents)
105 impl Drop for Patch {
107 fs2::write(&self.path, &self.original_contents).unwrap();