From e5804f3a744b5b721a35764a298102963d2666f9 Mon Sep 17 00:00:00 2001 From: web3-developer <51288821+web3-developer@users.noreply.github.com> Date: Wed, 20 Mar 2024 22:43:41 +0800 Subject: [PATCH] Move static linking into wrapper code. --- config.nims | 9 --------- rocksdb/columnfamily/cfopts.nim | 2 +- rocksdb/lib/librocksdb.nim | 11 +++++++++++ rocksdb/options/backupopts.nim | 2 +- rocksdb/options/dbopts.nim | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/config.nims b/config.nims index 22c3eb5..f9ce5e7 100644 --- a/config.nims +++ b/config.nims @@ -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") diff --git a/rocksdb/columnfamily/cfopts.nim b/rocksdb/columnfamily/cfopts.nim index 01a45e7..baef797 100644 --- a/rocksdb/columnfamily/cfopts.nim +++ b/rocksdb/columnfamily/cfopts.nim @@ -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) diff --git a/rocksdb/lib/librocksdb.nim b/rocksdb/lib/librocksdb.nim index 8dc12a9..02f053d 100644 --- a/rocksdb/lib/librocksdb.nim +++ b/rocksdb/lib/librocksdb.nim @@ -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: diff --git a/rocksdb/options/backupopts.nim b/rocksdb/options/backupopts.nim index 249b978..4fdc0ee 100644 --- a/rocksdb/options/backupopts.nim +++ b/rocksdb/options/backupopts.nim @@ -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 diff --git a/rocksdb/options/dbopts.nim b/rocksdb/options/dbopts.nim index 93ee78d..5be51b3 100644 --- a/rocksdb/options/dbopts.nim +++ b/rocksdb/options/dbopts.nim @@ -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())