diff options
Diffstat (limited to 'xtask/src')
-rw-r--r-- | xtask/src/dist.rs | 73 |
1 files changed, 58 insertions, 15 deletions
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index 9e15a5a4c..d59b88131 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs | |||
@@ -58,30 +58,73 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> { | |||
58 | } | 58 | } |
59 | 59 | ||
60 | fn dist_server() -> Result<()> { | 60 | fn dist_server() -> Result<()> { |
61 | if cfg!(target_os = "linux") { | 61 | let target = get_target(); |
62 | if target.contains("-linux-gnu") { | ||
62 | env::set_var("CC", "clang"); | 63 | env::set_var("CC", "clang"); |
63 | } | 64 | } |
64 | cmd!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release").run()?; | ||
65 | |||
66 | let (src, dst) = if cfg!(target_os = "linux") { | ||
67 | ("./target/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") | ||
72 | } else { | ||
73 | panic!("Unsupported OS") | ||
74 | }; | ||
75 | 65 | ||
76 | let src = Path::new(src); | 66 | let toolchain = toolchain(&target); |
77 | let dst = Path::new(dst); | 67 | cmd!("cargo +{toolchain} build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target} --release").run()?; |
78 | 68 | ||
79 | cp(&src, &dst)?; | 69 | let suffix = exe_suffix(&target); |
70 | let src = | ||
71 | Path::new("target").join(&target).join("release").join(format!("rust-analyzer{}", suffix)); | ||
72 | let dst = Path::new("dist").join(format!("rust-analyzer-{}{}", target, suffix)); | ||
80 | gzip(&src, &dst.with_extension("gz"))?; | 73 | gzip(&src, &dst.with_extension("gz"))?; |
81 | 74 | ||
75 | // FIXME: the old names are temporarily kept for client compatibility, but they should be removed | ||
76 | // Remove this block after a couple of releases | ||
77 | match target.as_ref() { | ||
78 | "x86_64-unknown-linux-gnu" => { | ||
79 | cp(&src, "dist/rust-analyzer-linux")?; | ||
80 | gzip(&src, Path::new("dist/rust-analyzer-linux.gz"))?; | ||
81 | } | ||
82 | "x86_64-pc-windows-msvc" => { | ||
83 | cp(&src, "dist/rust-analyzer-windows.exe")?; | ||
84 | gzip(&src, Path::new("dist/rust-analyzer-windows.gz"))?; | ||
85 | } | ||
86 | "x86_64-apple-darwin" => { | ||
87 | cp(&src, "dist/rust-analyzer-mac")?; | ||
88 | gzip(&src, Path::new("dist/rust-analyzer-mac.gz"))?; | ||
89 | } | ||
90 | _ => {} | ||
91 | } | ||
92 | |||
82 | Ok(()) | 93 | Ok(()) |
83 | } | 94 | } |
84 | 95 | ||
96 | fn get_target() -> String { | ||
97 | match env::var("RA_TARGET") { | ||
98 | Ok(target) => target, | ||
99 | _ => { | ||
100 | if cfg!(target_os = "linux") { | ||
101 | "x86_64-unknown-linux-gnu".to_string() | ||
102 | } else if cfg!(target_os = "windows") { | ||
103 | "x86_64-pc-windows-msvc".to_string() | ||
104 | } else if cfg!(target_os = "macos") { | ||
105 | "x86_64-apple-darwin".to_string() | ||
106 | } else { | ||
107 | panic!("Unsupported OS, maybe try setting RA_TARGET") | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | |||
113 | fn exe_suffix(target: &str) -> String { | ||
114 | if target.contains("-windows-") { | ||
115 | ".exe".into() | ||
116 | } else { | ||
117 | "".into() | ||
118 | } | ||
119 | } | ||
120 | |||
121 | fn toolchain(target: &str) -> String { | ||
122 | match target { | ||
123 | "aarch64-apple-darwin" => "beta".to_string(), | ||
124 | _ => "stable".to_string(), | ||
125 | } | ||
126 | } | ||
127 | |||
85 | fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> { | 128 | fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> { |
86 | let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best()); | 129 | let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best()); |
87 | let mut input = io::BufReader::new(File::open(src_path)?); | 130 | let mut input = io::BufReader::new(File::open(src_path)?); |