diff options
author | Laurențiu Nicola <[email protected]> | 2020-12-21 19:06:46 +0000 |
---|---|---|
committer | Laurențiu Nicola <[email protected]> | 2020-12-22 11:18:00 +0000 |
commit | e8818151153720898867c50699e0e781d88b2a34 (patch) | |
tree | 75afc5e63afa07287f932c0ab9f83b8c84ad87e1 /xtask | |
parent | e4f922a74d66153ac099ad909e0ea5151292b8a5 (diff) |
Build aarch64-apple-darwin binaries on CI
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/src/dist.rs | 72 |
1 files changed, 58 insertions, 14 deletions
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index 9e15a5a4c..d07ad9420 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs | |||
@@ -58,30 +58,74 @@ 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 | ||
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)); | ||
79 | cp(&src, &dst)?; | 73 | cp(&src, &dst)?; |
80 | gzip(&src, &dst.with_extension("gz"))?; | 74 | gzip(&src, &dst.with_extension("gz"))?; |
81 | 75 | ||
76 | // FIXME: the old names are temporarily kept for client compatibility, but they should be removed | ||
77 | // Remove this block after a couple of releases | ||
78 | match target.as_ref() { | ||
79 | "x86_64-unknown-linux-gnu" => { | ||
80 | cp(&src, "dist/rust-analyzer-linux")?; | ||
81 | gzip(&src, Path::new("dist/rust-analyzer-linux.gz"))?; | ||
82 | } | ||
83 | "x86_64-pc-windows-msvc" => { | ||
84 | cp(&src, "dist/rust-analyzer-windows.exe")?; | ||
85 | gzip(&src, Path::new("dist/rust-analyzer-windows.gz"))?; | ||
86 | } | ||
87 | "x86_64-apple-darwin" => { | ||
88 | cp(&src, "dist/rust-analyzer-mac")?; | ||
89 | gzip(&src, Path::new("dist/rust-analyzer-mac.gz"))?; | ||
90 | } | ||
91 | _ => {} | ||
92 | } | ||
93 | |||
82 | Ok(()) | 94 | Ok(()) |
83 | } | 95 | } |
84 | 96 | ||
97 | fn get_target() -> String { | ||
98 | match env::var("RA_TARGET") { | ||
99 | Ok(target) => target, | ||
100 | _ => { | ||
101 | if cfg!(target_os = "linux") { | ||
102 | "x86_64-unknown-linux-gnu".to_string() | ||
103 | } else if cfg!(target_os = "windows") { | ||
104 | "x86_64-pc-windows-msvc".to_string() | ||
105 | } else if cfg!(target_os = "macos") { | ||
106 | "x86_64-apple-darwin".to_string() | ||
107 | } else { | ||
108 | panic!("Unsupported OS, maybe try setting RA_TARGET") | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | |||
114 | fn exe_suffix(target: &str) -> String { | ||
115 | if target.contains("-windows-") { | ||
116 | ".exe".into() | ||
117 | } else { | ||
118 | "".into() | ||
119 | } | ||
120 | } | ||
121 | |||
122 | fn toolchain(target: &str) -> String { | ||
123 | match target { | ||
124 | "aarch64-apple-darwin" => "beta".to_string(), | ||
125 | _ => "stable".to_string(), | ||
126 | } | ||
127 | } | ||
128 | |||
85 | fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> { | 129 | fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> { |
86 | let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best()); | 130 | let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best()); |
87 | let mut input = io::BufReader::new(File::open(src_path)?); | 131 | let mut input = io::BufReader::new(File::open(src_path)?); |