Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wasm32-unknown-unknown support #92

Merged
merged 16 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
members = [
"spirv_cross",
"examples",
"bindings_generator"
"bindings_generator",
"wasm"
]
2 changes: 1 addition & 1 deletion bindings_generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ bindgen = "0.30.0"

[[bin]]
name = "bindings_generator"
path = "src/main.rs"
path = "src/main.rs"
61 changes: 58 additions & 3 deletions bindings_generator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
extern crate bindgen;

use std::env;
use std::path::PathBuf;

fn main() {
let out_path = PathBuf::from(env::current_dir().unwrap());
let out_path = env::current_dir().unwrap();
// For native targets, include all types and functions
bindgen::Builder::default()
.header(
out_path
Expand All @@ -20,10 +20,65 @@ fn main() {
.whitelisted_type("spirv_cross::Resource")
.whitelisted_type("spirv_cross::MSLVertexAttr")
.whitelisted_type("spirv_cross::MSLResourceBinding")
// TODO: Simplify with glob
.whitelisted_type("ScInternalCompilerBase")
.whitelisted_type("ScInternalCompilerHlsl")
.whitelisted_type("ScInternalCompilerMsl")
.whitelisted_type("ScInternalCompilerGlsl")
.whitelisted_type("ScInternalResult")
.whitelisted_type("ScEntryPoint")
.whitelisted_type("ScCombinedImageSampler")
.whitelisted_type("ScHlslRootConstant")
.whitelisted_type("ScHlslCompilerOptions")
.whitelisted_type("ScMslCompilerOptions")
.whitelisted_type("ScGlslCompilerOptions")
.whitelisted_type("ScResource")
.whitelisted_type("ScResourceArray")
.whitelisted_type("ScShaderResources")
.whitelisted_type("ScSpecializationConstant")
.whitelisted_type("ScType")
.opaque_type("std::.*")
.layout_tests(false)
.generate()
.expect("Unable to generate bindings")
.write_to_file(out_path.join("../spirv_cross/src/bindings.rs"))
.write_to_file(out_path.join("../spirv_cross/src/bindings_native.rs"))
.expect("Couldn't write bindings!");
// For wasm targets, include all types, functions will be implemented manually
bindgen::Builder::default()
.header(
out_path
.join("../spirv_cross/src/wrapper.hpp")
.to_str()
.unwrap(),
)
.clang_args(["-x", "c++", "-std=c++14"].iter())
.enable_cxx_namespaces()
.whitelisted_type("spv::.*")
.bitfield_enum(".*(Mask|Flags)")
.whitelisted_type("spirv_cross::Resource")
.whitelisted_type("spirv_cross::MSLVertexAttr")
.whitelisted_type("spirv_cross::MSLResourceBinding")
// TODO: Simplify with glob
.whitelisted_type("ScInternalCompilerBase")
.whitelisted_type("ScInternalCompilerHlsl")
.whitelisted_type("ScInternalCompilerMsl")
.whitelisted_type("ScInternalCompilerGlsl")
.whitelisted_type("ScInternalResult")
.whitelisted_type("ScEntryPoint")
.whitelisted_type("ScCombinedImageSampler")
.whitelisted_type("ScHlslRootConstant")
.whitelisted_type("ScHlslCompilerOptions")
.whitelisted_type("ScMslCompilerOptions")
.whitelisted_type("ScGlslCompilerOptions")
.whitelisted_type("ScResource")
.whitelisted_type("ScResourceArray")
.whitelisted_type("ScShaderResources")
.whitelisted_type("ScSpecializationConstant")
.whitelisted_type("ScType")
.opaque_type("std::.*")
.layout_tests(false)
.generate()
.expect("Unable to generate bindings")
.write_to_file(out_path.join("../spirv_cross/src/bindings_wasm.rs"))
.expect("Couldn't write bindings!");
}
1 change: 1 addition & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "examples"
version = "0.1.0"
authors = ["Joshua Groves <[email protected]>"]
edition = "2018"

[dependencies]
spirv_cross = { path = "../spirv_cross" }
Expand Down
1 change: 1 addition & 0 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(clippy::cast_ptr_alignment)]
pub fn words_from_bytes(buf: &[u8]) -> &[u32] {
unsafe {
std::slice::from_raw_parts(
Expand Down
16 changes: 15 additions & 1 deletion spirv_cross/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ repository = "https://github.com/grovesNL/spirv_cross"
readme = "../README.md"
keywords = ["spirv", "cross"]
build = "build.rs"
edition = "2018"

[build-dependencies]
[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["glsl", "hlsl", "msl"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not have anything by default

glsl = []
hlsl = []
msl = []

[target.'cfg(not(target_arch = "wasm32"))'.build-dependencies]
cc = "1.0.4"

[target.wasm32-unknown-unknown.dependencies]
wasm-bindgen = "0.2.33"
js-sys = "0.3.10"
27 changes: 20 additions & 7 deletions spirv_cross/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
extern crate cc;

fn main() {
// Prevent building SPIRV-Cross on wasm32 target
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH");
if let Ok(arch) = target_arch {
if "wasm32" == arch {
return;
}
}

let target_os = std::env::var("CARGO_CFG_TARGET_OS");
let is_macos = target_os.is_ok() && target_os.unwrap() == "macos";

Expand All @@ -22,9 +28,16 @@ fn main() {
.file("src/vendor/SPIRV-Cross/spirv_cross.cpp")
.file("src/vendor/SPIRV-Cross/spirv_cross_parsed_ir.cpp")
.file("src/vendor/SPIRV-Cross/spirv_parser.cpp")
.file("src/vendor/SPIRV-Cross/spirv_cross_util.cpp")
.file("src/vendor/SPIRV-Cross/spirv_glsl.cpp")
.file("src/vendor/SPIRV-Cross/spirv_hlsl.cpp")
.file("src/vendor/SPIRV-Cross/spirv_msl.cpp")
.compile("spirv-cross-rust-wrapper");
.file("src/vendor/SPIRV-Cross/spirv_cross_util.cpp");

#[cfg(feature = "glsl")]
build.file("src/vendor/SPIRV-Cross/spirv_glsl.cpp");

#[cfg(feature = "hlsl")]
build.file("src/vendor/SPIRV-Cross/spirv_hlsl.cpp");

#[cfg(feature = "msl")]
build.file("src/vendor/SPIRV-Cross/spirv_msl.cpp");

build.compile("spirv-cross-rust-wrapper");
}
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,10 @@ pub mod root {
pub fn sc_internal_compiler_set_scalar_constant(compiler:
*const root::ScInternalCompilerBase,
id: u32,
constant: u64)
constant_high_bits:
u32,
constant_low_bits:
u32)
-> root::ScInternalResult;
}
extern "C" {
Expand Down
Loading