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

Unclear what Config::build() returns #56

Open
ExpHP opened this issue Sep 5, 2018 · 4 comments
Open

Unclear what Config::build() returns #56

ExpHP opened this issue Sep 5, 2018 · 4 comments

Comments

@ExpHP
Copy link

ExpHP commented Sep 5, 2018

The output of this function is confusing and undocumented.

Based on the code samples in README.md lib.rs, it would appear to be the directory where libs were installed. However, printing its value, I see that it is simply the install prefix (target/debug/build/lammps-sys-96aab2de8377bb22/out), and I need to instead write something like

let dir = cmake.build();
// I don't even know if this is portable...
println!("cargo:rustc-link-search=native={}", dir.join("lib64").display());

I'm not sure what to make of this. I'd call it a bug, but that's assuming that the function is supposed to return the libs dir!


Note: To reproduce what I'm seeing, this isn't exactly minimal, but:

git clone https://github.com/ExpHP/lammps-sys
cd lammps-sys
git checkout 01c3d3bff
git submodule init
git submodule update
cargo build -v

and watch the build script output or linker flags. You'll see the path target/debug/build/lammps-sys-xxxxxxxxx/out/lib64, generated by this line of code, indicating that the return value ended in out as opposed to out/lib or out/lib64.

I see this even on the travis docker image, where much to my chagrin, it actually installs them to lib/. (of course, the linking step fails there!)

@alexcrichton
Copy link
Member

Right now I believe it's the root of the installation directory, but a PR to improve the docs would be much appreciated!

@ExpHP
Copy link
Author

ExpHP commented Sep 5, 2018

Hmm. I was about to ask if this means that the code examples in lib.rs are incorrect—but then I noticed that there is also a build free function, whose output is documented:

/// Builds the native library rooted at `path` with the default cmake options.
/// This will return the directory in which the library was installed.

Maybe I've actually run into a bug, and the function is supposed to return [OUT_DIR]/lib64 in my case? Or maybe it is supposed to return [OUT_DIR], and is also supposed to put the libraries there (but somehow isn't in this case)?


Addendum: I decided to start surveying cmake's dependent crates, and the first one I checked has this which definitely seems to suggest that the examples are wrong and the free function's documentation is misleading!

@alexcrichton
Copy link
Member

I believe returning$OUT_DIR is correct in that your crate will locally need to append lib64

@joelgallant
Copy link
Contributor

I think this confusion comes from the library with the CMakeLists.txt

CMake doesn't, strictly speaking, always produce binaries in the same place. The default target that cmake-rs uses is install, but you probably want cmake.build_target('lammps').build() (doc)

lammps installs to CMAKE_INSTALL_LIBDIR as seen here

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

3 participants