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

Linux - search common locations for libdxcompiler.so #68

Open
expenses opened this issue May 14, 2023 · 3 comments · May be fixed by #74
Open

Linux - search common locations for libdxcompiler.so #68

expenses opened this issue May 14, 2023 · 3 comments · May be fixed by #74

Comments

@expenses
Copy link

expenses commented May 14, 2023

Hi! I'm using the directx-shader-compiler package on arch linux that just installs libdxcompiler.so to /usr/lib/libdxcompiler.so, but hassle-rs currently requires it be in the local directory so I have to copy it over. It'd be great for hassle-rs to check common locations (such as /usr/lib) for it first.

Ideally a tool or crate should be used to find libraries instead of hardcoding paths - I think some interface to ldconfig (is there a crate for this?) would work. https://stackoverflow.com/q/9922949 has some suggestions.

@MarijnS95
Copy link
Member

MarijnS95 commented May 15, 2023

Hi!

We allow you to choose any path when constructing the objects directly via Dxc::new(Some("...")) and Dxil::new(Some("...")). No need to use any crate to help find it I think, relying on the system and LD environment variables should be enough. Semantics are different between Windows and Linux though, where Windows looks relative to the executable and Linux relative to PWD (in addition to other env vars and/or config steering LD). Either way we could drop the ./ IMO (for now I also have a libdxcompiler.so -> /usr/lib/libdxcompiler.so symlink 😬).

I do intend to remove the compile_hlsl() etc helper one day, or at the very least inline its error helpers into fn compile(), but it's been tricky with so many functions returning HRESULT and there being no precedent when or not the returned error string is set and could be bubbled up to the user 1. That's the only thing you'll have to copy/reimplement when using the Dxc and Dxil implementations directly.

Footnotes

  1. My idea is to handle as few HRESULTs as possible to get to the error string, and if it's set/non-zero store that as context to either return when any of the subsequent HRESULTs are checked, or finally provide it to the user on success.

@MarijnS95
Copy link
Member

Just running into a relatedly funny bug. When calling Dxc::new(Some("libdxcompiler.so")) on a Linux machine, but that relative filename isn't a file (doesn't exist at all) relative to $PWD. So this code runs into the else path and concatenates that ./libdxcompiler.so path...:

hassle-rs/src/wrapper.rs

Lines 514 to 518 in d472559

if lib_path.is_file() {
lib_path
} else {
lib_path.join(dxcompiler_lib_name())
}

And ends up with:

panicked at 'called `Result::unwrap()` on an `Err` value: HassleError(LoadLibraryError { filename: "libdxcompiler.so/./libdxcompiler.so", inner: DlOpen { desc: "libdxcompiler.so/./libdxcompiler.so: cannot open shared object file: No such file or directory" } })'

😂

@MarijnS95
Copy link
Member

I think the only way to fix this cleanly is to stop pretending lib_path could either be a dir or filename.

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

Successfully merging a pull request may close this issue.

2 participants