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

Correct way to include dylib folder in search path for cargo run #6773

Closed
tangmi opened this issue Mar 22, 2019 · 1 comment
Closed

Correct way to include dylib folder in search path for cargo run #6773

tangmi opened this issue Mar 22, 2019 · 1 comment
Labels
C-bug Category: bug

Comments

@tangmi
Copy link

tangmi commented Mar 22, 2019

Problem/Steps

I'm trying to create a wrapper for a native library that includes a static .lib and two .dlls.

Following the Cargo Book docs on build scripts, I'm outputting (actual source):

cargo:rustc-link-lib=static=slang
cargo:rustc-link-search={path to .dll and .lib folder}

When I run cargo build --verbose, I see that subsequent calls to rustc include a flag -L {path to .dll and .lib folder}, but when running an example program using that library, the process exits fast with STATUS_DLL_NOT_FOUND. If I remove the call to the native library bindings and dump the PATH, my rustc-link-search path is not present (the search paths for bzip2-sys, curl-sys, and libz-sys do appear in PATH, but examining their respective build.rss and cc-rs's source, I couldn't figure out what they were doing differently).

I found cargo::util::paths::dylib_path(), but couldn't figure out where it was used...

Also, adding cargo:rustc-link-lib=dylib=slang-glslang makes Cargo complain about not being able to find slang-glslang.lib, which confuses me since I expect it to look for slang-glslang.dll and thought .lib was for static libs on Windows.

Edit: If I add cc::Build::new().out_dir(&slang_binaries_path).file("dummy.c").compile("foo") (where dummy.c is an empty file), I correctly get the PATH variable set.

Notes

Output of cargo version: cargo 1.33.0 (f099fe94b 2019-02-12)

Rust version:

stable-x86_64-pc-windows-msvc (default)
rustc 1.33.0 (2aa4c46cf 2019-02-28)

OS: Windows 10

Thanks for your time!

@tangmi tangmi added the C-bug Category: bug label Mar 22, 2019
@tangmi
Copy link
Author

tangmi commented Mar 22, 2019

I've figured this out, I was being to clever and passing the fs::canonicalized path and cargo:rustc-link-search does not like that.

@tangmi tangmi closed this as completed Mar 22, 2019
CGMossa added a commit to extendr/libR-sys that referenced this issue Apr 10, 2023
`STATUS_DLL_NOT_FOUND`
error on Windows.
It is something to do with paths.
this rust-lang/cargo#6773
motivated the following change
(I know...)
CGMossa added a commit to extendr/libR-sys that referenced this issue Apr 12, 2023
* These callbacks are for trimming comments, thus they should be named as such

* I always get
`STATUS_DLL_NOT_FOUND`
error on Windows.
It is something to do with paths.
this rust-lang/cargo#6773
motivated the following change
(I know...)

* Added `is_anonymous`,
which depends on atleast `clang_3_7`,
so that is added, but hopefully it doesn't
Interfere with `runtime`-feature.

- `get_non_api` is only used when `use-bindgen` is enabled.
- Rename `RCallbacks` to reflect what they actually do right now, which is trimming the comments processed by clang, i.e. `TrimCommentsCallbacks`. 
- BUG FIX: On Windows paths to dylib/dlls don't get processed properly. Added a `.canonicalize` and it seems to fix it.
- Updated bindgen to latest version `0.64`. 
- Added a versioning header to all bindings; e.g.
```
/* bindgen clang version: Ubuntu clang version 14.0.0-1ubuntu1 */
/* clang-rs version: Ubuntu clang version 14.0.0-1ubuntu1 */
/* r version: 4.1.3 */
/* automatically generated by rust-bindgen 0.64.0 */
[...]
````
- BUG FIX: Added a `is_anonymous` check on the entities processed. This is necessary as some unamed items
gets a name in llvm16, and that isn't handled in any meaningful way by `clang-rs` unfortunately. This requires `clang_3_7` atleast, which is also added.
- Updated bindings

---------

Co-authored-by: CGMossa <CGMossa@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

1 participant