From c06efa380debe52dfdc965e23d3d4f2885a30ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 21 Dec 2020 21:06:46 +0200 Subject: Build aarch64-apple-darwin binaries on CI --- xtask/src/dist.rs | 72 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 14 deletions(-) (limited to 'xtask/src') 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<()> { } fn dist_server() -> Result<()> { - if cfg!(target_os = "linux") { + let target = get_target(); + if target.contains("-linux-gnu") { env::set_var("CC", "clang"); } - cmd!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release").run()?; - - let (src, dst) = if cfg!(target_os = "linux") { - ("./target/release/rust-analyzer", "./dist/rust-analyzer-linux") - } else if cfg!(target_os = "windows") { - ("./target/release/rust-analyzer.exe", "./dist/rust-analyzer-windows.exe") - } else if cfg!(target_os = "macos") { - ("./target/release/rust-analyzer", "./dist/rust-analyzer-mac") - } else { - panic!("Unsupported OS") - }; - let src = Path::new(src); - let dst = Path::new(dst); + let toolchain = toolchain(&target); + cmd!("cargo +{toolchain} build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target} --release").run()?; + let suffix = exe_suffix(&target); + let src = + Path::new("target").join(&target).join("release").join(format!("rust-analyzer{}", suffix)); + let dst = Path::new("dist").join(format!("rust-analyzer-{}{}", target, suffix)); cp(&src, &dst)?; gzip(&src, &dst.with_extension("gz"))?; + // FIXME: the old names are temporarily kept for client compatibility, but they should be removed + // Remove this block after a couple of releases + match target.as_ref() { + "x86_64-unknown-linux-gnu" => { + cp(&src, "dist/rust-analyzer-linux")?; + gzip(&src, Path::new("dist/rust-analyzer-linux.gz"))?; + } + "x86_64-pc-windows-msvc" => { + cp(&src, "dist/rust-analyzer-windows.exe")?; + gzip(&src, Path::new("dist/rust-analyzer-windows.gz"))?; + } + "x86_64-apple-darwin" => { + cp(&src, "dist/rust-analyzer-mac")?; + gzip(&src, Path::new("dist/rust-analyzer-mac.gz"))?; + } + _ => {} + } + Ok(()) } +fn get_target() -> String { + match env::var("RA_TARGET") { + Ok(target) => target, + _ => { + if cfg!(target_os = "linux") { + "x86_64-unknown-linux-gnu".to_string() + } else if cfg!(target_os = "windows") { + "x86_64-pc-windows-msvc".to_string() + } else if cfg!(target_os = "macos") { + "x86_64-apple-darwin".to_string() + } else { + panic!("Unsupported OS, maybe try setting RA_TARGET") + } + } + } +} + +fn exe_suffix(target: &str) -> String { + if target.contains("-windows-") { + ".exe".into() + } else { + "".into() + } +} + +fn toolchain(target: &str) -> String { + match target { + "aarch64-apple-darwin" => "beta".to_string(), + _ => "stable".to_string(), + } +} + fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> { let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best()); let mut input = io::BufReader::new(File::open(src_path)?); -- cgit v1.2.3