Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:

- uses: pnpm/action-setup@v2
with:
version: 6.32.9
version: 10.7.0
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
cache: 'pnpm'
cache-dependency-path: docs/pnpm-lock.yaml
- name: Build docs
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ node_modules
test/integration
.DS_Store
docs/.vitepress/cache
docs/public/latest-version.json
.idea
73 changes: 5 additions & 68 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ zip = { version = "2", features = ["bzip2", "chrono", "deflate"] }
strip = "symbols"
codegen-units = 1
lto = true

[profile.dev.build-override]
opt-level = 3
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
.PHONY: build build-release-tar build-release-zip check fmt install publish-all run-integration
.PHONY: build build-release build-release-tar build-release-zip check fmt install install-release publish-all run-integration

build:
cargo build
cargo build --features=skip-build-banner

build-release:
cargo build --release --features=skip-build-banner

build-release-tar:
cd $(target)-$(tag)-bin && \
Expand All @@ -24,7 +27,10 @@ fmt:
cargo +nightly fmt --all

install:
cargo install --path crates/cargo-lambda-cli
cargo install --path crates/cargo-lambda-cli --features=skip-build-banner

install-release:
cargo install --release --path crates/cargo-lambda-cli --features=skip-build-banner

publish-all:
cargo publish --package cargo-lambda-interactive
Expand Down
4 changes: 0 additions & 4 deletions crates/cargo-lambda-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ cargo-options.workspace = true
cargo-zigbuild.workspace = true
chrono.workspace = true
chrono-humanize = "0.2.3"
home.workspace = true
miette.workspace = true
object = "0.28.4"
rustc_version = "0.4.0"
sha2 = "0.10.2"
serde.workspace = true
serde_json.workspace = true
strum.workspace = true
strum_macros.workspace = true
tempfile.workspace = true
thiserror.workspace = true
toml.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-lambda-build/src/compiler/cargo_zigbuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl CargoZigbuild {
skip_target_check: bool,
) -> Result<Command> {
tracing::debug!("compiling with CargoZigbuild");
crate::zig::check_installation().await?;
crate::zig::check_installation(false).await?;

// confirm that target component is included in host toolchain, or add
// it with `rustup` otherwise.
Expand Down
5 changes: 1 addition & 4 deletions crates/cargo-lambda-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ use target_arch::validate_linux_target;
mod toolchain;
use toolchain::rustup_cmd;

mod zig;
pub use zig::{
InstallOption, check_installation, install_options, install_zig, print_install_options,
};
pub mod zig;

#[tracing::instrument(skip(build, metadata), target = "cargo_lambda")]
pub async fn run(build: &mut Build, metadata: &CargoMetadata) -> Result<()> {
Expand Down
68 changes: 57 additions & 11 deletions crates/cargo-lambda-build/src/zig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ use cargo_lambda_interactive::{
};
use cargo_zigbuild::Zig;
use miette::{IntoDiagnostic, Result};
use serde::Serialize;
use std::{path::PathBuf, process::Command};

#[derive(Debug, Default, Serialize)]
pub struct ZigInfo {
#[serde(default, skip_serializing_if = "Option::is_none")]
path: Option<PathBuf>,
#[serde(default, skip_serializing_if = "Option::is_none")]
install_options: Option<Vec<InstallOption>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
version: Option<String>,
}

/// Print information about the Zig installation.
pub fn print_install_options(options: &[InstallOption]) {
Expand All @@ -19,12 +31,20 @@ pub fn print_install_options(options: &[InstallOption]) {
}
}
println!(
"\t* Download Zig 0.9.1 or newer from https://ziglang.org/download/ and add it to your PATH"
"\t* Download Zig 0.13.0 or newer from https://ziglang.org/download/ and add it to your PATH"
);
}

/// Install Zig using a choice prompt.
pub async fn install_zig(options: Vec<InstallOption>) -> Result<()> {
pub async fn install_zig(options: Vec<InstallOption>, install_non_interactive: bool) -> Result<()> {
if install_non_interactive {
let Some(choice) = options.first().cloned() else {
return Err(BuildError::ZigMissing.into());
};

return choice.install().await;
}

let choice = choose_option(
"Zig is not installed in your system.\nHow do you want to install Zig?",
options,
Expand All @@ -36,22 +56,48 @@ pub async fn install_zig(options: Vec<InstallOption>) -> Result<()> {
}
}

pub async fn check_installation() -> Result<()> {
if Zig::find_zig().is_ok() {
return Ok(());
pub async fn check_installation(install_non_interactive: bool) -> Result<ZigInfo> {
let zig_info = get_zig_info();
if zig_info.is_ok() {
return zig_info;
}

let options = install_options();

if !is_stdin_tty() || options.is_empty() {
print_install_options(&options);
return Err(BuildError::ZigMissing.into());
if !options.is_empty() && (is_stdin_tty() || install_non_interactive) {
install_zig(options, install_non_interactive).await?;
return get_zig_info();
}

install_zig(options).await
print_install_options(&options);
Err(BuildError::ZigMissing.into())
}

pub fn get_zig_info() -> Result<ZigInfo> {
let Ok((path, run_modifiers)) = Zig::find_zig() else {
let options = install_options();
return Ok(ZigInfo {
install_options: Some(options),
..Default::default()
});
};

let mut cmd = Command::new(&path);
cmd.args(&run_modifiers);
cmd.arg("version");
let output = cmd.output().into_diagnostic()?;
let version = String::from_utf8(output.stdout)
.into_diagnostic()?
.trim()
.to_string();

Ok(ZigInfo {
path: Some(path),
version: Some(version),
..Default::default()
})
}

#[derive(Debug)]
#[derive(Clone, Debug)]
pub enum InstallOption {
#[cfg(not(windows))]
Brew,
Expand Down
Loading