Skip to content

Commit

Permalink
Move static linking into wrapper code.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhartnett committed Mar 20, 2024
1 parent 4b39c1c commit e5804f3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
9 changes: 0 additions & 9 deletions config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,8 @@ when fileExists("nimble.paths"):
include "nimble.paths"
# end Nimble config

switch("gcc.exe", "gcc")

when defined(rocksdb_static_linking):
import std/[os, strutils]

const libsDir = currentSourcePath.parentDir().replace('\\', '/') & "/build/lib"

switch("gcc.linkerexe", "g++") # use the C++ linker profile because it's a C++ library
switch("dynlibOverride", "librocksdb.a")
switch("dynlibOverride", "liblz4.a")
switch("dynlibOverride", "libzstd.a")
switch("l", libsDir & "/librocksdb.a")
switch("l", libsDir & "/liblz4.a")
switch("l", libsDir & "/libzstd.a")
2 changes: 1 addition & 1 deletion rocksdb/columnfamily/cfopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ proc defaultColFamilyOptions*(): ColFamilyOptionsRef =
let opts = newColFamilyOptions()

rocksdb_options_set_compression(opts.cPtr, rocksdb_lz4_compression)
rocksdb_options_set_bottommost_compression(opts.cPtr, rocksdb_zstd_compression)
# rocksdb_options_set_bottommost_compression(opts.cPtr, rocksdb_zstd_compression)

# Enable creating column families if they do not exist
opts.setCreateMissingColumnFamilies(true)
Expand Down
11 changes: 11 additions & 0 deletions rocksdb/lib/librocksdb.nim
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,18 @@ type
## DB operations

when defined(rocksdb_static_linking):
import std/[os, strutils]

{.pragma: importrocks, importc, cdecl.}

const
topLevelPath = currentSourcePath.parentDir().parentDir().parentDir()
libsDir = topLevelPath.replace('\\', '/') & "/build/lib"

{.passL: libsDir & "/librocksdb.a".}
{.passL: libsDir & "/liblz4.a".}
{.passL: libsDir & "/libzstd.a".}

when defined(windows):
{.passL: "-lshlwapi -lrpcrt4".}
else:
Expand Down
2 changes: 1 addition & 1 deletion rocksdb/options/backupopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ proc cPtr*(engineOpts: BackupEngineOptionsRef): BackupEngineOptionsPtr =
proc defaultBackupEngineOptions*(): BackupEngineOptionsRef {.inline.} =
let opts = newBackupEngineOptions()
rocksdb_options_set_compression(opts.cPtr, rocksdb_lz4_compression)
rocksdb_options_set_bottommost_compression(opts.cPtr, rocksdb_zstd_compression)
# rocksdb_options_set_bottommost_compression(opts.cPtr, rocksdb_zstd_compression)
opts


Expand Down
2 changes: 1 addition & 1 deletion rocksdb/options/dbopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ proc defaultDbOptions*(): DbOptionsRef =
let opts: DbOptionsRef = newDbOptions()

rocksdb_options_set_compression(opts.cPtr, rocksdb_lz4_compression)
rocksdb_options_set_bottommost_compression(opts.cPtr, rocksdb_zstd_compression)
# rocksdb_options_set_bottommost_compression(opts.cPtr, rocksdb_zstd_compression)

# Optimize RocksDB. This is the easiest way to get RocksDB to perform well:
opts.setIncreaseParallelism(countProcessors())
Expand Down

0 comments on commit e5804f3

Please sign in to comment.