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

Librashader.lib not being compiled as static #20

Closed
star69rem opened this issue Oct 9, 2023 · 22 comments
Closed

Librashader.lib not being compiled as static #20

star69rem opened this issue Oct 9, 2023 · 22 comments

Comments

@star69rem
Copy link

star69rem commented Oct 9, 2023

I'm not able to link librashader.lib with a Visual Studio project with MT_StaticRelease.

I get the following error when setting the crt-static environment variable (SET RUSTFLAGS=-Ctarget-feature=+crt-static):

librashader.lib(wrapper.o) has value MT_StaticRelease
librashader.lib(shaderc.obj) has value MD_DynamicRelease

Is some librashader dependency dynamic or something?

@chyyran
Copy link
Member

chyyran commented Oct 9, 2023

librashader-reflect uses https://github.com/google/shaderc-rs which builds as dynamic by default. You could try enabling the standalone cargo feature in librashader-reflect which should build shaderc from source.

If that doesn't work you'll have to do some digging. librashader is designed to be linked dynamically with librashader_ld.h, since theres so many moving parts I can't really accommodate for every static linking scenario. I recommend corrosion in the README since that usually manages to get things working but thats only applicable if you use CMake as a build system.

@star69rem
Copy link
Author

It doesn't compile anymore after making reflect standalone.

