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

Linking with system RocksDB #310

Open
jonhoo opened this issue May 31, 2019 · 23 comments · May be fixed by #354
Open

Linking with system RocksDB #310

jonhoo opened this issue May 31, 2019 · 23 comments · May be fixed by #354

Comments

@jonhoo
Copy link
Contributor

jonhoo commented May 31, 2019

#166 introduced the ability to link with an already-built instance of rocksdb (such as one installed system-wide). However, it requires that you explicitly give the path to search in (ROCKSDB_LIB_DIR, SNAPPY_LIB_DIR, etc.). It'd be really neat if rocksdb-sys checked if rocksdb and snappy were available in the standard OS locations too (originally suggested in #166 (comment)). It's a little unfortunate to have to pass custom environment variables every time we build even though those libraries are installed system-wide.

Alternatively, even just a ROCKSDB_USE_SYSTEM=1 would be a step up.

@jonhoo
Copy link
Contributor Author

jonhoo commented May 31, 2019

Related to this, it'd be great if these environment variables where documented in the README and the docs!

@expenses
Copy link

expenses commented Nov 2, 2019

This would be really useful!

@jonhoo
Copy link
Contributor Author

jonhoo commented Nov 15, 2019

The build file for openssl-sys may be a good place to draw on from inspiration here.

@lovesegfault
Copy link

I'm working on this

@jonhoo
Copy link
Contributor Author

jonhoo commented Feb 17, 2020

@lovesegfault How's your progress on this? Building rocksdb is by far the biggest part of my project's build time at the moment 😢

@aleksuss
Copy link
Member

What is a problem to use system library now? AFAIK, it works via pkg-config or env variable well.

@jonhoo
Copy link
Contributor Author

jonhoo commented Feb 17, 2020

@aleksuss Well, on current master, if I try to build librocksdb-sys, it still spins up a bunch of C++ compiler instances, even though I have rocksdb installed as a system-wide library:

$ ls /usr/lib/librocksdb.so*
/usr/lib/librocksdb.so  /usr/lib/librocksdb.so.6  /usr/lib/librocksdb.so.6.5.3

@lovesegfault
Copy link

I had stopped working on this because other things took priority in the office. I'm going on vacation for the next ~2 weeks, so hopefully I can pick this back up :)

@lovesegfault
Copy link

Note that #354 doesn’t add any library discovery magic. Mostly because RocksDB doesn’t support pkg-config or any other similar tool.

In the future a simple clause to that looks for the libraries in the usual places in case the corresponding envvar isn’t set could easily be added.

@jonhoo
Copy link
Contributor Author

jonhoo commented Feb 20, 2020

Ah, I see, so if the crate currently fails to find a system-wide RocksDB, that will continue to be the case. I wonder what's making it fail. Maybe it looks for exactly the same version of the .so, not just a compatible one?

@lovesegfault
Copy link

Well, the current crate will attempt to find a system rocksdb and vendor if it can't. #354 means you select, through a feature, whether to vendor or not. If you don't vendor, then you must set ROCKSDB_LIB_DIR and if you don't you'll get a helpful error message.

I can add a follow up that attempts to find the lib if the envvar isn't set, I'm just generally not a fan of that behavior.

@jonhoo
Copy link
Contributor Author

jonhoo commented Feb 21, 2020

@lovesegfault Not sure I'm reading that correctly? So, you're saying that currently, if ROCKSDB_LIB_DIR is not set, then rocksdb will vendor? And the only way to have it link with the system-wide lib is by setting ROCKSDB_LIB_DIR?

I'm curious -- why is it you would be against using the system library by default? Vendoring brings huge compile times, and I'm not sure what the upside is?

@lovesegfault
Copy link

@jonhoo
Current Behavior
librocksdb-sys will look for ROCKSDB_LIB_DIR envvar. If it is set it will link to the .so in that dir. If it is not set, then it will vendor rocksdb as an alternative. The exact same behavior also happens for the compression libraries such as bzip2, with the variable there being BZIP2_LIB_DIR, for example.

New behavior
librocksdb-sys has a new (default) feature vendor. If that feature is enabled it will not try to look for any system libraries, in any way. Instead it will vendor rocksdb and all the compression libraries.

