diff options
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/src/build.rs | 82 | ||||
-rw-r--r-- | xtask/src/flags.rs | 7 | ||||
-rw-r--r-- | xtask/src/main.rs | 30 | ||||
-rw-r--r-- | xtask/src/pipelines.rs | 50 |
4 files changed, 49 insertions, 120 deletions
diff --git a/xtask/src/build.rs b/xtask/src/build.rs index 86ca7cd23..edc0c79e6 100644 --- a/xtask/src/build.rs +++ b/xtask/src/build.rs @@ -3,7 +3,6 @@ //! Currently has the following functions: //! //! - [`build`]: Builds general cargo projects (i.e. zellij components) with `cargo build` -//! - [`wasm_opt_plugin`]: Calls `wasm-opt` on all plugins //! - [`manpage`]: Builds the manpage with `mandown` use crate::flags; use anyhow::Context; @@ -48,91 +47,10 @@ pub fn build(sh: &Shell, flags: flags::Build) -> anyhow::Result<()> { base_cmd = base_cmd.arg("--release"); } base_cmd.run().with_context(err_context)?; - - if subcrate.contains("plugins") { - let (_, plugin_name) = subcrate - .rsplit_once('/') - .context("Cannot determine plugin name from '{subcrate}'")?; - - if flags.release { - // Perform wasm-opt on plugin - wasm_opt_plugin(sh, plugin_name).with_context(err_context)?; - } - } } Ok(()) } -/// Call `wasm-opt` on all plugins. -/// -/// Plugins are discovered automatically by scanning the contents of `target/wasm32-wasi/release` -/// for filenames ending with `.wasm`. For this to work the plugins must be built beforehand. -// TODO: Should this panic if there is no plugin found? What should we do when only some plugins -// have been built before? -pub fn wasm_opt_plugin(sh: &Shell, plugin_name: &str) -> anyhow::Result<()> { - let err_context = || format!("failed to run 'wasm-opt' on plugin '{plugin_name}'"); - - let wasm_opt = wasm_opt(sh).with_context(err_context)?; - - let asset_dir = crate::project_root() - .join("zellij-utils") - .join("assets") - .join("plugins"); - sh.create_dir(&asset_dir).with_context(err_context)?; - let _pd = sh.push_dir(asset_dir); - - let plugin = PathBuf::from( - std::env::var_os("CARGO_TARGET_DIR") - .unwrap_or(crate::project_root().join("target").into_os_string()), - ) - .join("wasm32-wasi") - .join("release") - .join(plugin_name) - .with_extension("wasm"); - - if !plugin.is_file() { - return Err(anyhow::anyhow!("No plugin found at '{}'", plugin.display())) - .with_context(err_context); - } - let name = match plugin.file_name().with_context(err_context)?.to_str() { - Some(name) => name, - None => { - return Err(anyhow::anyhow!( - "couldn't read filename containing invalid unicode" - )) - .with_context(err_context) - }, - }; - - // This is a plugin we want to optimize - println!(); - let msg = format!(">> Optimizing plugin '{name}'"); - crate::status(&msg); - println!("{}", msg); - - let input = plugin.as_path(); - cmd!(sh, "{wasm_opt} -O {input} -o {name}") - .run() - .with_context(err_context)?; - - Ok(()) -} - -/// Get the path to a `wasm-opt` executable. -/// -/// If the executable isn't found, an error is returned instead. -// TODO: Offer the user to install latest wasm-opt on path? -fn wasm_opt(_sh: &Shell) -> anyhow::Result<PathBuf> { - match which::which("wasm-opt") { - Ok(path) => Ok(path), - Err(e) => { - println!("!! 'wasm-opt' wasn't found but is needed for this build step."); - println!("!! Please install it from here: https://github.com/WebAssembly/binaryen"); - Err(e).context("couldn't find 'wasm-opt' executable") - }, - } -} - /// Build the manpage with `mandown`. // mkdir -p ${root_dir}/assets/man // mandown ${root_dir}/docs/MANPAGE.md 1 > ${root_dir}/assets/man/zellij.1 diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs index 2aed0013f..4630a8938 100644 --- a/xtask/src/flags.rs +++ b/xtask/src/flags.rs @@ -38,6 +38,10 @@ xflags::xflags! { cmd publish { /// Perform a dry-run (don't push/publish anything) optional --dry-run + /// Push commit to custom git remote + optional --git-remote remote: OsString + /// Publish crates to custom registry + optional --cargo-registry registry: OsString } /// Package zellij for distribution (result found in ./target/dist) @@ -151,6 +155,8 @@ pub struct Manpage; #[derive(Debug)] pub struct Publish { pub dry_run: bool, + pub git_remote: Option<OsString>, + pub cargo_registry: Option<OsString>, } #[derive(Debug)] @@ -175,7 +181,6 @@ pub struct Run { pub args: Vec<OsString>, pub data_dir: Option<PathBuf>, - pub singlepass: bool, } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index c81717056..209caa5e7 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -5,36 +5,6 @@ //! xtask install` for installation of rust-analyzer server and client. //! //! This binary is integrated into the `cargo` command line by using an alias in `.cargo/config`. -// Current default "flow": -// - format-flow: `cargo fmt` -// - format-toml-conditioned-flow: ?? -// - build: `cargo build` -// - test: `cargo test` -// - clippy: `cargo clippy --all-targets --all-features -- --deny warnings $@` -// -// # Install flow: -// - build-plugins-release: `cargo build --release ...` -// - wasm-opt-plugins: `wasm-opt ...` -// - build-release: `cargo build --release` -// - install-mandown: `cargo install mandown` -// - manpage: | -// mkdir -p ${root_dir}/assets/man -// mandown ${root_dir}/docs/MANPAGE.md 1 > ${root_dir}/assets/man/zellij.1 -// - install: `cp target/release/zellij "$1"` -// -// # Release flow: -// - workspace: cargo make --profile development -- release -// -// # Publish flow: -// - update-default-config: -// - build-plugins-release: `cargo build --release ...` -// - wasm-opt-plugins: `wasm-opt ...` -// - release-commit: -// - commit-all: `git commit -aem "chore(release): v${CRATE_VERSION}"` -// - tag-release: `git tag --annotate --message "Version ${CRATE_VERSION}" -// "v${CRATE_VERSION}"` -// - `git push --atomic origin main "v${CRATE_VERSION}"` -// - publish-zellij: `cargo publish [tile, client, server, utils, tile-utils, zellij]` mod build; mod ci; diff --git a/xtask/src/pipelines.rs b/xtask/src/pipelines.rs index a615c0971..ad21bffe5 100644 --- a/xtask/src/pipelines.rs +++ b/xtask/src/pipelines.rs @@ -44,7 +44,6 @@ pub fn make(sh: &Shell, flags: flags::Make) -> anyhow::Result<()> { /// Runs the following steps in sequence: /// /// - [`build`](build::build) (release, plugins only) -/// - [`wasm_opt_plugins`](build::wasm_opt_plugins) /// - [`build`](build::build) (release, without plugins) /// - [`manpage`](build::manpage) /// - Copy the executable to [target file](flags::Install::destination) @@ -168,12 +167,30 @@ pub fn dist(sh: &Shell, _flags: flags::Dist) -> anyhow::Result<()> { pub fn publish(sh: &Shell, flags: flags::Publish) -> anyhow::Result<()> { let err_context = "failed to publish zellij"; - sh.change_dir(crate::project_root()); + // Process flags let dry_run = if flags.dry_run { Some("--dry-run") } else { None }; + let remote = flags.git_remote.unwrap_or("origin".into()); + let registry = if let Some(registry) = flags.cargo_registry { + Some(format!( + "--registry={}", + registry + .into_string() + .map_err(|registry| anyhow::Error::msg(format!( + "failed to convert '{:?}' to valid registry name", + registry + ))) + .context(err_context)? + )) + } else { + None + }; + let registry = registry.as_ref(); + + sh.change_dir(crate::project_root()); let cargo = crate::cargo().context(err_context)?; let project_dir = crate::project_root(); let manifest = sh @@ -265,22 +282,36 @@ pub fn publish(sh: &Shell, flags: flags::Publish) -> anyhow::Result<()> { if flags.dry_run { println!("Skipping push due to dry-run"); } else { - cmd!(sh, "git push --atomic origin main v{version}") + cmd!(sh, "git push --atomic {remote} main v{version}") .run() .context(err_context)?; } // Publish all the crates for member in crate::WORKSPACE_MEMBERS.iter() { - if member.contains("plugin") { + if member.contains("plugin") || member.contains("xtask") { continue; } let _pd = sh.push_dir(project_dir.join(member)); loop { - if let Err(err) = cmd!(sh, "{cargo} publish {dry_run...}") - .run() - .context(err_context) + let msg = format!(">> Publishing '{member}'"); + crate::status(&msg); + println!("{}", msg); + + let more_args = match *member { + // This is needed for zellij to pick up the plugins from the assets included in + // the released zellij-utils binary + "." => Some("--no-default-features"), + _ => None, + }; + + if let Err(err) = cmd!( + sh, + "{cargo} publish {registry...} {more_args...} {dry_run...}" + ) + .run() + .context(err_context) { println!(); println!("Publishing crate '{member}' failed with error:"); @@ -325,6 +356,11 @@ pub fn publish(sh: &Shell, flags: flags::Publish) -> anyhow::Result<()> { } } } + + println!(); + println!(" +-----------------------------------------------+"); + println!(" | PRAISE THE DEVS, WE HAVE A NEW ZELLIJ RELEASE |"); + println!(" +-----------------------------------------------+"); Ok(()) }; |