Skip to content

Commit

Permalink
Add rocksdb_dynamic_linking flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhartnett committed Jan 14, 2025
1 parent 9dac0fd commit e7b7c6e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 15 deletions.
4 changes: 2 additions & 2 deletions config.nims
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# nim-rocksdb
# Copyright (c) 2019-2023 Status Research & Development GmbH
# Copyright (c) 2019-2025 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
Expand All @@ -12,7 +12,7 @@ when fileExists("nimble.paths"):
include "nimble.paths"
# end Nimble config

when not defined(windows):
when not defined(rocksdb_dynamic_linking) and not defined(windows):
# use the C++ linker profile because it's a C++ library
when defined(macosx):
switch("clang.linkerexe", "clang++")
Expand Down
26 changes: 13 additions & 13 deletions rocksdb/lib/librocksdb.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2024 Status Research & Development GmbH
# Copyright 2018-2025 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)
Expand All @@ -22,6 +22,8 @@

## This file exposes the low-level C API of RocksDB

import std/[os, strutils]

{.push raises: [].}

type
Expand Down Expand Up @@ -87,29 +89,27 @@ type
rocksdb_memory_consumers_t* = object
rocksdb_wait_for_compact_options_t* = object

## DB operations

when defined(windows):
const librocksdb = "librocksdb.dll"
{.pragma: importrocks, importc, cdecl, dynlib: librocksdb.}
elif defined(macosx):
const librocksdb = "librocksdb.dylib"
else:
{.pragma: importrocks, importc, cdecl.}
const librocksdb = "librocksdb.so"

import std/[os, strutils]
when defined(rocksdb_dynamic_linking) or defined(windows):
{.push importc, cdecl, dynlib: librocksdb.}
else:
const
topLevelPath = currentSourcePath.parentDir().parentDir().parentDir()
libsDir = topLevelPath.replace('\\', '/') & "/build/lib"
libsDir = topLevelPath.replace('\\', '/') & "/build/lib/"

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

# This is require for static linking on windows
# when defined(windows):
# {.passl: "-lshlwapi -lrpcrt4".}
when defined(windows):
{.passl: "-lshlwapi -lrpcrt4".}

if defined(windows):
{.push importc, dynlib: librocksdb.}
{.push importc, cdecl.}

# Do I need importc for static lib?
include ./rocksdb_gen.nim
27 changes: 27 additions & 0 deletions scripts/build_shared_deps_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# Nim-RocksDB
# Copyright 2024-2025 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)
# * GPL license, version 2.0, ([LICENSE-GPLv2](LICENSE-GPLv2) or https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
#
# at your option. This file may not be copied, modified, or distributed except according to those terms.

set -e

cd "$(dirname "${BASH_SOURCE[0]}")"/..

REPO_DIR="${PWD}"
BUILD_DEST="${REPO_DIR}/build/"

git submodule update --init

${REPO_DIR}/vendor/vcpkg/bootstrap-vcpkg.sh -disableMetrics

${REPO_DIR}/vendor/vcpkg/vcpkg install rocksdb[lz4,zstd]:x64-linux-rocksdb --recurse --overlay-triplets=${REPO_DIR}/triplets

mkdir -p "${BUILD_DEST}"

cp "${REPO_DIR}/vendor/vcpkg/installed/x64-linux-rocksdb/lib/librocksdb.so" "${BUILD_DEST}/"
27 changes: 27 additions & 0 deletions scripts/build_shared_deps_osx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# Nim-RocksDB
# Copyright 2024-2025 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)
# * GPL license, version 2.0, ([LICENSE-GPLv2](LICENSE-GPLv2) or https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
#
# at your option. This file may not be copied, modified, or distributed except according to those terms.

set -e

cd "$(dirname "${BASH_SOURCE[0]}")"/..

REPO_DIR="${PWD}"
BUILD_DEST="${REPO_DIR}/build/"

git submodule update --init

${REPO_DIR}/vendor/vcpkg/bootstrap-vcpkg.sh -disableMetrics

${REPO_DIR}/vendor/vcpkg/vcpkg install rocksdb[lz4,zstd]:x64-osx-rocksdb --recurse --overlay-triplets=${REPO_DIR}/triplets

mkdir -p "${BUILD_DEST}"

cp "${REPO_DIR}/vendor/vcpkg/installed/x64-osx-rocksdb/lib/librocksdb.dylib" "${BUILD_DEST}/"

0 comments on commit e7b7c6e

Please sign in to comment.