My understanding of the publish process:
- cargo packages up all files into a
.crate file, excluding things in
.gitignore and as marked in
- cargo creates a temporary directory to test the crate
- cargo unpacks that packaged file into the temp directory
- cargo builds the packaged file
- if successful, cargo publishes to crates.io
You seem to be failing on the fourth step, where it's trying to build in a temp directory. While you could avoid this step, I think it is a real problem. When anyone depends on the crate, the crate will be built in
$CARGO_HOME/src/github-xxx/crate-name_crate-version/, and you definitely don't want to require users to stick a lib file in that source directory.
If your crate can't even build in a temporary directory on your computer, how is it supposed to build from inside
What you want to do is fine, though. It should be exactly the same as a crate like rust-openssl, which depends on OpenSSL being installed separately to build. (it does have a
vendored flag to allow for building openssl itself, but by default depends on an external library to exist).
To fix this, maybe you could adopt a strategy for locating the library more like the one OpenSSL uses? As long as it searches somewhere in system files, independent of your repo's folder, it should work.
Since your library is publicly available, is there an installer for it? If so, maybe you could look into where it sticks the lib files, and search independently?
Or if you're already doing that, then look into why it's failing. Maybe try cloning a fresh
git repository, and building that? That should show you the same errors that cargo is getting. Something's failing because it can't work without ignored files in the project repo, so making a fresh clone in a different directory should give you an opportunity to debug those errors.