build: allow passing arbitrary cargo flags

This commit is contained in:
chyyran 2024-02-20 18:08:00 -05:00 committed by Ronny Chan
parent e38f2636d9
commit be11953516
2 changed files with 16 additions and 5 deletions

View file

@ -2,7 +2,7 @@ use clap::Parser;
use std::fs::File; use std::fs::File;
use std::io::{BufWriter, Write}; use std::io::{BufWriter, Write};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::{Command, ExitCode};
use std::{env, fs}; use std::{env, fs};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@ -12,12 +12,14 @@ struct Args {
profile: String, profile: String,
#[arg(long, global = true)] #[arg(long, global = true)]
target: Option<String>, target: Option<String>,
#[arg(last = true)]
cargoflags: Vec<String>,
} }
pub fn main() { pub fn main() -> ExitCode {
// Do not update files on docsrs // Do not update files on docsrs
if env::var("DOCS_RS").is_ok() { if env::var("DOCS_RS").is_ok() {
return; return ExitCode::SUCCESS;
} }
let args = Args::parse(); let args = Args::parse();
@ -44,7 +46,14 @@ pub fn main() {
cmd.arg(format!("--target={}", &target)); cmd.arg(format!("--target={}", &target));
} }
Some(cmd.status().expect("Failed to build librashader-capi")); if !args.cargoflags.is_empty() {
cmd.args(args.cargoflags);
}
let status = cmd.status().expect("Failed to build librashader-capi");
if !status.success() {
return ExitCode::from(status.code().unwrap_or(1) as u8);
}
let mut output_dir = PathBuf::from(format!("target/{}", profile)); let mut output_dir = PathBuf::from(format!("target/{}", profile));
if let Some(target) = &args.target { if let Some(target) = &args.target {
@ -110,4 +119,6 @@ pub fn main() {
.unwrap(); .unwrap();
} }
} }
return ExitCode::SUCCESS;
} }

View file

@ -42,7 +42,7 @@ sptr = "0.3.2"
path = "../librashader" path = "../librashader"
version = "0.2.2" version = "0.2.2"
default-features = false default-features = false
features = ["presets", "preprocess"] features = ["reflect", "presets", "preprocess"]
[target.'cfg(windows)'.dependencies.windows] [target.'cfg(windows)'.dependencies.windows]
version = "0.48.0" version = "0.48.0"