diff options
author | Aleksey Kladov <[email protected]> | 2020-03-04 17:59:06 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-04 17:59:06 +0000 |
commit | ce663ed4954361a0421ff4b46747cb7c197e0204 (patch) | |
tree | 54ec341a5651c9c808515c2c58881e96c382a811 /xtask/src/dist.rs | |
parent | cbd34d1bdfa663c185f4b600f983fab7792a6f5a (diff) | |
parent | 6647e817e2f004133d7393171da5033c671ca0f9 (diff) |
Merge pull request #3461 from matklad/dist
Use xtask dist for releases
Diffstat (limited to 'xtask/src/dist.rs')
-rw-r--r-- | xtask/src/dist.rs | 79 |
1 files changed, 79 insertions, 0 deletions
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 @@ | |||
1 | use std::path::PathBuf; | ||
2 | |||
3 | use anyhow::Result; | ||
4 | |||
5 | use crate::{ | ||
6 | not_bash::{fs2, pushd, pwd, rm_rf, run}, | ||
7 | project_root, | ||
8 | }; | ||
9 | |||
10 | pub 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 | |||
22 | fn 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 | |||
46 | fn 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 | |||
70 | struct Restore { | ||
71 | path: PathBuf, | ||
72 | contents: String, | ||
73 | } | ||
74 | |||
75 | impl Drop for Restore { | ||
76 | fn drop(&mut self) { | ||
77 | fs2::write(&self.path, &self.contents).unwrap(); | ||
78 | } | ||
79 | } | ||