allow statically linking librocksdb (#29)

This commit is contained in:
Ștefan Talpalaru 2022-03-22 10:02:39 +01:00 committed by GitHub
parent c565aa88b9
commit c381daf84f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 5 deletions

View File

@ -20,6 +20,16 @@ A RocksDB installation that provides `librocksdb.so`. This means that on Debian,
See [simple_example](examples/simple_example.nim)
### Static linking
To statically link librocksdb, you would do something like:
```nim
nim c -d:LibrocksbStaticArgs='-l:librocksdb.a' --gcc.linkerexe=g++ --threads:on your_program.nim
```
(we need the C++ linker profile because it's a C++ library)
## Future directions
In the future, Nim-RocksDB might provide a high-level API that:

View File

@ -4,6 +4,7 @@ author = "Status Research & Development GmbH"
description = "A wrapper for Facebook's RocksDB, an embeddable, persistent key-value store for fast storage"
license = "Apache License 2.0 or GPLv2"
skipDirs = @["examples", "tests"]
mode = ScriptMode.Verbose
### Dependencies
requires "nim >= 1.2.0",
@ -18,4 +19,7 @@ proc test(args, path: string) =
task test, "Run tests":
test "", "tests/all.nim"
# Too troublesome to install "librocksdb.a" in CI, but this is how we would
# test it (we need the C++ linker profile because it's a C++ library):
# test "-d:LibrocksbStaticArgs='-l:librocksdb.a' --gcc.linkerexe=g++", "tests/all.nim"

View File

@ -1,5 +1,4 @@
# Nim-RocksDB
# Copyright 2018 Status Research & Development GmbH
# Copyright 2018-2022 Status Research & Development GmbH
# Licensed under either of
#
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
@ -48,6 +47,8 @@ proc shouldUseNativeLinking(): bool {.compileTime.} =
when defined(linux):
return true
const LibrocksbStaticArgs {.strdefine.}: string = ""
template rocksType(T) =
type T* = distinct pointer
proc isNil*(v: T): bool {.borrow, gcsafe.}
@ -100,6 +101,10 @@ rocksType rocksdb_transaction_t
rocksType rocksdb_checkpoint_t
## DB operations
when LibrocksbStaticArgs != "":
{.pragma: importrocks, importc, cdecl.}
{.passL: LibrocksbStaticArgs.}
else:
when shouldUseNativeLinking():
{.pragma: importrocks, importc, cdecl.}
{.passL: "-lrocksdb".}