gpui: make build dependencies mac only
This removes bindgen and cbindgen from the dependency graph on non-macos systems, improving compile times on those systems. Signed-off-by: Niklas Wimmer <mail@nwimmer.me>
This commit is contained in:
parent
50ab60b9f0
commit
97f1d61a4a
2 changed files with 183 additions and 172 deletions
|
@ -78,7 +78,7 @@ backtrace = "0.3"
|
||||||
collections = { workspace = true, features = ["test-support"] }
|
collections = { workspace = true, features = ["test-support"] }
|
||||||
util = { workspace = true, features = ["test-support"] }
|
util = { workspace = true, features = ["test-support"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[target.'cfg(target_os = "macos")'.build-dependencies]
|
||||||
bindgen = "0.65.1"
|
bindgen = "0.65.1"
|
||||||
cbindgen = "0.26.0"
|
cbindgen = "0.26.0"
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
#![cfg_attr(any(not(target_os = "macos"), feature = "macos-blade"), allow(unused))]
|
#![cfg_attr(any(not(target_os = "macos"), feature = "macos-blade"), allow(unused))]
|
||||||
|
|
||||||
|
//TODO: consider generating shader code for WGSL
|
||||||
|
//TODO: deprecate "runtime-shaders" and "macos-blade"
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
macos::build();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
mod macos {
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
@ -7,21 +17,18 @@ use std::{
|
||||||
|
|
||||||
use cbindgen::Config;
|
use cbindgen::Config;
|
||||||
|
|
||||||
//TODO: consider generating shader code for WGSL
|
pub(super) fn build() {
|
||||||
//TODO: deprecate "runtime-shaders" and "macos-blade"
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
generate_dispatch_bindings();
|
generate_dispatch_bindings();
|
||||||
#[cfg(all(target_os = "macos", not(feature = "macos-blade")))]
|
#[cfg(not(feature = "macos-blade"))]
|
||||||
|
{
|
||||||
let header_path = generate_shader_bindings();
|
let header_path = generate_shader_bindings();
|
||||||
#[cfg(all(target_os = "macos", not(feature = "macos-blade")))]
|
|
||||||
#[cfg(feature = "runtime_shaders")]
|
#[cfg(feature = "runtime_shaders")]
|
||||||
emit_stitched_shaders(&header_path);
|
emit_stitched_shaders(&header_path);
|
||||||
#[cfg(all(target_os = "macos", not(feature = "macos-blade")))]
|
|
||||||
#[cfg(not(feature = "runtime_shaders"))]
|
#[cfg(not(feature = "runtime_shaders"))]
|
||||||
compile_metal_shaders(&header_path);
|
compile_metal_shaders(&header_path);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn generate_dispatch_bindings() {
|
fn generate_dispatch_bindings() {
|
||||||
println!("cargo:rustc-link-lib=framework=System");
|
println!("cargo:rustc-link-lib=framework=System");
|
||||||
|
@ -125,7 +132,8 @@ fn emit_stitched_shaders(header_path: &Path) {
|
||||||
let header_contents = std::fs::read_to_string(header)?;
|
let header_contents = std::fs::read_to_string(header)?;
|
||||||
let shader_contents = std::fs::read_to_string(shader_path)?;
|
let shader_contents = std::fs::read_to_string(shader_path)?;
|
||||||
let stitched_contents = format!("{header_contents}\n{shader_contents}");
|
let stitched_contents = format!("{header_contents}\n{shader_contents}");
|
||||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("stitched_shaders.metal");
|
let out_path =
|
||||||
|
PathBuf::from(env::var("OUT_DIR").unwrap()).join("stitched_shaders.metal");
|
||||||
std::fs::write(&out_path, stitched_contents)?;
|
std::fs::write(&out_path, stitched_contents)?;
|
||||||
Ok(out_path)
|
Ok(out_path)
|
||||||
}
|
}
|
||||||
|
@ -134,12 +142,14 @@ fn emit_stitched_shaders(header_path: &Path) {
|
||||||
stitch_header(header_path, &shader_path).unwrap();
|
stitch_header(header_path, &shader_path).unwrap();
|
||||||
println!("cargo:rerun-if-changed={}", &shader_source_path);
|
println!("cargo:rerun-if-changed={}", &shader_source_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "runtime_shaders"))]
|
#[cfg(not(feature = "runtime_shaders"))]
|
||||||
fn compile_metal_shaders(header_path: &Path) {
|
fn compile_metal_shaders(header_path: &Path) {
|
||||||
use std::process::{self, Command};
|
use std::process::{self, Command};
|
||||||
let shader_path = "./src/platform/mac/shaders.metal";
|
let shader_path = "./src/platform/mac/shaders.metal";
|
||||||
let air_output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.air");
|
let air_output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.air");
|
||||||
let metallib_output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.metallib");
|
let metallib_output_path =
|
||||||
|
PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.metallib");
|
||||||
println!("cargo:rerun-if-changed={}", shader_path);
|
println!("cargo:rerun-if-changed={}", shader_path);
|
||||||
|
|
||||||
let output = Command::new("xcrun")
|
let output = Command::new("xcrun")
|
||||||
|
@ -184,3 +194,4 @@ fn compile_metal_shaders(header_path: &Path) {
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue