Giter Club home page Giter Club logo

spirv_cross's Introduction

spirv_cross

Safe wrapper around SPIR-V Cross

Crate Travis Build Status Appveyor Build Status

Example

spirv_cross provides a safe wrapper around SPIRV-Cross for use with Rust. For example, here is a simple function to parse a SPIR-V module and compile it to HLSL and MSL:

extern crate spirv_cross;
use spirv_cross::{spirv, hlsl, msl, ErrorCode};

fn example(module: spirv::Module) -> Result<(), ErrorCode> {
    // Compile to HLSL
    let ast = spirv::Ast::<hlsl::Target>::parse(&module)?;
    println!("{}", ast.compile()?);

    // Compile to MSL
    let ast = spirv::Ast::<msl::Target>::parse(&module)?;
    println!("{}", ast.compile()?);

    Ok(())
}

License

This project is licensed under either of Apache License, Version 2.0 or MIT license, at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache 2.0 license, shall be dual licensed as above, without any additional terms or conditions.

See CONTRIBUTING.md.

spirv_cross's People

Contributors

aclysma avatar aleksijuvani avatar bootra-dev avatar bors[bot] avatar cheako avatar glalonde avatar goddessfreya avatar grovesnl avatar jonil avatar jorundev avatar kvark avatar metaphorshear avatar msiglreith avatar mtak- avatar pollend avatar rob2309 avatar sir-earl avatar spacemaniac avatar tangmi avatar underdiskdev avatar versusvoid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spirv_cross's Issues

Migrate to GitHub Actions

In #170 bors failed to merge the PR because I ran out of credits on the new Travis CI plans. Let's remove Travis and AppVeyor and switch to GitHub Actions for everything.

Fails to build on Linux with Clang

In file included from src/wrapper.cpp:1:
In file included from src/vendor/SPIRV-Cross/spirv_hlsl.hpp:20:
In file included from src/vendor/SPIRV-Cross/spirv_glsl.hpp:20:
In file included from src/vendor/SPIRV-Cross/spirv_cross.hpp:21:
src/vendor/SPIRV-Cross/spirv_common.hpp:22:10: fatal error: 'cstdio' file not found
#include <cstdio>
               ^~~~~~~~
1 error generated.

The problem seems to be that the build.rs file enables libc++ automatically with Clang, even if it isn't installed.

I am using the latest Clang, but still want to build with the normal GNU libstdc++. Is there any specific reason for using cpp_set_stdlib("c++")? Right now using G++ works around this problem.

Update bindgen

Bindgen has changed quite a bit since the version being used in the generated bindings (0.30). We should update to the newest and adjust the bindings internally. Fortunately the changes shouldn't be too large – mostly renaming enum variants and similar.

Release updated version to crates.io

It looks like there is some new functionality to emulate atomic ops on textures/images in MSL. Currently this wgpu functionality works well on Vulkan, but doesn't run at all on MacOS.

Running examples from `master` fails

Cloning master and running examples currently fails with:

src/wrapper.cpp(4): fatal error C1083: Cannot open include file: 'vendor/SPIRV-Cross/spirv_cross_util.hpp': No such file or directory

This issue was probably introduced while minimizing the amount vendored files – I will look into it

More exception crazyness

https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=271957975&repo=try&lineNumber=22063

In file included from src/vendor/SPIRV-Cross/spirv_cross_util.hpp:20:
In file included from src/vendor/SPIRV-Cross/spirv_cross.hpp:21:
In file included from src/vendor/SPIRV-Cross/spirv_cfg.hpp:20:
In file included from src/vendor/SPIRV-Cross/spirv_common.hpp:21:
In file included from src/vendor/SPIRV-Cross/spirv_cross_containers.hpp:20:
In file included from src/vendor/SPIRV-Cross/spirv_cross_error_handling.hpp:20:
In file included from z:\build\build\src\vs2017_15.8.4\VC\include\stdexcept:6:
In file included from z:\build\build\src\vs2017_15.8.4\VC\include\exception:8:
z:/build/build/src/obj-firefox/dist/stl_wrappers\type_traits(74,6): error: "STL code can only be used with infallible ::operator new()"

Can't statically link on Windows when building for debug

Hello, I'm trying to put together an application that uses both C++ and rust. What I've done is create a static lib in rust that I then link into a C++ executable.

The problem I'm running into is that appears that spirv-cross is being built for Release on Windows no matter what. I've put together a small repro with build instructions here if you're interested.

This only reproduces when building in Debug mode on Windows. In Release mode it seems to work fine, and other platforms (Linux and macOS) seem to be fine in either Debug or Release modes.

Here's the linker error that I run into:

rust_lib.lib(wrapper.o) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.cpp.obj
rust_lib.lib(wrapper.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.cpp.obj
rust_lib.lib(spirv_cross.o) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.cpp.obj
rust_lib.lib(spirv_cross.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.cpp.obj
rust_lib.lib(spirv_cross_util.o) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.cpp.obj
rust_lib.lib(spirv_cross_util.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.cpp.obj
rust_lib.lib(spirv_glsl.o) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.cpp.obj
rust_lib.lib(spirv_glsl.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.cpp.obj
rust_lib.lib(spirv_hlsl.o) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.cpp.obj
rust_lib.lib(spirv_hlsl.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.cpp.obj
rust_lib.lib(spirv_msl.o) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.cpp.obj
rust_lib.lib(spirv_msl.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.cpp.obj
rust_lib.lib(spirv_cfg.o) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.cpp.obj
rust_lib.lib(spirv_cfg.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.cpp.obj
rust_lib.lib(spirv_cross_parsed_ir.o) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.cpp.obj
rust_lib.lib(spirv_cross_parsed_ir.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.cpp.obj
rust_lib.lib(spirv_parser.o) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.cpp.obj
rust_lib.lib(spirv_parser.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.cpp.obj
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
cpp-exe\cpp-exe.exe : fatal error LNK1319: 18 mismatches detected
ninja: build stopped: subcommand failed.

I'm a bit new to using Rust in this way, but is there a way to configure the build? As you can see in the repro, I'm not consuming spirv-cross directly, but instead consuming it through wpgu.

I'd be willing to submit a PR if required. I just need to know what direction to look in/what to look for.

Thanks for your project!

Update SPIRV-Cross submodule

The latest master contains changes for generating spaceN attributes for HLSL resources. Therefore, we don't need to diverge and can just use upstream (at least for now!)

Unable to build on MacOS

So I am trying to fork this library in order to add the functionality to be able to list types via the reflection API. As far as I can tell, it's only possible to query a type given the id, but if there's already a way to get all the type id's, that would already solve my problem.

But if that is not the case, I am running into an issue building this library locally.

I have cloned the repo to my workstation, and I am trying to build with cargo:

cargo build

And I get the following error:

The following warnings were emitted during compilation:

warning: clang: error: no such file or directory: 'src/vendor/SPIRV-Cross/spirv_cfg.cpp'
warning: clang: error: no input files
warning: clang: error: no such file or directory: 'src/vendor/SPIRV-Cross/spirv_cross.cpp'
warning: clang: error: no input files
warning: clang: error: no such file or directory: 'src/vendor/SPIRV-Cross/spirv_cross_parsed_ir.cpp'
warning: clang: error: no input files
warning: src/wrapper.cpp:4:10: fatal error: 'vendor/SPIRV-Cross/spirv_cross_util.hpp' file not found
warning: #include "vendor/SPIRV-Cross/spirv_cross_util.hpp"
warning:          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: 1 error generated.
warning: clang: error: no such file or directory: 'src/vendor/SPIRV-Cross/spirv_parser.cpp'
warning: clang: error: no input files

error: failed to run custom build command for `spirv_cross v0.23.1 (/Users/spencerkohan/projects/rust/vulkan_dsl/spirv_cross/spirv_cross)`

Caused by:
  process didn't exit successfully: `/Users/spencerkohan/projects/rust/vulkan_dsl/spirv_cross/target/debug/build/spirv_cross-4fa09f7a5a708f06/build-script-build` (exit status: 1)
  --- stdout
  OPT_LEVEL = Some("0")
  TARGET = Some("aarch64-apple-darwin")
  HOST = Some("aarch64-apple-darwin")
  CXX_aarch64-apple-darwin = None
  CXX_aarch64_apple_darwin = None
  HOST_CXX = None
  CXX = None
  CXXFLAGS_aarch64-apple-darwin = None
  CXXFLAGS_aarch64_apple_darwin = None
  HOST_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,llvm14-builtins-abi,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,v8.1a,v8.2a,v8.3a,v8.4a,vh")
  CXX_aarch64-apple-darwin = None
  CXX_aarch64_apple_darwin = None
  HOST_CXX = None
  CXX = None
  CXXFLAGS_aarch64-apple-darwin = None
  CXXFLAGS_aarch64_apple_darwin = None
  HOST_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some("aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,llvm14-builtins-abi,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,v8.1a,v8.2a,v8.3a,v8.4a,vh")
  running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-arch" "arm64" "-Wall" "-Wextra" "-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS" "-DSPIRV_CROSS_WRAPPER_NO_EXCEPTIONS" "-DSPIRV_CROSS_WRAPPER_GLSL" "-DSPIRV_CROSS_WRAPPER_HLSL" "-DSPIRV_CROSS_WRAPPER_MSL" "-std=c++14" "-o" "/Users/spencerkohan/projects/rust/vulkan_dsl/spirv_cross/target/debug/build/spirv_cross-d81183c040bf4aa5/out/src/vendor/SPIRV-Cross/spirv_cross_parsed_ir.o" "-c" "src/vendor/SPIRV-Cross/spirv_cross_parsed_ir.cpp"
  running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-arch" "arm64" "-Wall" "-Wextra" "-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS" "-DSPIRV_CROSS_WRAPPER_NO_EXCEPTIONS" "-DSPIRV_CROSS_WRAPPER_GLSL" "-DSPIRV_CROSS_WRAPPER_HLSL" "-DSPIRV_CROSS_WRAPPER_MSL" "-std=c++14" "-o" "/Users/spencerkohan/projects/rust/vulkan_dsl/spirv_cross/target/debug/build/spirv_cross-d81183c040bf4aa5/out/src/vendor/SPIRV-Cross/spirv_cross.o" "-c" "src/vendor/SPIRV-Cross/spirv_cross.cpp"
  running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-arch" "arm64" "-Wall" "-Wextra" "-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS" "-DSPIRV_CROSS_WRAPPER_NO_EXCEPTIONS" "-DSPIRV_CROSS_WRAPPER_GLSL" "-DSPIRV_CROSS_WRAPPER_HLSL" "-DSPIRV_CROSS_WRAPPER_MSL" "-std=c++14" "-o" "/Users/spencerkohan/projects/rust/vulkan_dsl/spirv_cross/target/debug/build/spirv_cross-d81183c040bf4aa5/out/src/wrapper.o" "-c" "src/wrapper.cpp"
  running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-arch" "arm64" "-Wall" "-Wextra" "-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS" "-DSPIRV_CROSS_WRAPPER_NO_EXCEPTIONS" "-DSPIRV_CROSS_WRAPPER_GLSL" "-DSPIRV_CROSS_WRAPPER_HLSL" "-DSPIRV_CROSS_WRAPPER_MSL" "-std=c++14" "-o" "/Users/spencerkohan/projects/rust/vulkan_dsl/spirv_cross/target/debug/build/spirv_cross-d81183c040bf4aa5/out/src/vendor/SPIRV-Cross/spirv_cfg.o" "-c" "src/vendor/SPIRV-Cross/spirv_cfg.cpp"
  cargo:warning=clang: error: no such file or directory: 'src/vendor/SPIRV-Cross/spirv_cfg.cpp'
  cargo:warning=clang: error: no input files
  exit status: 1
  running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-arch" "arm64" "-Wall" "-Wextra" "-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS" "-DSPIRV_CROSS_WRAPPER_NO_EXCEPTIONS" "-DSPIRV_CROSS_WRAPPER_GLSL" "-DSPIRV_CROSS_WRAPPER_HLSL" "-DSPIRV_CROSS_WRAPPER_MSL" "-std=c++14" "-o" "/Users/spencerkohan/projects/rust/vulkan_dsl/spirv_cross/target/debug/build/spirv_cross-d81183c040bf4aa5/out/src/vendor/SPIRV-Cross/spirv_parser.o" "-c" "src/vendor/SPIRV-Cross/spirv_parser.cpp"
  cargo:warning=clang: error: no such file or directory: 'src/vendor/SPIRV-Cross/spirv_cross.cpp'
  cargo:warning=clang: error: no input files
  exit status: 1
  cargo:warning=clang: error: no such file or directory: 'src/vendor/SPIRV-Cross/spirv_cross_parsed_ir.cpp'
  cargo:warning=clang: error: no input files
  cargo:warning=src/wrapper.cpp:4:10: fatal error: 'vendor/SPIRV-Cross/spirv_cross_util.hpp' file not found
  cargo:warning=#include "vendor/SPIRV-Cross/spirv_cross_util.hpp"
  cargo:warning=         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  exit status: 1
  cargo:warning=1 error generated.
  exit status: 1
  cargo:warning=clang: error: no such file or directory: 'src/vendor/SPIRV-Cross/spirv_parser.cpp'
  cargo:warning=clang: error: no input files
  exit status: 1

  --- stderr


  error occurred: Command "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-arch" "arm64" "-Wall" "-Wextra" "-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS" "-DSPIRV_CROSS_WRAPPER_NO_EXCEPTIONS" "-DSPIRV_CROSS_WRAPPER_GLSL" "-DSPIRV_CROSS_WRAPPER_HLSL" "-DSPIRV_CROSS_WRAPPER_MSL" "-std=c++14" "-o" "/Users/spencerkohan/projects/rust/vulkan_dsl/spirv_cross/target/debug/build/spirv_cross-d81183c040bf4aa5/out/src/wrapper.o" "-c" "src/wrapper.cpp" with args "c++" did not execute successfully (status code exit status: 1).

So it looks like it's having trouble finding a header from the spire-cross cpp implementation.

Is there a step I am missing to make this work? I have the Vulkan SDK installed locally. Also this library works fine if I include it as a cargo dependency.

stage_inputs format

Just wondering how to get the stride of a vertex input so I can create my buffer descriptor correctly. Calling get_type(input.type_id) on layout(location = 0) in vec4 a_Pos; appears to return a Float { array: [] }. There doesn't seem to be any way to get the actual vecsize which I was expecting. Am I missing something here?

Expose `{get,set}_common_options`

I encountered an issue in wgpu where a given shader causes the generation of hlsl shader with an uninitialized variable. DXCompiler is very unhappy with this. spirv-cross cli has an option --force-zero-initialized-variables which will fix this problem. As such, we would like gfx-hal to always have this option on.

This seems to be exposed via the {get,set}_common_option which is not yet exposed by this crate (see https://github.com/KhronosGroup/SPIRV-Cross/blob/master/main.cpp#L1121-L1140 for how the cli sets the option). I'm not sure how exactly that would manifest for this crate, but getting access to those options would be very useful in general.

Minimize the vendored code

I'm trying to vendor spirv_cross, and there appear to be a lot of seemingly unneeded files in the repo, e.g. everything in reference folder.

We need to make it a smaller dependency in terms of code... Another alternative we are considering is only shipping the Vulkan backend until the Javelin project is mature enough, but that's very risky.

Target std=gnu++14 rather than std=c++14 on Windows systems

The spirv_cross build.rs sets the c++ compiler to use the c++14 standard. On POSIX systems this is fine, because those systems will simply implicitly include the POSIX standard as well. This is not the case on Windows while using GCC, however - it uses the strict c++14 standard. This does not include some key functions used by spirv_cross, namely strdup. Attempting to build a crate with spirv-cross as a dependency on x64 Windows 10 with GCC 9.10 results in the following laundry list of errors:

error: failed to run custom build command for `spirv_cross v0.14.2`
process didn't exit successfully: `C:\Users\sera4-1\Desktop\git\roguelike-rs-proto\target\debug\build\spirv_cross-ca6a20db42e8191e\build-script-build` (exit code: 1)
--- stdout
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-pc-windows-msvc")
HOST = Some("x86_64-pc-windows-msvc")
CXX_x86_64-pc-windows-msvc = None
CXX_x86_64_pc_windows_msvc = None
HOST_CXX = None
CXX = Some("g++")
CXXFLAGS_x86_64-pc-windows-msvc = None
CXXFLAGS_x86_64_pc_windows_msvc = None
HOST_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
CXX_x86_64-pc-windows-msvc = None
CXX_x86_64_pc_windows_msvc = None
HOST_CXX = None
CXX = Some("g++")
CXXFLAGS_x86_64-pc-windows-msvc = None
CXXFLAGS_x86_64_pc_windows_msvc = None
HOST_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
running: "g++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-DSPIRV_CROSS_WRAPPER_GLSL" "-DSPIRV_CROSS_WRAPPER_HLSL" "-std=c++14" "-FoC:\\Users\\sera4-1\\Desktop\\git\\roguelike-rs-proto\\target\\debug\\build\\spirv_cross-a26c25184055b81e\\out\\src\\wrapper.o" "-c" "src/wrapper.cpp"
cargo:warning=src/wrapper.cpp:2: warning: ignoring #pragma warning  [-Wunknown-pragmas]
cargo:warning=    2 | #pragma warning(disable : 4996 4101)
cargo:warning=      |
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_get_latest_exception_message(const char**)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:53:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=   53 |         INTERNAL_RESULT(*message = latest_exception_message;)
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_hlsl_new(ScInternalCompilerHlsl**, const uint32_t*, size_t)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:59:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=   59 |         INTERNAL_RESULT(*compiler = new spirv_cross::CompilerHLSL(ir, size);)
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_hlsl_set_options(const ScInternalCompilerHlsl*, const ScHlslCompilerOptions*)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:64:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=   64 |         INTERNAL_RESULT(
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_hlsl_set_root_constant_layout(const ScInternalCompilerHlsl*, const ScHlslRootConstant*, size_t)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:84:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=   84 |         INTERNAL_RESULT(
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_glsl_new(ScInternalCompilerGlsl**, const uint32_t*, size_t)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:171:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  171 |         INTERNAL_RESULT(*compiler = new spirv_cross::CompilerGLSL(ir, size);)
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_glsl_set_options(const ScInternalCompilerGlsl*, const ScGlslCompilerOptions*)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:176:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  176 |         INTERNAL_RESULT(
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_glsl_build_combined_image_samplers(const ScInternalCompilerBase*)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:190:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  190 |         INTERNAL_RESULT(
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_glsl_get_combined_image_samplers(const ScInternalCompilerBase*, const ScCombinedImageSampler**, size_t*)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:198:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  198 |         INTERNAL_RESULT(
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_get_decoration(const ScInternalCompilerBase*, uint32_t*, uint32_t, spv::Decoration)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:209:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  209 |         INTERNAL_RESULT(*result = ((spirv_cross::Compiler *)compiler)->get_decoration(id, decoration);)
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_unset_decoration(const ScInternalCompilerBase*, uint32_t, spv::Decoration)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:214:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  214 |         INTERNAL_RESULT(((spirv_cross::Compiler *)compiler)->unset_decoration(id, decoration);)
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_set_decoration(const ScInternalCompilerBase*, uint32_t, spv::Decoration, uint32_t)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:219:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  219 |         INTERNAL_RESULT(((spirv_cross::Compiler *)compiler)->set_decoration(id, decoration, argument);)
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_set_name(const ScInternalCompilerBase*, uint32_t, const char*)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:224:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  224 |         INTERNAL_RESULT(((spirv_cross::Compiler *)compiler)->set_name(id, std::string(name));)
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_get_entry_points(const ScInternalCompilerBase*, ScEntryPoint**, size_t*)':
cargo:warning=src/wrapper.cpp:246:45: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=  246 |                     entry_points[i]->name = strdup(sc_entry_point.name.c_str());
cargo:warning=      |                                             ^~~~~~
cargo:warning=src/wrapper.cpp:28:17: note: in definition of macro 'INTERNAL_RESULT'
cargo:warning=   28 |                 block_to_attempt                          \
cargo:warning=      |                 ^~~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:229:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  229 |         INTERNAL_RESULT(
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_get_cleansed_entry_point_name(const ScInternalCompilerBase*, const char*, spv::ExecutionModel, const char**)':
cargo:warning=src/wrapper.cpp:259:46: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=  259 |                 *compiled_entry_point_name = strdup(
cargo:warning=      |                                              ^~~~~~
cargo:warning=src/wrapper.cpp:28:17: note: in definition of macro 'INTERNAL_RESULT'
cargo:warning=   28 |                 block_to_attempt                          \
cargo:warning=      |                 ^~~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:257:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  257 |         INTERNAL_RESULT(
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'void fill_resource_array(ScResourceArray*, const spirv_cross::SmallVector<spirv_cross::Resource>&)':
cargo:warning=src/wrapper.cpp:285:39: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=  285 |             resources->data[i].name = strdup(resource.name.c_str());
cargo:warning=      |                                       ^~~~~~
cargo:warning=      |                                       strcmp
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_get_shader_resources(const ScInternalCompilerBase*, ScShaderResources*)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:291:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  291 |         INTERNAL_RESULT(
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_get_specialization_constants(const ScInternalCompilerBase*, ScSpecializationConstant**, size_t*)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:311:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  311 |         INTERNAL_RESULT(
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_set_scalar_constant(const ScInternalCompilerBase*, uint32_t, uint32_t, uint32_t)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:330:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  330 |         INTERNAL_RESULT(
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_get_type(const ScInternalCompilerBase*, uint32_t, const ScType**)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:339:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  339 |         INTERNAL_RESULT(
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_get_member_name(const ScInternalCompilerBase*, uint32_t, uint32_t, const char**)':
cargo:warning=src/wrapper.cpp:383:25: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=  383 |                 *name = strdup(member_name.c_str());
cargo:warning=      |                         ^~~~~~
cargo:warning=src/wrapper.cpp:28:17: note: in definition of macro 'INTERNAL_RESULT'
cargo:warning=   28 |                 block_to_attempt                          \
cargo:warning=      |                 ^~~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:380:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  380 |         INTERNAL_RESULT(
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_get_member_decoration(const ScInternalCompilerBase*, uint32_t, uint32_t, spv::Decoration, uint32_t*)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:389:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  389 |         INTERNAL_RESULT(*result = ((spirv_cross::Compiler *)compiler)->get_member_decoration(id, index, decoration);)
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_set_member_decoration(const ScInternalCompilerBase*, uint32_t, uint32_t, spv::Decoration, uint32_t)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:394:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  394 |         INTERNAL_RESULT(((spirv_cross::Compiler *)compiler)->set_member_decoration(id, index, decoration, argument);)
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_get_declared_struct_size(const ScInternalCompilerBase*, uint32_t, uint32_t*)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:399:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  399 |         INTERNAL_RESULT(do {
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_get_declared_struct_member_size(const ScInternalCompilerBase*, uint32_t, uint32_t, uint32_t*)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:407:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  407 |         INTERNAL_RESULT(do {
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_rename_interface_variable(const ScInternalCompilerBase*, const ScResource*, size_t, uint32_t, const char*)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:415:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  415 |         INTERNAL_RESULT(do {
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_get_work_group_size_specialization_constants(const ScInternalCompilerBase*, ScSpecializationConstant**)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:437:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  437 |         INTERNAL_RESULT(do {
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_compile(const ScInternalCompilerBase*, const char**)':
cargo:warning=src/wrapper.cpp:457:35: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=  457 |         INTERNAL_RESULT(*shader = strdup(((spirv_cross::Compiler *)compiler)->compile().c_str());)
cargo:warning=      |                                   ^~~~~~
cargo:warning=src/wrapper.cpp:28:17: note: in definition of macro 'INTERNAL_RESULT'
cargo:warning=   28 |                 block_to_attempt                          \
cargo:warning=      |                 ^~~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:457:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  457 |         INTERNAL_RESULT(*shader = strdup(((spirv_cross::Compiler *)compiler)->compile().c_str());)
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_compiler_delete(ScInternalCompilerBase*)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:462:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  462 |         INTERNAL_RESULT(delete (spirv_cross::Compiler *)compiler;)
cargo:warning=      |         ^~~~~~~~~~~~~~~
cargo:warning=src/wrapper.cpp: In function 'ScInternalResult sc_internal_free_pointer(void*)':
cargo:warning=src/wrapper.cpp:34:40: error: 'strdup' was not declared in this scope; did you mean 'strcmp'?
cargo:warning=   34 |             latest_exception_message = strdup(ex.what()); \
cargo:warning=      |                                        ^~~~~~
cargo:warning=src/wrapper.cpp:467:9: note: in expansion of macro 'INTERNAL_RESULT'
cargo:warning=  467 |         INTERNAL_RESULT(free(pointer);)
cargo:warning=      |         ^~~~~~~~~~~~~~~
exit code: 1

--- stderr

error occurred: Command "g++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-DSPIRV_CROSS_WRAPPER_GLSL" "-DSPIRV_CROSS_WRAPPER_HLSL" "-std=c++14" "-FoC:\\Users\\sera4-1\\Desktop\\git\\roguelike-rs-proto\\target\\debug\\build\\spirv_cross-a26c25184055b81e\\out\\src\\wrapper.o" "-c" "src/wrapper.cpp" with args "g++" did not execute successfully (status code exit code: 1).

warning: build failed, waiting for other jobs to finish..

I do not have time at the moment to test, but I believe this can be fixed by telling the compiler to use std=gnu++11. This will include the relevant POSIX standard headers to enable strdup and friends to compile correctly. I will test this when I have time and respond back in this issue if I test a solution that works.

Yank v0.1.9

v0.1.9 has different API from v0.1.8 (e.g. no spirv::Parser). It's also lacking hlsl::Compiler.
Breaking versions should bump the minor number (while 0 is the major), not the patch one.

Cross-compiled windows binary won't work because of missing libstdc++-6.dll

I'm working on a project that has spirv_cross in its dependency tree. Everything's fine on my Linux machine, but when I try to cross-compile a Windows executable, it can't be executed because libstdc++-6.dll is missing. I was able to verify this under Linux using Wine.

The problem can be reproduced easily using the example in this repository:

cargo install cross
cross build --package examples --bin glsl --target=x86_64-pc-windows-gnu
wine target/x86_64-pc-windows-gnu/debug/glsl.exe

This results in the following error message on my machine:

002b:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\hanno\\Projects\\vndf\\vendor\\spirv_cross\\target\\x86_64-pc-windows-gnu\\debug\\glsl.exe") not found
002b:err:module:LdrInitializeThunk Importing dlls for L"Z:\\home\\hanno\\Projects\\vndf\\vendor\\spirv_cross\\target\\x86_64-pc-windows-gnu\\debug\\glsl.exe" failed, status c0000135

This matches the report from a user testing on Windows.

I tried fixing this, but was not successful. I found a Stack Overflow answer that says to link statically. I tried adding the following the build.rs, but it made no difference:

build.flag("-static-libstdc++");

No idea how to proceed, as I'm barely familiar with C++, Windows, or cross-compiling.

get_entry_points: Use after free.

check!(br::sc_internal_free_pointer(
entry_point_raw_ptr as *mut c_void
));

The array is allocated as one whole, but each element of the array is freed individually. As the first element is freed first the other accesses are then working on un-allocated memory.

Also void free(void*), by definition, cannot return anything and thus never fails, but you are attempting to handle cases where it does.

Support for ray tracing shaders

It would be nice to have support for raytracing shaders in the reflection API, notably

  • New shader execution models (closest hit, anyhit, etc)
  • Acceleration structure resources.

Wasm32 Example

Hi Joshua, I'm trying to use this crate with a cross-platform "framework" I'm developing but I wasn't able to make it work with wasm32.

Can you give me a hint or a simple example of a wasm32 project to do it? Is this supported?

Thanks

Conditionally compile

Is it better to conditionally compile these files for reducing binary size for mobile app?

.file("src/vendor/SPIRV-Cross/spirv_glsl.cpp")
.file("src/vendor/SPIRV-Cross/spirv_hlsl.cpp")
.file("src/vendor/SPIRV-Cross/spirv_msl.cpp")

Support for wasm32-wasi

This crate currently seems to use cfg(target_arch = "wasm32") in order to mean "the web".
However, wasm32-wasi is meant to be an actual operating-system-like environment. The WASI SDK for example provides a clang toolchain that can compile C/C++ code.
Trying to compiling this crate for wasm32-wasi yields errors about JsValue not being found.

I would suggest using target_os = "emscripten" rather than target_arch = "wasm32" for everything Emscripten-related, and treat target_os = "wasi" in a cross-platform manner.

Try to compile C++ library without Emscripten

Now that clang supports WebAssembly directly, attempt to compile the C++ SPIRV-Cross library to WebAssembly using --target wasm32-unknown-unknown-wasm and avoid Emscripten.

If this is successful, investigate static linking the Rust and C++ portions together so we can remove the temporary workaround (moving data through JavaScript to call into Emscripten-wasm32 C++ from wasm32 Rust).

Remove `cdylib` in crate-type section?

We added a crate-type of cdylib to support wasm32-unknown-unknown which seemed to be best practice at the time, but it's unclear if this is necessary. As far as I know, cdylib was needed previously to avoid having a start section in the produced wasm binary.

It would be good to remove cdylib if possible so we could avoid having a separate crate re-exposing cdylib (see servo/servo#24708 (comment)).

cc @kvark

Review API to follow Rust guidelines

Certain functions are prefixed with get_ which is not best practice. Consider changing these and review Rust guidelines to see if anything else should be improved in the API.

Update to more recent upstream?

I recently ran into this issue when writing code using wgpu-native.

Any interest in updating the spirv_cross crate to the most recent upstream? I'm happy to test whether a simple submodule bump works, or whether more of the API has changed.

Pushing the fix all the way downstream to wgpu-native is going to be a challenge, as I think it goes through

  • spirv_cross
  • gfx backends
  • gfx-hal proper
  • wgpu-core
  • wgpu-native

But having an updated spirv_cross is the first step!

Simplify error handling

Some functions (especially simple getter-like functions) could probably avoid returning a Result and simply return the type, because we don't actually expect exceptions to be thrown on the C++ side.

As well, reconsider ErrorCode. Perhaps a String is sufficient for these cases and we can avoid the enum altogether.

Immutable `Ast` usage

gfx-rs Metal backend stores the shader module in order to compile it with different options for different pipeline layouts (see gfx-rs/gfx#1576). It would be great to store Ast instead of re-parsing it each time, and just provide a reference to CompilerOption at the spot where compilation is needed.

How about we remove set_compiler_options at all and make the Ast::compile(&self, &CompilerOptions) (notice &self)?

get_member_name() never fails.

ast.get_member_name() never fails, it just returns an empty string.
If this is by design because it's not considered an error, then maybe the Result<T> should be changed to Result<Option<T>>?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.