cargo xtask dist

This builds the typescript extension
This commit is contained in:
Aleksey Kladov 2020-03-04 17:58:22 +01:00
parent ae6109a68c
commit fd586e58d9
6 changed files with 81 additions and 41 deletions

View file

@ -41,19 +41,27 @@ 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'
run: cargo xtask dist
- name: Build VS Code extension
if: matrix.os == 'ubuntu-latest' && 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: Create distribution dir
run: mkdir ./dist
- 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
@ -72,33 +80,6 @@ jobs:
name: server-${{ matrix.os }}
path: ./dist
build-clients:
name: build-clients
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v1
- name: Install Nodejs
uses: actions/setup-node@v1
with:
node-version: 12.x
- run: npm ci
working-directory: ./editors/code
- run: npm run package --scripts-prepend-node-path
working-directory: ./editors/code
- name: Copy vscode extension
run: mkdir -p ./dist/code && cp ./editors/code/rust-analyzer.vsix ./dist/
- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: editor-plugins
path: ./dist
make-release:
name: make-release
runs-on: ubuntu-latest
@ -150,4 +131,4 @@ jobs:
if: github.event_name == 'push'
working-directory: ./editors/code
# token from https://dev.azure.com/rust-analyzer/
run: npx vsce publish 0.1.$(date +%Y%m%d) --pat ${{ secrets.MARKETPLACE_TOKEN }}
run: npx vsce publish 0.1.$(date +%Y%m%d) --pat ${{ secrets.MARKETPLACE_TOKEN }} --packagePath ../../dist/rust-analyzer.vsix

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
/target/
/dist/
crates/*/target
**/*.rs.bk
**/*.rs.pending-snap

View file

@ -4,10 +4,7 @@ use std::{env, path::PathBuf, str};
use anyhow::{bail, format_err, Context, Result};
use crate::{
not_bash::{pushd, run},
project_root,
};
use crate::not_bash::{pushd, run};
// Latest stable, feel free to send a PR if this lags behind.
const REQUIRED_RUST_VERSION: u32 = 41;
@ -27,7 +24,6 @@ pub struct ServerOpt {
impl InstallCmd {
pub fn run(self) -> Result<()> {
let _dir = pushd(project_root());
let both = self.server.is_some() && self.client.is_some();
if cfg!(target_os = "macos") {
fix_path_for_mac().context("Fix path for mac")?

View file

@ -19,7 +19,7 @@ use std::{
use crate::{
codegen::Mode,
not_bash::{fs2, pushd, rm_rf, run},
not_bash::{fs2, pushd, pwd, rm_rf, run},
};
pub use anyhow::Result;
@ -206,3 +206,42 @@ 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();
}
}

View file

@ -14,7 +14,9 @@ use pico_args::Arguments;
use xtask::{
codegen::{self, Mode},
install::{ClientOpt, InstallCmd, ServerOpt},
pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_release, run_rustfmt, Result,
not_bash::pushd,
pre_commit, project_root, run_clippy, run_dist, run_fuzzer, run_pre_cache, run_release,
run_rustfmt, Result,
};
fn main() -> Result<()> {
@ -22,6 +24,8 @@ fn main() -> Result<()> {
return pre_commit::run_hook();
}
let _d = pushd(project_root());
let mut args = Arguments::from_env();
let subcommand = args.subcommand()?.unwrap_or_default();
@ -97,6 +101,11 @@ FLAGS:
args.finish()?;
run_release(dry_run)
}
"dist" => {
let nightly = args.contains("--nightly");
args.finish()?;
run_dist(nightly)
}
_ => {
eprintln!(
"\
@ -112,7 +121,8 @@ SUBCOMMANDS:
fuzz-tests
codegen
install
lint"
lint
dist"
);
Ok(())
}

View file

@ -19,6 +19,11 @@ pub mod fs2 {
fs::read_dir(path).with_context(|| format!("Failed to read {}", path.display()))
}
pub fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String> {
let path = path.as_ref();
fs::read_to_string(path).with_context(|| format!("Failed to read {}", path.display()))
}
pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> {
let path = path.as_ref();
fs::write(path, contents).with_context(|| format!("Failed to write {}", path.display()))
@ -40,6 +45,11 @@ pub mod fs2 {
let path = path.as_ref();
fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display()))
}
pub fn create_dir_all<P: AsRef<Path>>(path: P) -> Result<()> {
let path = path.as_ref();
fs::create_dir_all(path).with_context(|| format!("Failed to create dir {}", path.display()))
}
}
macro_rules! _run {
@ -61,6 +71,10 @@ pub fn pushd(path: impl Into<PathBuf>) -> Pushd {
Pushd { _p: () }
}
pub fn pwd() -> PathBuf {
Env::with(|env| env.cwd())
}
impl Drop for Pushd {
fn drop(&mut self) {
Env::with(|env| env.popd())
@ -85,7 +99,6 @@ pub fn run_process(cmd: String, echo: bool) -> Result<String> {
}
fn run_process_inner(cmd: &str, echo: bool) -> Result<String> {
let cwd = Env::with(|env| env.cwd());
let mut args = shelx(cmd);
let binary = args.remove(0);
@ -95,7 +108,7 @@ fn run_process_inner(cmd: &str, echo: bool) -> Result<String> {
let output = Command::new(binary)
.args(args)
.current_dir(cwd)
.current_dir(pwd())
.stdin(Stdio::null())
.stderr(Stdio::inherit())
.output()?;