If the vendor feature is not enabled, then librocksdb-sys will not, in any way, attempt to vendor any libraries, including rocksdb and compression libs. Instead it will look for envvars that inform it of where to find the necessary libraries. These envvars are in the form LIBNAME_LIB_DIR. It will not attempt to do any discovery of system libraries, it relies on the user specifying them, If you have vendor disabled and forget to set the corresponding envvar, then the build will fail with a message telling you to set the envvar.

Possible future behavior
In the future, when vendor is disabled, we could attempt to do discovery of system libraries, as a fallback when the envvars are not set. I have not implemented this yet, but plan to when I have time.

@jonhoo
Copy link
Contributor Author

jonhoo commented Feb 21, 2020

Doing this with a feature is a little odd, because it means that if any crate in your dependency tree includes rocksdb with the vendor feature set, then RocksDB will be vendored. It won't make much of a difference for small crates, but for a large binary that may have multiple transitive dependencies on RocksDB, it makes it pretty likely that there is no way to opt out of vendoring..

@lovesegfault
Copy link

@jonhoo That's true, how else do you imagine this working?

IMHO there should be no vendoring at all, vendoring is the root of all evil. If @aleksuss and other maintainers would allow it I'd prefer to get rid of vendoring alltogether.

@jonhoo
Copy link
Contributor Author

jonhoo commented Feb 21, 2020

I agree with you -- the solution is to not vendor. At the very least, vendoring should not be in the default feature set. One option is to have vendoring be opt-in using an environment variable.

@lovesegfault
Copy link

That could be done, @aleksuss @vitvakatu what are you guys' thoughts?

@vitvakatu
Copy link

Features are indeed hard to control in case of transitive dependencies, and compiling RocksDB from source costs a lot (for our project, it's about 30% increase of the build time!). However, I don't like the idea of complete removing of vendoring. On some platforms we do not have newest rocksdb version available: we were even forced to make our own PPA for older Ubuntu distributions.

So, I'd prefer to save the current behavior, but maybe improve it (automatic libraries search?). Perhaps we should force user to manually enable vendoring (via env var), but it would be a bit annoying for transitive dependencies as well.

Well, on current master, if I try to build librocksdb-sys, it still spins up a bunch of C++ compiler instances, even though I have rocksdb installed as a system-wide library:

This also looks pretty weird and probably should be fixed.

@jonhoo
Copy link
Contributor Author

jonhoo commented Feb 22, 2020

@vitvakatu Yeah, I think "inverting" the behavior so that users opt-in to vendoring is probably the right way to go :)

This also looks pretty weird and probably should be fixed.

Note that I do not have any env vars set, so I believe this is intended behavior per today?

@lovesegfault
Copy link

Alright, I inverted the behavior :)

@jonhoo
Copy link
Contributor Author

jonhoo commented Feb 22, 2020

@lovesegfault I think if we are inverting the behavior, then it's probably also necessary to have build.rs search for rocksdb in /usr/lib or something by default. Otherwise a bunch of users are suddenly going to get compilation errors since they do not have the env var set.

@lovesegfault
Copy link

Alright, so pending work is::

  • Library discovery
  • Turn vendor feature into envvar

BusyJay pushed a commit to BusyJay/rust-rocksdb that referenced this issue Jul 23, 2020
* Fix titan config (rust-rocksdb#306)

* Add titan read option (rust-rocksdb#309)

Signed-off-by: Connor1996 <zbk602423539@gmail.com>
@d4h0
Copy link

d4h0 commented May 6, 2023

I'm using rust-rocksdb via SurrealDB, and on every file change rocksdb (or part of it) seems to get re-compiled, which results in 100% of all my CPU cores being used for several minutes (and my system becoming therefore sluggish).

Having to specify the environment variables everywhere (IDE, command line, etc.) isn't great (as mentioned).

My workaround is to define those variables in .cargo/config.toml:

[env]
ROCKSDB_LIB_DIR = "/usr/lib/"
SNAPPY_LIB_DIR = "/usr/lib/"

Now every Cargo instance that runs within the project directory has ROCKSDB_LIB_DIR and SNAPPY_LIB_DIR set.

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.

6 participants