Compiling librashader-runtime-vk v0.1.4 (C:\msys64\librashader\librashader-runtime-vk)
error[E0277]: the trait bound CachedCompilation<GlslangCompilation>: ShaderCompilation is not satisfied
--> librashader-runtime-gl\src\filter_chain\filter_impl.rs:107:39
|
107 | GLSL::compile_preset_passes::<CachedCompilation, FilterChainError>(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait ShaderCompilation is not implemented for CachedCompilation<GlslangCompilation>
|
= help: the trait ShaderCompilation is implemented for CachedCompilation<T>
note: required by a bound in compile_preset_passes
--> C:\msys64\librashader\librashader-reflect\src\reflect\presets.rs:51:12
|
38 | fn compile_preset_passes<C, E>(
| --------------------- required by a bound in this associated function
...
51 | C: ShaderCompilation,
| ^^^^^^^^^^^^^^^^^ required by this bound in CompilePresetTarget::compile_preset_passes

error[E0277]: the trait bound CachedCompilation<GlslangCompilation>: ShaderCompilation is not satisfied
--> librashader-runtime-d3d11\src\filter_chain.rs:83:39
|
83 | HLSL::compile_preset_passes::<CachedCompilation, FilterChainError>(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait ShaderCompilation is not implemented for CachedCompilation<GlslangCompilation>
|
= help: the trait ShaderCompilation is implemented for CachedCompilation<T>
note: required by a bound in compile_preset_passes
--> C:\msys64\librashader\librashader-reflect\src\reflect\presets.rs:51:12
|
38 | fn compile_preset_passes<C, E>(
| --------------------- required by a bound in this associated function
...
51 | C: ShaderCompilation,
| ^^^^^^^^^^^^^^^^^ required by this bound in CompilePresetTarget::compile_preset_passes

error[E0277]: the trait bound CachedCompilation<GlslangCompilation>: ShaderCompilation is not satisfied
--> librashader-runtime-vk\src\filter_chain.rs:216:40
|
216 | SPIRV::compile_preset_passes::<CachedCompilation, FilterChainError>(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait ShaderCompilation is not implemented for CachedCompilation<GlslangCompilation>
|
= help: the trait ShaderCompilation is implemented for CachedCompilation<T>
note: required by a bound in compile_preset_passes
--> C:\msys64\librashader\librashader-reflect\src\reflect\presets.rs:51:12
|
38 | fn compile_preset_passes<C, E>(
| --------------------- required by a bound in this associated function
...
51 | C: ShaderCompilation,
| ^^^^^^^^^^^^^^^^^ required by this bound in CompilePresetTarget::compile_preset_passes

error[E0277]: the trait bound CachedCompilation<GlslangCompilation>: ShaderCompilation is not satisfied
--> librashader-runtime-d3d12\src\filter_chain.rs:154:39
|
154 | DXIL::compile_preset_passes::<CachedCompilation, FilterChainError>(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait ShaderCompilation is not implemented for CachedCompilation<GlslangCompilation>
|
= help: the trait ShaderCompilation is implemented for CachedCompilation<T>
note: required by a bound in compile_preset_passes
--> C:\msys64\librashader\librashader-reflect\src\reflect\presets.rs:51:12
|
38 | fn compile_preset_passes<C, E>(
| --------------------- required by a bound in this associated function
...
51 | C: ShaderCompilation,
| ^^^^^^^^^^^^^^^^^ required by this bound in CompilePresetTarget::compile_preset_passes

error[E0277]: the trait bound CachedCompilation<GlslangCompilation>: ShaderCompilation is not satisfied
--> librashader-runtime-d3d12\src\filter_chain.rs:171:39
|
171 | HLSL::compile_preset_passes::<CachedCompilation, FilterChainError>(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait ShaderCompilation is not implemented for CachedCompilation<GlslangCompilation>
|
= help: the trait ShaderCompilation is implemented for CachedCompilation<T>
note: required by a bound in compile_preset_passes
--> C:\msys64\librashader\librashader-reflect\src\reflect\presets.rs:51:12
|
38 | fn compile_preset_passes<C, E>(
| --------------------- required by a bound in this associated function
...
51 | C: ShaderCompilation,
| ^^^^^^^^^^^^^^^^^ required by this bound in CompilePresetTarget::compile_preset_passes

For more information about this error, try rustc --explain E0277.
error: could not compile librashader-runtime-gl (lib) due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile librashader-runtime-d3d11 (lib) due to previous error
error: could not compile librashader-runtime-vk (lib) due to previous error
error: could not compile librashader-runtime-d3d12 (lib) due to 2 previous errors

@chyyran
Copy link
Member

chyyran commented Oct 9, 2023

Are you using the nightly compiler?

@star69rem
Copy link
Author

Yes. It compiles fine if I don't try to build it static MT.

@chyyran
Copy link
Member

chyyran commented Oct 9, 2023 via email

@star69rem
Copy link
Author

If there wasn't I wouldn't be going through this BDSM.

@chyyran
Copy link
Member

chyyran commented Oct 9, 2023

I'm going to need to know more about your use case as to why the supported headers aren't a valid option.

@star69rem
Copy link
Author

I don't want users to have to install the C++ Redistributables. Thanks!

@chyyran
Copy link
Member

chyyran commented Oct 12, 2023

While I honestly don’t think it’s worth the trouble of static linking just to avoid installing the C++ redistributables (especially since librashader_ld.h means that the librashader version is user-upgradable: it’s very unlikely the ABI will change at this point), I can look into this for you; just in the middle of a move right now so it’ll be some time until I can get set up again.

@star69rem
Copy link
Author

I would appreciate it but there's no rush. I just keep running into people who get tripped up by the redistributables and I would really prefer to not have to package a whole installer for it. Thanks again!

@chyyran
Copy link
Member

chyyran commented Nov 29, 2023

google/shaderc-rs#143

looks like I'll need this, will need to wait until the next shaderc release to get this working.

@chyyran
Copy link
Member

chyyran commented Nov 30, 2023

Could you check if shaderc links properly as of 2bd6f8f?

@chyyran
Copy link
Member

chyyran commented Nov 30, 2023

Publishing librashader 0.2.0-beta.2 for you to test. I removed DXIL support on Linux, hence the minor bump.

@star69rem
Copy link
Author

star69rem commented Nov 30, 2023

Get this error:

3>lld-link : error : /failifmismatch: mismatch detected for 'RuntimeLibrary':
3>>>> librashader.lib(wrapper.o) has value MT_StaticRelease
3>>>> librashader.lib(shaderc.obj) has value MD_DynamicRelease

@star69rem
Copy link
Author

Output from shaderc-sys build:
cargo:warning=shaderc: searching native shaderc libraries in Vulkan SDK 'C:\VulkanSDK\1.3.236.0/lib'
cargo:warning=shaderc: Windows MSVC static build is experimental
cargo:rustc-link-search=native=\?\C:\VulkanSDK\1.3.236.0\Lib
cargo:rustc-link-lib=static=shaderc_combined

@star69rem
Copy link
Author

I got it to compile by just moving the shaderc libs out of the vulkan SDK folder.

@star69rem
Copy link
Author

Still having one problem: it all works if it's using the optimized profile, but using the debug profile doesn't work because it seems like some stuff is still being compiled in release mode. So it seems like the debug setting isn't being passed to all dependencies?

@star69rem
Copy link
Author

2>>>> libcpmtd.lib(xstoull.obj) has value 2
2>>>> librashader_debug.lib(wrapper.o) has value 0

xstoull.obj for some reason is in release

@star69rem
Copy link
Author

I tried the recommendation to set the environment variables: SET CXXFLAGS=-MTd SET CFLAGS=-MTd

Now it fails on xstrxfrm.obj instead of xstoull.obj.

1>>>> libcpmtd.lib(xstrxfrm.obj) has value 2
1>>>> librashader_debug.lib(shaderc.cc.obj) has value 0

@chyyran
Copy link
Member

chyyran commented Dec 1, 2023

I'm honestly not sure where libcpmtd.lib is coming from. Maybe spirv-to-dxil-rs? Does it build without dxil support?

@star69rem
Copy link
Author

star69rem commented Dec 1, 2023

I looked into it a bit, and apparently this is a known issue with rust's libc being hardcoded to compile with a release flag. I'm not even sure there's anything you can do. Seems like it's been an issue for years.

rust-lang/rust#39016

I worked around it by just throwing in some preprocessor definitions to use the DLL for debug mode and the static linking for the release build. Not ideal, but it works. Stuff like this is why I think there's going to be so much friction actually getting your program into emulators. Emulator authors tend to be OCD nutjobs and stuff like this is going to drive them crazy. They all want to rule their own little world with statically linked everything.

@chyyran
Copy link
Member

chyyran commented Dec 13, 2023

Closing as resolved.

@chyyran chyyran closed this as completed Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants