aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/release.yaml45
-rw-r--r--xtask/src/dist.rs79
-rw-r--r--xtask/src/lib.rs42
-rw-r--r--xtask/src/main.rs5
4 files changed, 92 insertions, 79 deletions
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index f5a07c21f..4031981a8 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -41,43 +41,18 @@ jobs:
41 target: x86_64-unknown-linux-musl 41 target: x86_64-unknown-linux-musl
42 override: true 42 override: true
43 43
44 - name: Create distribution dir 44 - name: Dist
45 run: mkdir ./dist 45 if: github.event_name == 'push'
46
47 - name: Build
48 if: matrix.os == 'ubuntu-latest'
49 run: cargo build --package rust-analyzer --bin rust-analyzer --release --target x86_64-unknown-linux-musl
50 env:
51 CC: clang
52
53 - name: Build VS Code extension
54 if: matrix.os == 'ubuntu-latest' && github.event_name == 'push'
55 run: cargo xtask dist 46 run: cargo xtask dist
56 47
57 - name: Build VS Code extension 48 - name: Dist
58 if: matrix.os == 'ubuntu-latest' && github.event_name != 'push' 49 if: github.event_name != 'push'
59 run: cargo xtask dist --nightly 50 run: cargo xtask dist --nightly
60 51
61 - name: Build
62 if: matrix.os != 'ubuntu-latest'
63 run: cargo build --package rust-analyzer --bin rust-analyzer --release
64
65 - name: Copy binary
66 if: matrix.os == 'ubuntu-latest'
67 run: cp ./target/x86_64-unknown-linux-musl/release/rust-analyzer ./dist/rust-analyzer-linux && strip ./dist/rust-analyzer-linux
68
69 - name: Copy binary
70 if: matrix.os == 'macos-latest'
71 run: cp ./target/release/rust-analyzer ./dist/rust-analyzer-mac
72
73 - name: Copy binary
74 if: matrix.os == 'windows-latest'
75 run: copy ./target/release/rust-analyzer.exe ./dist/rust-analyzer-windows.exe
76
77 - name: Upload artifacts 52 - name: Upload artifacts
78 uses: actions/upload-artifact@v1 53 uses: actions/upload-artifact@v1
79 with: 54 with:
80 name: server-${{ matrix.os }} 55 name: dist-${{ matrix.os }}
81 path: ./dist 56 path: ./dist
82 57
83 make-release: 58 make-release:
@@ -101,19 +76,15 @@ jobs:
101 76
102 - uses: actions/download-artifact@v1 77 - uses: actions/download-artifact@v1
103 with: 78 with:
104 name: editor-plugins 79 name: dist-macos-latest
105 path: dist
106 - uses: actions/download-artifact@v1
107 with:
108 name: server-macos-latest
109 path: dist 80 path: dist
110 - uses: actions/download-artifact@v1 81 - uses: actions/download-artifact@v1
111 with: 82 with:
112 name: server-ubuntu-latest 83 name: dist-ubuntu-latest
113 path: dist 84 path: dist
114 - uses: actions/download-artifact@v1 85 - uses: actions/download-artifact@v1
115 with: 86 with:
116 name: server-windows-latest 87 name: dist-windows-latest
117 path: dist 88 path: dist
118 - run: ls -all ./dist 89 - run: ls -all ./dist
119 90
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs
new file mode 100644
index 000000000..cdd3db21c
--- /dev/null
+++ b/xtask/src/dist.rs
@@ -0,0 +1,79 @@
1use std::path::PathBuf;
2
3use anyhow::Result;
4
5use crate::{
6 not_bash::{fs2, pushd, pwd, rm_rf, run},
7 project_root,
8};
9
10pub fn run_dist(nightly: bool) -> Result<()> {
11 let dist = project_root().join("dist");
12 rm_rf(&dist)?;
13 fs2::create_dir_all(&dist)?;
14
15 if cfg!(target_os = "linux") {
16 dist_client(nightly)?;
17 }
18 dist_server()?;
19 Ok(())
20}
21
22fn dist_client(nightly: bool) -> Result<()> {
23 let _d = pushd("./editors/code");
24
25 let package_json_path = pwd().join("package.json");
26 let original_package_json = fs2::read_to_string(&package_json_path)?;
27 let _restore =
28 Restore { path: package_json_path.clone(), contents: original_package_json.clone() };
29
30 let mut package_json = original_package_json.replace(r#""enableProposedApi": true,"#, r#""#);
31
32 if nightly {
33 package_json = package_json
34 .replace(r#""name": "rust-analyzer""#, r#""name": "rust-analyzer-nightly""#)
35 .replace(
36 r#""displayName": "rust-analyzer""#,
37 r#""displayName": "rust-analyzer nightly""#,
38 );
39 }
40 fs2::write(package_json_path, package_json)?;
41
42 run!("npx vsce package -o ../../dist/rust-analyzer.vsix")?;
43 Ok(())
44}
45
46fn dist_server() -> Result<()> {
47 if cfg!(target_os = "linux") {
48 std::env::set_var("CC", "clang");
49 run!("cargo build --package rust-analyzer --bin rust-analyzer --release --target x86_64-unknown-linux-musl")?;
50 run!("strip ./target/x86_64-unknown-linux-musl/release/rust-analyzer")?;
51 } else {
52 run!("cargo build --package rust-analyzer --bin rust-analyzer --release")?;
53 }
54
55 let (src, dst) = if cfg!(target_os = "linux") {
56 ("./target/x86_64-unknown-linux-musl/release/rust-analyzer", "./dist/rust-analyzer-linux")
57 } else if cfg!(target_os = "windows") {
58 ("/target/release/rust-analyzer.exe", "./dist/rust-analyzer-windows.exe")
59 } else if cfg!(target_os = "macos") {
60 ("/target/release/rust-analyzer", "./dist/rust-analyzer-mac")
61 } else {
62 panic!("Unsupported OS")
63 };
64
65 fs2::copy(src, dst)?;
66
67 Ok(())
68}
69
70struct Restore {
71 path: PathBuf,
72 contents: String,
73}
74
75impl Drop for Restore {
76 fn drop(&mut self) {
77 fs2::write(&self.path, &self.contents).unwrap();
78 }
79}
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs
index 23f85b579..014b61b37 100644
--- a/xtask/src/lib.rs
+++ b/xtask/src/lib.rs
@@ -4,6 +4,7 @@
4 4
5pub mod not_bash; 5pub mod not_bash;
6pub mod install; 6pub mod install;
7pub mod dist;
7pub mod pre_commit; 8pub mod pre_commit;
8 9
9pub mod codegen; 10pub mod codegen;
@@ -19,7 +20,7 @@ use std::{
19 20
20use crate::{ 21use crate::{
21 codegen::Mode, 22 codegen::Mode,
22 not_bash::{fs2, pushd, pwd, rm_rf, run}, 23 not_bash::{fs2, pushd, rm_rf, run},
23}; 24};
24 25
25pub use anyhow::Result; 26pub use anyhow::Result;
@@ -205,42 +206,3 @@ Release: release:{}[]
205fn is_release_tag(tag: &str) -> bool { 206fn is_release_tag(tag: &str) -> bool {
206 tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit()) 207 tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit())
207} 208}
208
209pub fn run_dist(nightly: bool) -> Result<()> {
210 let dist = project_root().join("dist");
211 rm_rf(&dist)?;
212 fs2::create_dir_all(&dist)?;
213
214 let _d = pushd("./editors/code");
215
216 let package_json_path = pwd().join("package.json");
217 let original_package_json = fs2::read_to_string(&package_json_path)?;
218 let _restore =
219 Restore { path: package_json_path.clone(), contents: original_package_json.clone() };
220
221 let mut package_json = original_package_json.replace(r#""enableProposedApi": true,"#, r#""#);
222
223 if nightly {
224 package_json = package_json
225 .replace(r#""name": "rust-analyzer""#, r#""name": "rust-analyzer-nightly""#)
226 .replace(
227 r#""displayName": "rust-analyzer""#,
228 r#""displayName": "rust-analyzer nightly""#,
229 );
230 }
231 fs2::write(package_json_path, package_json)?;
232
233 run!("npx vsce package -o {}/rust-analyzer.vsix", dist.display())?;
234 Ok(())
235}
236
237struct Restore {
238 path: PathBuf,
239 contents: String,
240}
241
242impl Drop for Restore {
243 fn drop(&mut self) {
244 fs2::write(&self.path, &self.contents).unwrap();
245 }
246}
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 17a2f1c68..7c8ea9001 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -13,10 +13,11 @@ use std::env;
13use pico_args::Arguments; 13use pico_args::Arguments;
14use xtask::{ 14use xtask::{
15 codegen::{self, Mode}, 15 codegen::{self, Mode},
16 dist::run_dist,
16 install::{ClientOpt, InstallCmd, ServerOpt}, 17 install::{ClientOpt, InstallCmd, ServerOpt},
17 not_bash::pushd, 18 not_bash::pushd,
18 pre_commit, project_root, run_clippy, run_dist, run_fuzzer, run_pre_cache, run_release, 19 pre_commit, project_root, run_clippy, run_fuzzer, run_pre_cache, run_release, run_rustfmt,
19 run_rustfmt, Result, 20 Result,
20}; 21};
21 22
22fn main() -> Result<()> { 23fn main() -> Result<()> {