-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
101 lines (95 loc) · 3.8 KB
/
Copy pathbuild.rs
File metadata and controls
101 lines (95 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use std::env;
use std::path::PathBuf;
use std::process::Command;
fn sdk_path(sdk_name: &str) -> String {
let output = Command::new("xcrun")
.args(["--sdk", sdk_name, "--show-sdk-path"])
.output()
.expect("xcrun failed")
.stdout;
std::str::from_utf8(&output)
.expect("invalid output from `xcrun`")
.trim()
.to_owned()
}
fn main() {
println!("cargo:rerun-if-changed=ffi/webgpu-headers/webgpu.h");
println!("cargo:rerun-if-changed=ffi/wgpu.h");
println!("cargo:rerun-if-env-changed=TARGET");
println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS");
#[rustfmt::skip]
let types_to_rename = vec![
("WGPUAdapter", "WGPUAdapterImpl"),
("WGPUBindGroup", "WGPUBindGroupImpl"),
("WGPUBindGroupLayout", "WGPUBindGroupLayoutImpl"),
("WGPUBuffer", "WGPUBufferImpl"),
("WGPUCommandBuffer", "WGPUCommandBufferImpl"),
("WGPUCommandEncoder", "WGPUCommandEncoderImpl"),
("WGPUComputePassEncoder", "WGPUComputePassEncoderImpl"),
("WGPUComputePipeline", "WGPUComputePipelineImpl"),
("WGPUDevice", "WGPUDeviceImpl"),
("WGPUInstance", "WGPUInstanceImpl"),
("WGPUPipelineLayout", "WGPUPipelineLayoutImpl"),
("WGPUQuerySet", "WGPUQuerySetImpl"),
("WGPUQueue", "WGPUQueueImpl"),
("WGPURenderBundle", "WGPURenderBundleImpl"),
("WGPURenderBundleEncoder", "WGPURenderBundleEncoderImpl"),
("WGPURenderPassEncoder", "WGPURenderPassEncoderImpl"),
("WGPURenderPipeline", "WGPURenderPipelineImpl"),
("WGPUSampler", "WGPUSamplerImpl"),
("WGPUShaderModule", "WGPUShaderModuleImpl"),
("WGPUSurface", "WGPUSurfaceImpl"),
("WGPUTexture", "WGPUTextureImpl"),
("WGPUTextureView", "WGPUTextureViewImpl"),
];
let mut builder = bindgen::Builder::default()
.header("ffi/wgpu.h")
.clang_arg("-Iffi/webgpu-headers")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.allowlist_item("WGPU.*")
.allowlist_item("wgpu.*")
.blocklist_function("wgpuGetProcAddress")
.prepend_enum_name(false)
.size_t_is_usize(true)
.ignore_functions()
.layout_tests(true)
.clang_macro_fallback();
for (old_name, new_name) in types_to_rename {
let line = format!("pub type {old_name} = *const crate::{new_name};");
builder = builder
.blocklist_type(old_name)
.blocklist_type(format!("{old_name}Impl"))
.raw_line(line);
}
if let Ok(target) = env::var("TARGET") {
match target.as_str() {
"aarch64-apple-ios" => {
builder = builder
.clang_arg("-isysroot")
.clang_arg(sdk_path("iphoneos"))
.clang_arg("--target=arm64-apple-ios");
}
"aarch64-apple-ios-sim" => {
builder = builder
.clang_arg("-isysroot")
.clang_arg(sdk_path("iphonesimulator"))
.clang_arg("--target=arm64-apple-ios-simulator");
}
"x86_64-apple-ios" => {
builder = builder
.clang_arg("-isysroot")
.clang_arg(sdk_path("iphonesimulator"))
.clang_arg("--target=x86_64-apple-ios-simulator");
}
"aarch64-apple-darwin" | "x86_64-apple-darwin" => {
builder = builder.clang_arg("-isysroot").clang_arg(sdk_path("macosx"));
}
_ => {}
}
}
let bindings = builder.generate().expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}