Skip to content

Commit

Permalink
Merge pull request #49 from messense/metadata
Browse files Browse the repository at this point in the history
Add `cargo-zigbuild metadata` subcommand
  • Loading branch information
messense authored Jul 22, 2022
2 parents b799b38 + cc0aa1c commit 8b0dcd5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ jobs:
fail-fast: ${{ !contains(github.event.pull_request.labels.*.name, 'CI-no-fail-fast') }}
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
toolchain: [1.56.1, stable, nightly]
toolchain: [1.57.0, stable, nightly]
zig: [0.9.1, master]
exclude:
# Only test MSRV with zig stable version
- toolchain: 1.56.1
- toolchain: 1.57.0
zig: master
steps:
- uses: actions/checkout@v3
Expand Down
32 changes: 16 additions & 16 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cargo_metadata = "0.15.0"
clap = { version = "3.1.2", features = ["derive", "env", "wrap_help"] }
dirs = "4.0.0"
fs-err = "2.6.0"
path-slash = "0.1.4"
path-slash = "0.2.0"
rustc_version = "0.4.0"
semver = "1.0.5"
serde = { version = "1.0.136", features = ["derive"] }
Expand Down
14 changes: 14 additions & 0 deletions src/bin/cargo-zigbuild.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use anyhow::Context;
use cargo_options::Metadata;
use cargo_zigbuild::{Build, Run, Rustc, Test, Zig};
use clap::Parser;

Expand All @@ -11,6 +13,8 @@ use clap::Parser;
pub enum Opt {
#[clap(name = "zigbuild", aliases = &["build", "b"] )]
Build(Build),
#[clap(name = "metadata")]
Metadata(Metadata),
#[clap(name = "rustc")]
Rustc(Rustc),
#[clap(name = "run", alias = "r")]
Expand All @@ -25,6 +29,16 @@ fn main() -> anyhow::Result<()> {
let opt = Opt::parse();
match opt {
Opt::Build(build) => build.execute()?,
Opt::Metadata(metadata) => {
let mut cmd = metadata.command();
let mut child = cmd.spawn().context("Failed to run cargo metadata")?;
let status = child
.wait()
.expect("Failed to wait on cargo metadata process");
if !status.success() {
std::process::exit(status.code().unwrap_or(1));
}
}
Opt::Rustc(rustc) => rustc.execute()?,
Opt::Run(run) => run.execute()?,
Opt::Test(test) => test.execute()?,
Expand Down
8 changes: 4 additions & 4 deletions src/zig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,11 @@ impl Zig {
let (zig_cc, zig_cxx) = prepare_zig_linker(raw_target)?;
if is_mingw_shell() {
let zig_cc = zig_cc.to_slash_lossy();
cmd.env(format!("CC_{}", env_target), &zig_cc);
cmd.env(format!("CXX_{}", env_target), &zig_cxx.to_slash_lossy());
cmd.env(format!("CC_{}", env_target), &*zig_cc);
cmd.env(format!("CXX_{}", env_target), &*zig_cxx.to_slash_lossy());
cmd.env(
format!("CARGO_TARGET_{}_LINKER", env_target.to_uppercase()),
&zig_cc,
&*zig_cc,
);
} else {
cmd.env(format!("CC_{}", env_target), &zig_cc);
Expand Down Expand Up @@ -565,7 +565,7 @@ fn write_linker_wrapper(path: &Path, command: &str, args: &str) -> Result<()> {
env::current_exe()?
};
let current_exe = if is_mingw_shell() {
current_exe.to_slash_lossy()
current_exe.to_slash_lossy().to_string()
} else {
current_exe.display().to_string()
};
Expand Down

0 comments on commit 8b0dcd5

Please sign in to comment.