allow statically linking librocksdb (#29)
This commit is contained in:
parent
c565aa88b9
commit
c381daf84f
10
README.md
10
README.md
|
@ -20,6 +20,16 @@ A RocksDB installation that provides `librocksdb.so`. This means that on Debian,
|
||||||
|
|
||||||
See [simple_example](examples/simple_example.nim)
|
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
|
## Future directions
|
||||||
|
|
||||||
In the future, Nim-RocksDB might provide a high-level API that:
|
In the future, Nim-RocksDB might provide a high-level API that:
|
||||||
|
|
|
@ -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"
|
description = "A wrapper for Facebook's RocksDB, an embeddable, persistent key-value store for fast storage"
|
||||||
license = "Apache License 2.0 or GPLv2"
|
license = "Apache License 2.0 or GPLv2"
|
||||||
skipDirs = @["examples", "tests"]
|
skipDirs = @["examples", "tests"]
|
||||||
|
mode = ScriptMode.Verbose
|
||||||
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
requires "nim >= 1.2.0",
|
requires "nim >= 1.2.0",
|
||||||
|
@ -18,4 +19,7 @@ proc test(args, path: string) =
|
||||||
|
|
||||||
task test, "Run tests":
|
task test, "Run tests":
|
||||||
test "", "tests/all.nim"
|
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"
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
# Nim-RocksDB
|
# Copyright 2018-2022 Status Research & Development GmbH
|
||||||
# Copyright 2018 Status Research & Development GmbH
|
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
#
|
#
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
# * 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):
|
when defined(linux):
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
const LibrocksbStaticArgs {.strdefine.}: string = ""
|
||||||
|
|
||||||
template rocksType(T) =
|
template rocksType(T) =
|
||||||
type T* = distinct pointer
|
type T* = distinct pointer
|
||||||
proc isNil*(v: T): bool {.borrow, gcsafe.}
|
proc isNil*(v: T): bool {.borrow, gcsafe.}
|
||||||
|
@ -100,11 +101,15 @@ rocksType rocksdb_transaction_t
|
||||||
rocksType rocksdb_checkpoint_t
|
rocksType rocksdb_checkpoint_t
|
||||||
|
|
||||||
## DB operations
|
## DB operations
|
||||||
when shouldUseNativeLinking():
|
when LibrocksbStaticArgs != "":
|
||||||
{.pragma: importrocks, importc, cdecl.}
|
{.pragma: importrocks, importc, cdecl.}
|
||||||
{.passL: "-lrocksdb".}
|
{.passL: LibrocksbStaticArgs.}
|
||||||
else:
|
else:
|
||||||
{.pragma: importrocks, importc, cdecl, dynlib: librocksdb.}
|
when shouldUseNativeLinking():
|
||||||
|
{.pragma: importrocks, importc, cdecl.}
|
||||||
|
{.passL: "-lrocksdb".}
|
||||||
|
else:
|
||||||
|
{.pragma: importrocks, importc, cdecl, dynlib: librocksdb.}
|
||||||
|
|
||||||
proc rocksdb_open*(options: rocksdb_options_t; name: cstring; errptr: ptr cstring): rocksdb_t {.importrocks.}
|
proc rocksdb_open*(options: rocksdb_options_t; name: cstring; errptr: ptr cstring): rocksdb_t {.importrocks.}
|
||||||
proc rocksdb_open_for_read_only*(options: rocksdb_options_t; name: cstring;
|
proc rocksdb_open_for_read_only*(options: rocksdb_options_t; name: cstring;
|
||||||
|
|
Loading…
Reference in New Issue