From 694ca4e1856605477961015e4ec3ccd8211bcd34 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 4 Mar 2020 18:36:16 +0100 Subject: Build server via dist as well --- xtask/src/dist.rs | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ xtask/src/lib.rs | 42 ++--------------------------- xtask/src/main.rs | 5 ++-- 3 files changed, 84 insertions(+), 42 deletions(-) create mode 100644 xtask/src/dist.rs 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 @@ +use std::path::PathBuf; + +use anyhow::Result; + +use crate::{ + not_bash::{fs2, pushd, pwd, rm_rf, run}, + project_root, +}; + +pub fn run_dist(nightly: bool) -> Result<()> { + let dist = project_root().join("dist"); + rm_rf(&dist)?; + fs2::create_dir_all(&dist)?; + + if cfg!(target_os = "linux") { + dist_client(nightly)?; + } + dist_server()?; + Ok(()) +} + +fn dist_client(nightly: bool) -> Result<()> { + let _d = pushd("./editors/code"); + + let package_json_path = pwd().join("package.json"); + let original_package_json = fs2::read_to_string(&package_json_path)?; + let _restore = + Restore { path: package_json_path.clone(), contents: original_package_json.clone() }; + + let mut package_json = original_package_json.replace(r#""enableProposedApi": true,"#, r#""#); + + if nightly { + package_json = package_json + .replace(r#""name": "rust-analyzer""#, r#""name": "rust-analyzer-nightly""#) + .replace( + r#""displayName": "rust-analyzer""#, + r#""displayName": "rust-analyzer nightly""#, + ); + } + fs2::write(package_json_path, package_json)?; + + run!("npx vsce package -o ../../dist/rust-analyzer.vsix")?; + Ok(()) +} + +fn dist_server() -> Result<()> { + if cfg!(target_os = "linux") { + std::env::set_var("CC", "clang"); + run!("cargo build --package rust-analyzer --bin rust-analyzer --release --target x86_64-unknown-linux-musl")?; + run!("strip ./target/x86_64-unknown-linux-musl/release/rust-analyzer")?; + } else { + run!("cargo build --package rust-analyzer --bin rust-analyzer --release")?; + } + + let (src, dst) = if cfg!(target_os = "linux") { + ("./target/x86_64-unknown-linux-musl/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") + }; + + fs2::copy(src, dst)?; + + Ok(()) +} + +struct Restore { + path: PathBuf, + contents: String, +} + +impl Drop for Restore { + fn drop(&mut self) { + fs2::write(&self.path, &self.contents).unwrap(); + } +} diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 23f85b579..014b61b37 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -4,6 +4,7 @@ pub mod not_bash; pub mod install; +pub mod dist; pub mod pre_commit; pub mod codegen; @@ -19,7 +20,7 @@ use std::{ use crate::{ codegen::Mode, - not_bash::{fs2, pushd, pwd, rm_rf, run}, + not_bash::{fs2, pushd, rm_rf, run}, }; pub use anyhow::Result; @@ -205,42 +206,3 @@ Release: release:{}[] fn is_release_tag(tag: &str) -> bool { tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit()) } - -pub fn run_dist(nightly: bool) -> Result<()> { - let dist = project_root().join("dist"); - rm_rf(&dist)?; - fs2::create_dir_all(&dist)?; - - let _d = pushd("./editors/code"); - - let package_json_path = pwd().join("package.json"); - let original_package_json = fs2::read_to_string(&package_json_path)?; - let _restore = - Restore { path: package_json_path.clone(), contents: original_package_json.clone() }; - - let mut package_json = original_package_json.replace(r#""enableProposedApi": true,"#, r#""#); - - if nightly { - package_json = package_json - .replace(r#""name": "rust-analyzer""#, r#""name": "rust-analyzer-nightly""#) - .replace( - r#""displayName": "rust-analyzer""#, - r#""displayName": "rust-analyzer nightly""#, - ); - } - fs2::write(package_json_path, package_json)?; - - run!("npx vsce package -o {}/rust-analyzer.vsix", dist.display())?; - Ok(()) -} - -struct Restore { - path: PathBuf, - contents: String, -} - -impl Drop for Restore { - fn drop(&mut self) { - fs2::write(&self.path, &self.contents).unwrap(); - } -} diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 17a2f1c68..7c8ea9001 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -13,10 +13,11 @@ use std::env; use pico_args::Arguments; use xtask::{ codegen::{self, Mode}, + dist::run_dist, install::{ClientOpt, InstallCmd, ServerOpt}, not_bash::pushd, - pre_commit, project_root, run_clippy, run_dist, run_fuzzer, run_pre_cache, run_release, - run_rustfmt, Result, + pre_commit, project_root, run_clippy, run_fuzzer, run_pre_cache, run_release, run_rustfmt, + Result, }; fn main() -> Result<()> { -- cgit v1.2.3 From 6647e817e2f004133d7393171da5033c671ca0f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 4 Mar 2020 18:52:18 +0100 Subject: Use xtask dist for releases --- .github/workflows/release.yaml | 45 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f5a07c21f..4031981a8 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -41,43 +41,18 @@ jobs: target: x86_64-unknown-linux-musl override: true - - name: Create distribution dir - run: mkdir ./dist - - - name: Build - if: matrix.os == 'ubuntu-latest' - run: cargo build --package rust-analyzer --bin rust-analyzer --release --target x86_64-unknown-linux-musl - env: - CC: clang - - - name: Build VS Code extension - if: matrix.os == 'ubuntu-latest' && github.event_name == 'push' + - name: Dist + if: github.event_name == 'push' run: cargo xtask dist - - name: Build VS Code extension - if: matrix.os == 'ubuntu-latest' && github.event_name != 'push' + - name: Dist + if: github.event_name != 'push' run: cargo xtask dist --nightly - - name: Build - if: matrix.os != 'ubuntu-latest' - run: cargo build --package rust-analyzer --bin rust-analyzer --release - - - name: Copy binary - if: matrix.os == 'ubuntu-latest' - run: cp ./target/x86_64-unknown-linux-musl/release/rust-analyzer ./dist/rust-analyzer-linux && strip ./dist/rust-analyzer-linux - - - name: Copy binary - if: matrix.os == 'macos-latest' - run: cp ./target/release/rust-analyzer ./dist/rust-analyzer-mac - - - name: Copy binary - if: matrix.os == 'windows-latest' - run: copy ./target/release/rust-analyzer.exe ./dist/rust-analyzer-windows.exe - - name: Upload artifacts uses: actions/upload-artifact@v1 with: - name: server-${{ matrix.os }} + name: dist-${{ matrix.os }} path: ./dist make-release: @@ -101,19 +76,15 @@ jobs: - uses: actions/download-artifact@v1 with: - name: editor-plugins - path: dist - - uses: actions/download-artifact@v1 - with: - name: server-macos-latest + name: dist-macos-latest path: dist - uses: actions/download-artifact@v1 with: - name: server-ubuntu-latest + name: dist-ubuntu-latest path: dist - uses: actions/download-artifact@v1 with: - name: server-windows-latest + name: dist-windows-latest path: dist - run: ls -all ./dist -- cgit v1.2.3