build: allow building stable with --stable flag

This commit is contained in:
chyyran 2024-09-15 02:15:01 -04:00 committed by Ronny Chan
parent e930f90a9c
commit 316e92dc09
2 changed files with 28 additions and 18 deletions

View file

@ -18,7 +18,7 @@ Windows and macOS users can grab the latest binaries from [GitHub Releases](http
librashader supports all modern graphics runtimes, including wgpu, Vulkan, OpenGL 3.3+ and 4.6 (with DSA), librashader supports all modern graphics runtimes, including wgpu, Vulkan, OpenGL 3.3+ and 4.6 (with DSA),
Direct3D 11, Direct3D 12, and Metal. Direct3D 11, Direct3D 12, and Metal.
librashader does not support legacy render APIs such as older versions of OpenGL or Direct3D, except for experimental librashader does not support legacy render APIs such as older versions of OpenGL or Direct3D, except for limited
support for Direct3D 9. support for Direct3D 9.
| **API** | **Status** | **`librashader` feature** | | **API** | **Status** | **`librashader` feature** |

View file

@ -12,6 +12,8 @@ struct Args {
profile: String, profile: String,
#[arg(long, global = true)] #[arg(long, global = true)]
target: Option<String>, target: Option<String>,
#[arg(long, default_value_t = false, global = true)]
stable: bool,
#[arg(last = true)] #[arg(last = true)]
cargoflags: Vec<String>, cargoflags: Vec<String>,
} }
@ -27,7 +29,7 @@ pub fn main() -> ExitCode {
let profile = args.profile; let profile = args.profile;
let crate_dir = Path::new("librashader-capi"); let crate_dir = Path::new("librashader-capi");
println!("Building librashader C API..."); println!("INFO: Building librashader C API...");
let mut cmd = Command::new("cargo"); let mut cmd = Command::new("cargo");
cmd.arg("build"); cmd.arg("build");
@ -46,6 +48,10 @@ pub fn main() -> ExitCode {
cmd.arg(format!("--target={}", &target)); cmd.arg(format!("--target={}", &target));
} }
if args.stable {
println!("WARN: Building librashader with stable Rust compatibility. C headers will not be generated.");
cmd.args(["--features", "stable"]);
}
if !args.cargoflags.is_empty() { if !args.cargoflags.is_empty() {
cmd.args(args.cargoflags); cmd.args(args.cargoflags);
} }
@ -64,22 +70,26 @@ pub fn main() -> ExitCode {
.canonicalize() .canonicalize()
.expect("Could not find output directory."); .expect("Could not find output directory.");
println!("Generating C headers..."); if args.stable {
println!("WARN: C header generation is not supported when building for stable Rust.");
} else {
println!("INFO: Generating C headers...");
// Create headers. // Create headers.
let mut buf = BufWriter::new(Vec::new()); let mut buf = BufWriter::new(Vec::new());
cbindgen::generate(crate_dir) cbindgen::generate(crate_dir)
.expect("Unable to generate bindings") .expect("Unable to generate bindings")
.write(&mut buf); .write(&mut buf);
let bytes = buf.into_inner().expect("Unable to extract bytes"); let bytes = buf.into_inner().expect("Unable to extract bytes");
let string = String::from_utf8(bytes).expect("Unable to create string"); let string = String::from_utf8(bytes).expect("Unable to create string");
File::create(output_dir.join("librashader.h")) File::create(output_dir.join("librashader.h"))
.expect("Unable to open file") .expect("Unable to open file")
.write_all(string.as_bytes()) .write_all(string.as_bytes())
.expect("Unable to write bindings."); .expect("Unable to write bindings.");
}
println!("Moving artifacts..."); println!("INFO: Moving artifacts...");
if cfg!(target_os = "macos") { if cfg!(target_os = "macos") {
let artifacts = &["liblibrashader_capi.dylib", "liblibrashader_capi.a"]; let artifacts = &["liblibrashader_capi.dylib", "liblibrashader_capi.a"];
for artifact in artifacts { for artifact in artifacts {
@ -106,12 +116,12 @@ pub fn main() -> ExitCode {
]; ];
for artifact in artifacts { for artifact in artifacts {
let ext = artifact.replace("_capi", ""); let ext = artifact.replace("_capi", "");
println!("Renaming {artifact} to {ext}"); println!("INFO: Renaming {artifact} to {ext}");
fs::rename(output_dir.join(artifact), output_dir.join(ext)).unwrap(); fs::rename(output_dir.join(artifact), output_dir.join(ext)).unwrap();
} }
if output_dir.join("librashader_capi.pdb").exists() { if output_dir.join("librashader_capi.pdb").exists() {
println!("Renaming librashader_capi.pdb to librashader.pdb"); println!("INFO: Renaming librashader_capi.pdb to librashader.pdb");
fs::rename( fs::rename(
output_dir.join("librashader_capi.pdb"), output_dir.join("librashader_capi.pdb"),
output_dir.join("librashader.pdb"), output_dir.join("librashader.pdb"),
@ -120,5 +130,5 @@ pub fn main() -> ExitCode {
} }
} }
return ExitCode::SUCCESS; ExitCode::SUCCESS
} }