@@ -7,7 +7,7 @@ use std::{
7
7
8
8
use anyhow:: Result ;
9
9
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} ;
11
11
12
12
use crate :: { date_iso, flags, project_root} ;
13
13
@@ -16,10 +16,15 @@ impl flags::Dist {
16
16
let stable =
17
17
std:: env:: var ( "GITHUB_REF" ) . unwrap_or_default ( ) . as_str ( ) == "refs/heads/release" ;
18
18
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" ) ;
20
22
rm_rf ( & dist) ?;
21
23
mkdir_p ( & dist) ?;
22
24
25
+ let release_channel = if stable { "stable" } else { "nightly" } ;
26
+ dist_server ( release_channel, & target) ?;
27
+
23
28
if let Some ( patch_version) = self . client_patch_version {
24
29
let version = if stable {
25
30
format ! ( "0.2.{}" , patch_version)
@@ -28,20 +33,24 @@ impl flags::Dist {
28
33
format ! ( "0.3.{}" , patch_version)
29
34
} ;
30
35
let release_tag = if stable { date_iso ( ) ? } else { "nightly" . to_string ( ) } ;
31
- dist_client ( & version, & release_tag) ?;
36
+ dist_client ( & version, & release_tag, & target ) ?;
32
37
}
33
- let release_channel = if stable { "stable" } else { "nightly" } ;
34
- dist_server ( release_channel) ?;
35
38
Ok ( ( ) )
36
39
}
37
40
}
38
41
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
+
40
50
let _d = pushd ( "./editors/code" ) ?;
41
51
let nightly = release_tag == "nightly" ;
42
52
43
53
let mut patch = Patch :: new ( "./package.json" ) ?;
44
-
45
54
patch
46
55
. replace ( r#""version": "0.4.0-dev""# , & format ! ( r#""version": "{}""# , version) )
47
56
. replace ( r#""releaseTag": null"# , & format ! ( r#""releaseTag": "{}""# , release_tag) )
@@ -59,12 +68,10 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> {
59
68
}
60
69
patch. commit ( ) ?;
61
70
62
- cmd ! ( "npm ci" ) . run ( ) ?;
63
- cmd ! ( "npx vsce package -o ../../dist/rust-analyzer.vsix" ) . run ( ) ?;
64
71
Ok ( ( ) )
65
72
}
66
73
67
- fn dist_server ( release_channel : & str ) -> Result < ( ) > {
74
+ fn dist_server ( release_channel : & str , target : & Target ) -> Result < ( ) > {
68
75
let _e = pushenv ( "RUST_ANALYZER_CHANNEL" , release_channel) ;
69
76
let _e = pushenv ( "CARGO_PROFILE_RELEASE_LTO" , "thin" ) ;
70
77
@@ -73,47 +80,19 @@ fn dist_server(release_channel: &str) -> Result<()> {
73
80
// * on Linux, this blows up the binary size from 8MB to 43MB, which is unreasonable.
74
81
// let _e = pushenv("CARGO_PROFILE_RELEASE_DEBUG", "1");
75
82
76
- let target = get_target ( ) ;
77
- if target. contains ( "-linux-gnu" ) || target. contains ( "-linux-musl" ) {
83
+ if target. name . contains ( "-linux-" ) {
78
84
env:: set_var ( "CC" , "clang" ) ;
79
85
}
80
86
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 ( ) ?;
82
89
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" ) ) ?;
88
92
89
93
Ok ( ( ) )
90
94
}
91
95
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
-
117
96
fn gzip ( src_path : & Path , dest_path : & Path ) -> Result < ( ) > {
118
97
let mut encoder = GzEncoder :: new ( File :: create ( dest_path) ?, Compression :: best ( ) ) ;
119
98
let mut input = io:: BufReader :: new ( File :: open ( src_path) ?) ;
@@ -122,6 +101,41 @@ fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> {
122
101
Ok ( ( ) )
123
102
}
124
103
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
+
125
139
struct Patch {
126
140
path : PathBuf ,
127
141
original_contents : String ,
@@ -149,6 +163,8 @@ impl Patch {
149
163
150
164
impl Drop for Patch {
151
165
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();
153
169
}
154
170
}
0 commit comments