cmake-rs
cmake-rs copied to clipboard
Unclear what Config::build() returns
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!)
Right now I believe it's the root of the installation directory, but a PR to improve the docs would be much appreciated!
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!
I believe returning$OUT_DIR
is correct in that your crate will locally need to append lib64
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