From ab4e190d474eab1f62e93cd7794592c174f85162 Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 9 May 2024 10:18:06 +0200 Subject: [PATCH 01/31] copy in submodule and build.sh --- .gitmodules | 3 +++ build.sh | 16 ++++++++++++++++ sources | 1 + 3 files changed, 20 insertions(+) create mode 100644 .gitmodules create mode 100644 build.sh create mode 160000 sources diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..06101e6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "sources"] + path = sources + url = https://github.com/google/leveldb diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..60fb27c --- /dev/null +++ b/build.sh @@ -0,0 +1,16 @@ +#!/bin/bash +root=$(dirname "$0") + +# install nimterop, if not already installed +if ! [ -x "$(command -v toast)" ]; then + nimble install -y nimterop@0.6.13 +fi + +# generate nim wrapper with nimterop +toast \ + --compile="${root}/sources/randombytes.c" \ + --compile="${root}/sources/hazmat.c" \ + --pnim \ + --noHeader \ + "${root}/sources/randombytes.h" \ + "${root}/sources/hazmat.h" > "${root}/sss/cwrapper.nim" diff --git a/sources b/sources new file mode 160000 index 0000000..99b3c03 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +Subproject commit 99b3c03b3284f5886f9ef9a4ef703d57373e61be From f88e10b034213eedd4bde4b05c00eb50a075ee3f Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 9 May 2024 11:01:21 +0200 Subject: [PATCH 02/31] working on buildscript --- .github/workflows/main.yml | 77 ++++++++------------------------------ build.sh | 30 +++++++++++---- 2 files changed, 38 insertions(+), 69 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 831440d..55c9e9d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,66 +1,19 @@ -name: website +name: CI -#on: [push] # debugging only -on: - push: - tags: - - '[0-9]+.[0-9]+.[0-9]+' +on: [push, pull_request] jobs: - publish: - runs-on: ubuntu-latest + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macOS-latest, windows-latest] steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set output - id: vars - run: echo ::set-output name=tag::${GITHUB_REF:10} - - name: Cache choosenim - id: cache-choosenim - uses: actions/cache@v1 - with: - path: ~/.choosenim - key: ${{ runner.os }}-choosenim-stable - - name: Cache nimble - id: cache-nimble - uses: actions/cache@v1 - with: - path: ~/.nimble - key: ${{ runner.os }}-nimble-stable - - uses: jiro4989/setup-nim-action@v1 - with: - nim-version: 'stable' - - name: Install libsnappy - run: sudo apt-get install libsnappy1v5 - - name: Install leveldb c library - run: | - wget http://ftp.us.debian.org/debian/pool/main/l/leveldb/libleveldb1d_1.22-3_amd64.deb - wget http://ftp.us.debian.org/debian/pool/main/l/leveldb/libleveldb-dev_1.22-3_amd64.deb - sudo dpkg -i *.deb - - name: Build and test - env: - RELEASE_VERSION: ${{ steps.vars.outputs.tag }} - run: | - nimble build -Y - nimble test -Y - - name: Build doc - env: - RELEASE_VERSION: ${{ steps.vars.outputs.tag }} - run: | - # Due to bug https://github.com/nim-lang/Nim/issues/14281, compile the documentation separately. - nimble doc --project --git.url:https://github.com/$GITHUB_REPOSITORY --git.commit:$RELEASE_VERSION src/leveldb.nim - find . - # Deploying documentation of the latest version. - mkdir -p ./public - mv src/htmldocs/* public/ - cd ./public/ - ln -s ./leveldb.html index.html - cd ../ - - name: Deploy - if: success() - uses: crazy-max/ghaction-github-pages@v1.3.0 - with: - target_branch: gh-pages - build_dir: ./public - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/checkout@v2 + with: + submodules: true + - uses: iffy/install-nim@v3 + - name: Build + run: nimble install -y + - name: Test + run: nimble test -y diff --git a/build.sh b/build.sh index 60fb27c..1e02541 100644 --- a/build.sh +++ b/build.sh @@ -6,11 +6,27 @@ if ! [ -x "$(command -v toast)" ]; then nimble install -y nimterop@0.6.13 fi +cmake -S "${root}/sources" -B "${root}/build" + +# prelude: not needed? + +echo >> "${root}/leveldb.nim" + +# assemble files to be compiled: +extensions="c cc cpp" +for ext in ${extensions}; do + echo ${ext} + for file in `find "${root}/sources" -type f -name "*.${ext}"`; do + echo ${file} + done +done + # generate nim wrapper with nimterop -toast \ - --compile="${root}/sources/randombytes.c" \ - --compile="${root}/sources/hazmat.c" \ - --pnim \ - --noHeader \ - "${root}/sources/randombytes.h" \ - "${root}/sources/hazmat.h" > "${root}/sss/cwrapper.nim" +#toast \ +# --compile="${root}/sources/randombytes.c" \ +# --compile="${root}/sources/hazmat.c" \ +# --pnim \ +# --noHeader \ +# "${root}/sources/randombytes.h" \ +# "${root}/sources/hazmat.h" > "${root}/sss/cwrapper.nim" +~ ~ ~ \ No newline at end of file From e755ff4cbf862ee10ba7623b899be408c09067a0 Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 9 May 2024 11:26:26 +0200 Subject: [PATCH 03/31] build.sh begin toasting --- build.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/build.sh b/build.sh index 1e02541..b91acd5 100644 --- a/build.sh +++ b/build.sh @@ -15,18 +15,17 @@ echo >> "${root}/leveldb.nim" # assemble files to be compiled: extensions="c cc cpp" for ext in ${extensions}; do - echo ${ext} for file in `find "${root}/sources" -type f -name "*.${ext}"`; do - echo ${file} + compile="${compile} --compile=${file}" done done # generate nim wrapper with nimterop -#toast \ -# --compile="${root}/sources/randombytes.c" \ -# --compile="${root}/sources/hazmat.c" \ -# --pnim \ -# --noHeader \ -# "${root}/sources/randombytes.h" \ -# "${root}/sources/hazmat.h" > "${root}/sss/cwrapper.nim" -~ ~ ~ \ No newline at end of file +toast \ + $compile \ + --pnim \ + --preprocess \ + --noHeader \ + --includeDirs="${root}/sources/include/leveldb" \ + --includeDirs="${root}/build/include" \ + "${root}/sources/include/leveldb/c.h" >> "${root}/leveldb.nim" From f438417e72131029d47d9ee361093c6061e7d2d5 Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 9 May 2024 11:42:52 +0200 Subject: [PATCH 04/31] skip test files --- build.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index b91acd5..454b10f 100644 --- a/build.sh +++ b/build.sh @@ -10,13 +10,18 @@ cmake -S "${root}/sources" -B "${root}/build" # prelude: not needed? +rm "${root}/leveldb.nim" echo >> "${root}/leveldb.nim" # assemble files to be compiled: extensions="c cc cpp" for ext in ${extensions}; do for file in `find "${root}/sources" -type f -name "*.${ext}"`; do - compile="${compile} --compile=${file}" + if [[ $file == *"_test"* ]]; then + echo "Skip test file: ${file}" + else + compile="${compile} --compile=${file}" + fi done done @@ -26,6 +31,10 @@ toast \ --pnim \ --preprocess \ --noHeader \ - --includeDirs="${root}/sources/include/leveldb" \ + --includeDirs="${root}/sources" \ + --includeDirs="${root}/sources/helpers" \ + --includeDirs="${root}/sources/helpers/memenv" \ + --includeDirs="${root}/sources/port" \ + --includeDirs="${root}/sources/include" \ --includeDirs="${root}/build/include" \ "${root}/sources/include/leveldb/c.h" >> "${root}/leveldb.nim" From 90f998333a79e1f092a0177166db36d314b7e7ce Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 9 May 2024 11:58:18 +0200 Subject: [PATCH 05/31] removing unnecessary files --- build.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/build.sh b/build.sh index 454b10f..ab056c9 100644 --- a/build.sh +++ b/build.sh @@ -6,8 +6,16 @@ if ! [ -x "$(command -v toast)" ]; then nimble install -y nimterop@0.6.13 fi +git submodule deinit -f "${root}" +git submodule update --init --recursive --checkout "${root}" + cmake -S "${root}/sources" -B "${root}/build" +# Remove testing, benchmarking, third-party libraries. +rm -Rf "${root}/sources/third_party" +rm -Rf "${root}/sources/benchmarks" +rm "${root}/sources/util/testutil.cc" + # prelude: not needed? rm "${root}/leveldb.nim" @@ -20,6 +28,7 @@ for ext in ${extensions}; do if [[ $file == *"_test"* ]]; then echo "Skip test file: ${file}" else + echo "Include file: ${file}" compile="${compile} --compile=${file}" fi done @@ -38,3 +47,4 @@ toast \ --includeDirs="${root}/sources/include" \ --includeDirs="${root}/build/include" \ "${root}/sources/include/leveldb/c.h" >> "${root}/leveldb.nim" + \ No newline at end of file From 432ffc21523ceac6d5a52612113ba4539d64d386 Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 9 May 2024 14:05:01 +0200 Subject: [PATCH 06/31] sets up prelude --- build.sh | 20 +++++++++----------- prelude.nim | 7 +++++++ 2 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 prelude.nim diff --git a/build.sh b/build.sh index ab056c9..4ea1455 100644 --- a/build.sh +++ b/build.sh @@ -16,21 +16,18 @@ rm -Rf "${root}/sources/third_party" rm -Rf "${root}/sources/benchmarks" rm "${root}/sources/util/testutil.cc" -# prelude: not needed? - -rm "${root}/leveldb.nim" +# Prelude: +cat "${root}/prelude.nim" > "${root}/leveldb.nim" echo >> "${root}/leveldb.nim" # assemble files to be compiled: extensions="c cc cpp" for ext in ${extensions}; do - for file in `find "${root}/sources" -type f -name "*.${ext}"`; do - if [[ $file == *"_test"* ]]; then - echo "Skip test file: ${file}" - else - echo "Include file: ${file}" - compile="${compile} --compile=${file}" - fi + for file in `find "${root}/sources" -type f -name "*.${ext}" \ + | grep -v "_test" \ + | grep -v "env_windows.cc" \ + | grep -v "env_posix.cc"`; do + compile="${compile} --compile=${file}" done done @@ -46,5 +43,6 @@ toast \ --includeDirs="${root}/sources/port" \ --includeDirs="${root}/sources/include" \ --includeDirs="${root}/build/include" \ + --includeDirs="${root}/build/include/port" \ "${root}/sources/include/leveldb/c.h" >> "${root}/leveldb.nim" - \ No newline at end of file + diff --git a/prelude.nim b/prelude.nim new file mode 100644 index 0000000..8c3394a --- /dev/null +++ b/prelude.nim @@ -0,0 +1,7 @@ +when defined(windows): + {.compile: "./sources/util/env_windows.cc".} + {.passc: "-DLEVELDB_PLATFORM_POSIX".} + +when defined(posix): + {.compile: "./sources/util/env_posix.cc".} + {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} From e305ae74b50a7f41df0e92e9d98350aef7161835 Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 9 May 2024 14:11:08 +0200 Subject: [PATCH 07/31] excludes util-main from build --- build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 4ea1455..bf5ded3 100644 --- a/build.sh +++ b/build.sh @@ -26,7 +26,8 @@ for ext in ${extensions}; do for file in `find "${root}/sources" -type f -name "*.${ext}" \ | grep -v "_test" \ | grep -v "env_windows.cc" \ - | grep -v "env_posix.cc"`; do + | grep -v "env_posix.cc" \ + | grep -v "leveldbutil.cc"`; do compile="${compile} --compile=${file}" done done From 3f3ab38734e9b5cf14d5b520bec299320f3e6ec3 Mon Sep 17 00:00:00 2001 From: ThatBen Date: Thu, 9 May 2024 14:19:07 +0200 Subject: [PATCH 08/31] Builds library --- build.sh | 0 leveldb.nim | 293 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 293 insertions(+) mode change 100644 => 100755 build.sh create mode 100644 leveldb.nim diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 diff --git a/leveldb.nim b/leveldb.nim new file mode 100644 index 0000000..9b1b554 --- /dev/null +++ b/leveldb.nim @@ -0,0 +1,293 @@ +when defined(windows): + {.compile: "./sources/util/env_windows.cc".} + {.passc: "-DLEVELDB_PLATFORM_POSIX".} + +when defined(posix): + {.compile: "./sources/util/env_posix.cc".} + {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} + +# Generated @ 2024-05-09T14:13:25+02:00 +# Command line: +# /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./sources/helpers/memenv/memenv.cc --compile=./sources/table/table.cc --compile=./sources/table/iterator.cc --compile=./sources/table/merger.cc --compile=./sources/table/block.cc --compile=./sources/table/table_builder.cc --compile=./sources/table/format.cc --compile=./sources/table/two_level_iterator.cc --compile=./sources/table/filter_block.cc --compile=./sources/table/block_builder.cc --compile=./sources/db/write_batch.cc --compile=./sources/db/version_edit.cc --compile=./sources/db/dbformat.cc --compile=./sources/db/builder.cc --compile=./sources/db/repair.cc --compile=./sources/db/db_impl.cc --compile=./sources/db/dumpfile.cc --compile=./sources/db/filename.cc --compile=./sources/db/log_reader.cc --compile=./sources/db/memtable.cc --compile=./sources/db/table_cache.cc --compile=./sources/db/c.cc --compile=./sources/db/log_writer.cc --compile=./sources/db/version_set.cc --compile=./sources/db/db_iter.cc --compile=./sources/util/hash.cc --compile=./sources/util/options.cc --compile=./sources/util/comparator.cc --compile=./sources/util/coding.cc --compile=./sources/util/histogram.cc --compile=./sources/util/logging.cc --compile=./sources/util/cache.cc --compile=./sources/util/env.cc --compile=./sources/util/filter_policy.cc --compile=./sources/util/arena.cc --compile=./sources/util/bloom.cc --compile=./sources/util/crc32c.cc --compile=./sources/util/status.cc --pnim --preprocess --noHeader --includeDirs=./sources --includeDirs=./sources/helpers --includeDirs=./sources/helpers/memenv --includeDirs=./sources/port --includeDirs=./sources/include --includeDirs=./build/include --includeDirs=./build/include/port ./sources/include/leveldb/c.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passC: "-I./sources".} +{.passC: "-I./sources/helpers".} +{.passC: "-I./sources/helpers/memenv".} +{.passC: "-I./sources/port".} +{.passC: "-I./sources/include".} +{.passC: "-I./build/include".} +{.passC: "-I./build/include/port".} +{.compile: "./sources/helpers/memenv/memenv.cc".} +{.compile: "./sources/table/table.cc".} +{.compile: "./sources/table/iterator.cc".} +{.compile: "./sources/table/merger.cc".} +{.compile: "./sources/table/block.cc".} +{.compile: "./sources/table/table_builder.cc".} +{.compile: "./sources/table/format.cc".} +{.compile: "./sources/table/two_level_iterator.cc".} +{.compile: "./sources/table/filter_block.cc".} +{.compile: "./sources/table/block_builder.cc".} +{.compile: "./sources/db/write_batch.cc".} +{.compile: "./sources/db/version_edit.cc".} +{.compile: "./sources/db/dbformat.cc".} +{.compile: "./sources/db/builder.cc".} +{.compile: "./sources/db/repair.cc".} +{.compile: "./sources/db/db_impl.cc".} +{.compile: "./sources/db/dumpfile.cc".} +{.compile: "./sources/db/filename.cc".} +{.compile: "./sources/db/log_reader.cc".} +{.compile: "./sources/db/memtable.cc".} +{.compile: "./sources/db/table_cache.cc".} +{.compile: "./sources/db/c.cc".} +{.compile: "./sources/db/log_writer.cc".} +{.compile: "./sources/db/version_set.cc".} +{.compile: "./sources/db/db_iter.cc".} +{.compile: "./sources/util/hash.cc".} +{.compile: "./sources/util/options.cc".} +{.compile: "./sources/util/comparator.cc".} +{.compile: "./sources/util/coding.cc".} +{.compile: "./sources/util/histogram.cc".} +{.compile: "./sources/util/logging.cc".} +{.compile: "./sources/util/cache.cc".} +{.compile: "./sources/util/env.cc".} +{.compile: "./sources/util/filter_policy.cc".} +{.compile: "./sources/util/arena.cc".} +{.compile: "./sources/util/bloom.cc".} +{.compile: "./sources/util/crc32c.cc".} +{.compile: "./sources/util/status.cc".} +defineEnum(Enum_ch1) +const + leveldb_no_compression* = (0).cint + leveldb_snappy_compression* = (1).cint +type + leveldb_t* {.incompleteStruct.} = object + leveldb_cache_t* {.incompleteStruct.} = object + leveldb_comparator_t* {.incompleteStruct.} = object + leveldb_env_t* {.incompleteStruct.} = object + leveldb_filelock_t* {.incompleteStruct.} = object + leveldb_filterpolicy_t* {.incompleteStruct.} = object + leveldb_iterator_t* {.incompleteStruct.} = object + leveldb_logger_t* {.incompleteStruct.} = object + leveldb_options_t* {.incompleteStruct.} = object + leveldb_randomfile_t* {.incompleteStruct.} = object + leveldb_readoptions_t* {.incompleteStruct.} = object + leveldb_seqfile_t* {.incompleteStruct.} = object + leveldb_snapshot_t* {.incompleteStruct.} = object + leveldb_writablefile_t* {.incompleteStruct.} = object + leveldb_writebatch_t* {.incompleteStruct.} = object + leveldb_writeoptions_t* {.incompleteStruct.} = object +proc leveldb_open*(options: ptr leveldb_options_t; name: cstring; + errptr: ptr cstring): ptr leveldb_t {.importc, cdecl.} +proc leveldb_close*(db: ptr leveldb_t) {.importc, cdecl.} +proc leveldb_put*(db: ptr leveldb_t; options: ptr leveldb_writeoptions_t; + key: cstring; keylen: uint; val: cstring; vallen: uint; + errptr: ptr cstring) {.importc, cdecl.} +proc leveldb_delete*(db: ptr leveldb_t; options: ptr leveldb_writeoptions_t; + key: cstring; keylen: uint; errptr: ptr cstring) {.importc, + cdecl.} +proc leveldb_write*(db: ptr leveldb_t; options: ptr leveldb_writeoptions_t; + batch: ptr leveldb_writebatch_t; errptr: ptr cstring) {. + importc, cdecl.} +proc leveldb_get*(db: ptr leveldb_t; options: ptr leveldb_readoptions_t; + key: cstring; keylen: uint; vallen: ptr uint; + errptr: ptr cstring): cstring {.importc, cdecl.} + ## ``` + ## Returns NULL if not found. A malloc()ed array otherwise. + ## Stores the length of the array invallen. + ## ``` +proc leveldb_create_iterator*(db: ptr leveldb_t; + options: ptr leveldb_readoptions_t): ptr leveldb_iterator_t {. + importc, cdecl.} +proc leveldb_create_snapshot*(db: ptr leveldb_t): ptr leveldb_snapshot_t {. + importc, cdecl.} +proc leveldb_release_snapshot*(db: ptr leveldb_t; + snapshot: ptr leveldb_snapshot_t) {.importc, + cdecl.} +proc leveldb_property_value*(db: ptr leveldb_t; propname: cstring): cstring {. + importc, cdecl.} + ## ``` + ## Returns NULL if property name is unknown. + ## Else returns a pointer to a malloc()-ed null-terminated value. + ## ``` +proc leveldb_approximate_sizes*(db: ptr leveldb_t; num_ranges: cint; + range_start_key: ptr cstring; + range_start_key_len: ptr uint; + range_limit_key: ptr cstring; + range_limit_key_len: ptr uint; sizes: ptr uint64) {. + importc, cdecl.} +proc leveldb_compact_range*(db: ptr leveldb_t; start_key: cstring; + start_key_len: uint; limit_key: cstring; + limit_key_len: uint) {.importc, cdecl.} +proc leveldb_destroy_db*(options: ptr leveldb_options_t; name: cstring; + errptr: ptr cstring) {.importc, cdecl.} +proc leveldb_repair_db*(options: ptr leveldb_options_t; name: cstring; + errptr: ptr cstring) {.importc, cdecl.} +proc leveldb_iter_destroy*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} +proc leveldb_iter_valid*(a1: ptr leveldb_iterator_t): uint8 {.importc, cdecl.} +proc leveldb_iter_seek_to_first*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} +proc leveldb_iter_seek_to_last*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} +proc leveldb_iter_seek*(a1: ptr leveldb_iterator_t; k: cstring; klen: uint) {. + importc, cdecl.} +proc leveldb_iter_next*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} +proc leveldb_iter_prev*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} +proc leveldb_iter_key*(a1: ptr leveldb_iterator_t; klen: ptr uint): cstring {. + importc, cdecl.} +proc leveldb_iter_value*(a1: ptr leveldb_iterator_t; vlen: ptr uint): cstring {. + importc, cdecl.} +proc leveldb_iter_get_error*(a1: ptr leveldb_iterator_t; errptr: ptr cstring) {. + importc, cdecl.} +proc leveldb_writebatch_create*(): ptr leveldb_writebatch_t {.importc, cdecl.} +proc leveldb_writebatch_destroy*(a1: ptr leveldb_writebatch_t) {.importc, cdecl.} +proc leveldb_writebatch_clear*(a1: ptr leveldb_writebatch_t) {.importc, cdecl.} +proc leveldb_writebatch_put*(a1: ptr leveldb_writebatch_t; key: cstring; + klen: uint; val: cstring; vlen: uint) {.importc, + cdecl.} +proc leveldb_writebatch_delete*(a1: ptr leveldb_writebatch_t; key: cstring; + klen: uint) {.importc, cdecl.} +proc leveldb_writebatch_iterate*(a1: ptr leveldb_writebatch_t; state: pointer; + put: proc (a1: pointer; k: cstring; klen: uint; v: cstring; vlen: uint) {. + cdecl.}; deleted: proc (a1: pointer; k: cstring; klen: uint) {.cdecl.}) {. + importc, cdecl.} +proc leveldb_writebatch_append*(destination: ptr leveldb_writebatch_t; + source: ptr leveldb_writebatch_t) {.importc, + cdecl.} +proc leveldb_options_create*(): ptr leveldb_options_t {.importc, cdecl.} +proc leveldb_options_destroy*(a1: ptr leveldb_options_t) {.importc, cdecl.} +proc leveldb_options_set_comparator*(a1: ptr leveldb_options_t; + a2: ptr leveldb_comparator_t) {.importc, + cdecl.} +proc leveldb_options_set_filter_policy*(a1: ptr leveldb_options_t; + a2: ptr leveldb_filterpolicy_t) {. + importc, cdecl.} +proc leveldb_options_set_create_if_missing*(a1: ptr leveldb_options_t; a2: uint8) {. + importc, cdecl.} +proc leveldb_options_set_error_if_exists*(a1: ptr leveldb_options_t; a2: uint8) {. + importc, cdecl.} +proc leveldb_options_set_paranoid_checks*(a1: ptr leveldb_options_t; a2: uint8) {. + importc, cdecl.} +proc leveldb_options_set_env*(a1: ptr leveldb_options_t; a2: ptr leveldb_env_t) {. + importc, cdecl.} +proc leveldb_options_set_info_log*(a1: ptr leveldb_options_t; + a2: ptr leveldb_logger_t) {.importc, cdecl.} +proc leveldb_options_set_write_buffer_size*(a1: ptr leveldb_options_t; a2: uint) {. + importc, cdecl.} +proc leveldb_options_set_max_open_files*(a1: ptr leveldb_options_t; a2: cint) {. + importc, cdecl.} +proc leveldb_options_set_cache*(a1: ptr leveldb_options_t; + a2: ptr leveldb_cache_t) {.importc, cdecl.} +proc leveldb_options_set_block_size*(a1: ptr leveldb_options_t; a2: uint) {. + importc, cdecl.} +proc leveldb_options_set_block_restart_interval*(a1: ptr leveldb_options_t; + a2: cint) {.importc, cdecl.} +proc leveldb_options_set_max_file_size*(a1: ptr leveldb_options_t; a2: uint) {. + importc, cdecl.} +proc leveldb_options_set_compression*(a1: ptr leveldb_options_t; a2: cint) {. + importc, cdecl.} +proc leveldb_comparator_create*(state: pointer; + destructor: proc (a1: pointer) {.cdecl.}; + compare: proc (a1: pointer; a: cstring; alen: uint; b: cstring; blen: uint): cint {. + cdecl.}; name: proc (a1: pointer): cstring {.cdecl.}): ptr leveldb_comparator_t {. + importc, cdecl.} +proc leveldb_comparator_destroy*(a1: ptr leveldb_comparator_t) {.importc, cdecl.} +proc leveldb_filterpolicy_create*(state: pointer; + destructor: proc (a1: pointer) {.cdecl.}; + create_filter: proc (a1: pointer; key_array: ptr cstring; + key_length_array: ptr uint; num_keys: cint; + filter_length: ptr uint): cstring {.cdecl.}; + key_may_match: proc (a1: pointer; key: cstring; length: uint; + filter: cstring; filter_length: uint): uint8 {.cdecl.}; + name: proc (a1: pointer): cstring {.cdecl.}): ptr leveldb_filterpolicy_t {. + importc, cdecl.} +proc leveldb_filterpolicy_destroy*(a1: ptr leveldb_filterpolicy_t) {.importc, + cdecl.} +proc leveldb_filterpolicy_create_bloom*(bits_per_key: cint): ptr leveldb_filterpolicy_t {. + importc, cdecl.} +proc leveldb_readoptions_create*(): ptr leveldb_readoptions_t {.importc, cdecl.} +proc leveldb_readoptions_destroy*(a1: ptr leveldb_readoptions_t) {.importc, + cdecl.} +proc leveldb_readoptions_set_verify_checksums*(a1: ptr leveldb_readoptions_t; + a2: uint8) {.importc, cdecl.} +proc leveldb_readoptions_set_fill_cache*(a1: ptr leveldb_readoptions_t; + a2: uint8) {.importc, cdecl.} +proc leveldb_readoptions_set_snapshot*(a1: ptr leveldb_readoptions_t; + a2: ptr leveldb_snapshot_t) {.importc, + cdecl.} +proc leveldb_writeoptions_create*(): ptr leveldb_writeoptions_t {.importc, cdecl.} +proc leveldb_writeoptions_destroy*(a1: ptr leveldb_writeoptions_t) {.importc, + cdecl.} +proc leveldb_writeoptions_set_sync*(a1: ptr leveldb_writeoptions_t; a2: uint8) {. + importc, cdecl.} +proc leveldb_cache_create_lru*(capacity: uint): ptr leveldb_cache_t {.importc, + cdecl.} +proc leveldb_cache_destroy*(cache: ptr leveldb_cache_t) {.importc, cdecl.} +proc leveldb_create_default_env*(): ptr leveldb_env_t {.importc, cdecl.} +proc leveldb_env_destroy*(a1: ptr leveldb_env_t) {.importc, cdecl.} +proc leveldb_env_get_test_directory*(a1: ptr leveldb_env_t): cstring {.importc, + cdecl.} + ## ``` + ## If not NULL, the returned buffer must be released using leveldb_free(). + ## ``` +proc leveldb_free*(`ptr`: pointer) {.importc, cdecl.} + ## ``` + ## Utility + ## Calls free(ptr). + ## REQUIRES: ptr was malloc()-ed and returned by one of the routines + ## in this file. Note that in certain cases (typically on Windows), you + ## may need to call this routine instead of free(ptr) to dispose of + ## malloc()-ed memory returned by this library. + ## ``` +proc leveldb_major_version*(): cint {.importc, cdecl.} + ## ``` + ## Return the major version number for this release. + ## ``` +proc leveldb_minor_version*(): cint {.importc, cdecl.} + ## ``` + ## Return the minor version number for this release. + ## ``` +{.pop.} From 3d9a2d982db446fca9f40ff66fee6bb4d879c454 Mon Sep 17 00:00:00 2001 From: ThatBen Date: Thu, 9 May 2024 14:42:38 +0200 Subject: [PATCH 09/31] moves build output to /src/leveldb/raw.nim --- .gitignore | 1 - build.sh | 8 +- leveldb.nim | 293 ---------------------------- src/leveldb/raw.nim | 464 ++++++++++++++++++++++++++------------------ 4 files changed, 284 insertions(+), 482 deletions(-) delete mode 100644 leveldb.nim diff --git a/.gitignore b/.gitignore index 4444336..9cc6f1f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ nimcache/ /test.db/ /leveldb.e tests/packagetest/packagetest -src/leveldb tests/test src/htmldocs/ leveldbtool diff --git a/build.sh b/build.sh index bf5ded3..4278e35 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,8 @@ #!/bin/bash root=$(dirname "$0") +output="${root}/src/leveldb/raw.nim" + # install nimterop, if not already installed if ! [ -x "$(command -v toast)" ]; then nimble install -y nimterop@0.6.13 @@ -17,8 +19,8 @@ rm -Rf "${root}/sources/benchmarks" rm "${root}/sources/util/testutil.cc" # Prelude: -cat "${root}/prelude.nim" > "${root}/leveldb.nim" -echo >> "${root}/leveldb.nim" +cat "${root}/prelude.nim" > "${output}" +echo >> "${output}" # assemble files to be compiled: extensions="c cc cpp" @@ -45,5 +47,5 @@ toast \ --includeDirs="${root}/sources/include" \ --includeDirs="${root}/build/include" \ --includeDirs="${root}/build/include/port" \ - "${root}/sources/include/leveldb/c.h" >> "${root}/leveldb.nim" + "${root}/sources/include/leveldb/c.h" >> "${output}" diff --git a/leveldb.nim b/leveldb.nim deleted file mode 100644 index 9b1b554..0000000 --- a/leveldb.nim +++ /dev/null @@ -1,293 +0,0 @@ -when defined(windows): - {.compile: "./sources/util/env_windows.cc".} - {.passc: "-DLEVELDB_PLATFORM_POSIX".} - -when defined(posix): - {.compile: "./sources/util/env_posix.cc".} - {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} - -# Generated @ 2024-05-09T14:13:25+02:00 -# Command line: -# /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./sources/helpers/memenv/memenv.cc --compile=./sources/table/table.cc --compile=./sources/table/iterator.cc --compile=./sources/table/merger.cc --compile=./sources/table/block.cc --compile=./sources/table/table_builder.cc --compile=./sources/table/format.cc --compile=./sources/table/two_level_iterator.cc --compile=./sources/table/filter_block.cc --compile=./sources/table/block_builder.cc --compile=./sources/db/write_batch.cc --compile=./sources/db/version_edit.cc --compile=./sources/db/dbformat.cc --compile=./sources/db/builder.cc --compile=./sources/db/repair.cc --compile=./sources/db/db_impl.cc --compile=./sources/db/dumpfile.cc --compile=./sources/db/filename.cc --compile=./sources/db/log_reader.cc --compile=./sources/db/memtable.cc --compile=./sources/db/table_cache.cc --compile=./sources/db/c.cc --compile=./sources/db/log_writer.cc --compile=./sources/db/version_set.cc --compile=./sources/db/db_iter.cc --compile=./sources/util/hash.cc --compile=./sources/util/options.cc --compile=./sources/util/comparator.cc --compile=./sources/util/coding.cc --compile=./sources/util/histogram.cc --compile=./sources/util/logging.cc --compile=./sources/util/cache.cc --compile=./sources/util/env.cc --compile=./sources/util/filter_policy.cc --compile=./sources/util/arena.cc --compile=./sources/util/bloom.cc --compile=./sources/util/crc32c.cc --compile=./sources/util/status.cc --pnim --preprocess --noHeader --includeDirs=./sources --includeDirs=./sources/helpers --includeDirs=./sources/helpers/memenv --includeDirs=./sources/port --includeDirs=./sources/include --includeDirs=./build/include --includeDirs=./build/include/port ./sources/include/leveldb/c.h - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - - -{.experimental: "codeReordering".} -{.passC: "-I./sources".} -{.passC: "-I./sources/helpers".} -{.passC: "-I./sources/helpers/memenv".} -{.passC: "-I./sources/port".} -{.passC: "-I./sources/include".} -{.passC: "-I./build/include".} -{.passC: "-I./build/include/port".} -{.compile: "./sources/helpers/memenv/memenv.cc".} -{.compile: "./sources/table/table.cc".} -{.compile: "./sources/table/iterator.cc".} -{.compile: "./sources/table/merger.cc".} -{.compile: "./sources/table/block.cc".} -{.compile: "./sources/table/table_builder.cc".} -{.compile: "./sources/table/format.cc".} -{.compile: "./sources/table/two_level_iterator.cc".} -{.compile: "./sources/table/filter_block.cc".} -{.compile: "./sources/table/block_builder.cc".} -{.compile: "./sources/db/write_batch.cc".} -{.compile: "./sources/db/version_edit.cc".} -{.compile: "./sources/db/dbformat.cc".} -{.compile: "./sources/db/builder.cc".} -{.compile: "./sources/db/repair.cc".} -{.compile: "./sources/db/db_impl.cc".} -{.compile: "./sources/db/dumpfile.cc".} -{.compile: "./sources/db/filename.cc".} -{.compile: "./sources/db/log_reader.cc".} -{.compile: "./sources/db/memtable.cc".} -{.compile: "./sources/db/table_cache.cc".} -{.compile: "./sources/db/c.cc".} -{.compile: "./sources/db/log_writer.cc".} -{.compile: "./sources/db/version_set.cc".} -{.compile: "./sources/db/db_iter.cc".} -{.compile: "./sources/util/hash.cc".} -{.compile: "./sources/util/options.cc".} -{.compile: "./sources/util/comparator.cc".} -{.compile: "./sources/util/coding.cc".} -{.compile: "./sources/util/histogram.cc".} -{.compile: "./sources/util/logging.cc".} -{.compile: "./sources/util/cache.cc".} -{.compile: "./sources/util/env.cc".} -{.compile: "./sources/util/filter_policy.cc".} -{.compile: "./sources/util/arena.cc".} -{.compile: "./sources/util/bloom.cc".} -{.compile: "./sources/util/crc32c.cc".} -{.compile: "./sources/util/status.cc".} -defineEnum(Enum_ch1) -const - leveldb_no_compression* = (0).cint - leveldb_snappy_compression* = (1).cint -type - leveldb_t* {.incompleteStruct.} = object - leveldb_cache_t* {.incompleteStruct.} = object - leveldb_comparator_t* {.incompleteStruct.} = object - leveldb_env_t* {.incompleteStruct.} = object - leveldb_filelock_t* {.incompleteStruct.} = object - leveldb_filterpolicy_t* {.incompleteStruct.} = object - leveldb_iterator_t* {.incompleteStruct.} = object - leveldb_logger_t* {.incompleteStruct.} = object - leveldb_options_t* {.incompleteStruct.} = object - leveldb_randomfile_t* {.incompleteStruct.} = object - leveldb_readoptions_t* {.incompleteStruct.} = object - leveldb_seqfile_t* {.incompleteStruct.} = object - leveldb_snapshot_t* {.incompleteStruct.} = object - leveldb_writablefile_t* {.incompleteStruct.} = object - leveldb_writebatch_t* {.incompleteStruct.} = object - leveldb_writeoptions_t* {.incompleteStruct.} = object -proc leveldb_open*(options: ptr leveldb_options_t; name: cstring; - errptr: ptr cstring): ptr leveldb_t {.importc, cdecl.} -proc leveldb_close*(db: ptr leveldb_t) {.importc, cdecl.} -proc leveldb_put*(db: ptr leveldb_t; options: ptr leveldb_writeoptions_t; - key: cstring; keylen: uint; val: cstring; vallen: uint; - errptr: ptr cstring) {.importc, cdecl.} -proc leveldb_delete*(db: ptr leveldb_t; options: ptr leveldb_writeoptions_t; - key: cstring; keylen: uint; errptr: ptr cstring) {.importc, - cdecl.} -proc leveldb_write*(db: ptr leveldb_t; options: ptr leveldb_writeoptions_t; - batch: ptr leveldb_writebatch_t; errptr: ptr cstring) {. - importc, cdecl.} -proc leveldb_get*(db: ptr leveldb_t; options: ptr leveldb_readoptions_t; - key: cstring; keylen: uint; vallen: ptr uint; - errptr: ptr cstring): cstring {.importc, cdecl.} - ## ``` - ## Returns NULL if not found. A malloc()ed array otherwise. - ## Stores the length of the array invallen. - ## ``` -proc leveldb_create_iterator*(db: ptr leveldb_t; - options: ptr leveldb_readoptions_t): ptr leveldb_iterator_t {. - importc, cdecl.} -proc leveldb_create_snapshot*(db: ptr leveldb_t): ptr leveldb_snapshot_t {. - importc, cdecl.} -proc leveldb_release_snapshot*(db: ptr leveldb_t; - snapshot: ptr leveldb_snapshot_t) {.importc, - cdecl.} -proc leveldb_property_value*(db: ptr leveldb_t; propname: cstring): cstring {. - importc, cdecl.} - ## ``` - ## Returns NULL if property name is unknown. - ## Else returns a pointer to a malloc()-ed null-terminated value. - ## ``` -proc leveldb_approximate_sizes*(db: ptr leveldb_t; num_ranges: cint; - range_start_key: ptr cstring; - range_start_key_len: ptr uint; - range_limit_key: ptr cstring; - range_limit_key_len: ptr uint; sizes: ptr uint64) {. - importc, cdecl.} -proc leveldb_compact_range*(db: ptr leveldb_t; start_key: cstring; - start_key_len: uint; limit_key: cstring; - limit_key_len: uint) {.importc, cdecl.} -proc leveldb_destroy_db*(options: ptr leveldb_options_t; name: cstring; - errptr: ptr cstring) {.importc, cdecl.} -proc leveldb_repair_db*(options: ptr leveldb_options_t; name: cstring; - errptr: ptr cstring) {.importc, cdecl.} -proc leveldb_iter_destroy*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} -proc leveldb_iter_valid*(a1: ptr leveldb_iterator_t): uint8 {.importc, cdecl.} -proc leveldb_iter_seek_to_first*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} -proc leveldb_iter_seek_to_last*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} -proc leveldb_iter_seek*(a1: ptr leveldb_iterator_t; k: cstring; klen: uint) {. - importc, cdecl.} -proc leveldb_iter_next*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} -proc leveldb_iter_prev*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} -proc leveldb_iter_key*(a1: ptr leveldb_iterator_t; klen: ptr uint): cstring {. - importc, cdecl.} -proc leveldb_iter_value*(a1: ptr leveldb_iterator_t; vlen: ptr uint): cstring {. - importc, cdecl.} -proc leveldb_iter_get_error*(a1: ptr leveldb_iterator_t; errptr: ptr cstring) {. - importc, cdecl.} -proc leveldb_writebatch_create*(): ptr leveldb_writebatch_t {.importc, cdecl.} -proc leveldb_writebatch_destroy*(a1: ptr leveldb_writebatch_t) {.importc, cdecl.} -proc leveldb_writebatch_clear*(a1: ptr leveldb_writebatch_t) {.importc, cdecl.} -proc leveldb_writebatch_put*(a1: ptr leveldb_writebatch_t; key: cstring; - klen: uint; val: cstring; vlen: uint) {.importc, - cdecl.} -proc leveldb_writebatch_delete*(a1: ptr leveldb_writebatch_t; key: cstring; - klen: uint) {.importc, cdecl.} -proc leveldb_writebatch_iterate*(a1: ptr leveldb_writebatch_t; state: pointer; - put: proc (a1: pointer; k: cstring; klen: uint; v: cstring; vlen: uint) {. - cdecl.}; deleted: proc (a1: pointer; k: cstring; klen: uint) {.cdecl.}) {. - importc, cdecl.} -proc leveldb_writebatch_append*(destination: ptr leveldb_writebatch_t; - source: ptr leveldb_writebatch_t) {.importc, - cdecl.} -proc leveldb_options_create*(): ptr leveldb_options_t {.importc, cdecl.} -proc leveldb_options_destroy*(a1: ptr leveldb_options_t) {.importc, cdecl.} -proc leveldb_options_set_comparator*(a1: ptr leveldb_options_t; - a2: ptr leveldb_comparator_t) {.importc, - cdecl.} -proc leveldb_options_set_filter_policy*(a1: ptr leveldb_options_t; - a2: ptr leveldb_filterpolicy_t) {. - importc, cdecl.} -proc leveldb_options_set_create_if_missing*(a1: ptr leveldb_options_t; a2: uint8) {. - importc, cdecl.} -proc leveldb_options_set_error_if_exists*(a1: ptr leveldb_options_t; a2: uint8) {. - importc, cdecl.} -proc leveldb_options_set_paranoid_checks*(a1: ptr leveldb_options_t; a2: uint8) {. - importc, cdecl.} -proc leveldb_options_set_env*(a1: ptr leveldb_options_t; a2: ptr leveldb_env_t) {. - importc, cdecl.} -proc leveldb_options_set_info_log*(a1: ptr leveldb_options_t; - a2: ptr leveldb_logger_t) {.importc, cdecl.} -proc leveldb_options_set_write_buffer_size*(a1: ptr leveldb_options_t; a2: uint) {. - importc, cdecl.} -proc leveldb_options_set_max_open_files*(a1: ptr leveldb_options_t; a2: cint) {. - importc, cdecl.} -proc leveldb_options_set_cache*(a1: ptr leveldb_options_t; - a2: ptr leveldb_cache_t) {.importc, cdecl.} -proc leveldb_options_set_block_size*(a1: ptr leveldb_options_t; a2: uint) {. - importc, cdecl.} -proc leveldb_options_set_block_restart_interval*(a1: ptr leveldb_options_t; - a2: cint) {.importc, cdecl.} -proc leveldb_options_set_max_file_size*(a1: ptr leveldb_options_t; a2: uint) {. - importc, cdecl.} -proc leveldb_options_set_compression*(a1: ptr leveldb_options_t; a2: cint) {. - importc, cdecl.} -proc leveldb_comparator_create*(state: pointer; - destructor: proc (a1: pointer) {.cdecl.}; - compare: proc (a1: pointer; a: cstring; alen: uint; b: cstring; blen: uint): cint {. - cdecl.}; name: proc (a1: pointer): cstring {.cdecl.}): ptr leveldb_comparator_t {. - importc, cdecl.} -proc leveldb_comparator_destroy*(a1: ptr leveldb_comparator_t) {.importc, cdecl.} -proc leveldb_filterpolicy_create*(state: pointer; - destructor: proc (a1: pointer) {.cdecl.}; - create_filter: proc (a1: pointer; key_array: ptr cstring; - key_length_array: ptr uint; num_keys: cint; - filter_length: ptr uint): cstring {.cdecl.}; - key_may_match: proc (a1: pointer; key: cstring; length: uint; - filter: cstring; filter_length: uint): uint8 {.cdecl.}; - name: proc (a1: pointer): cstring {.cdecl.}): ptr leveldb_filterpolicy_t {. - importc, cdecl.} -proc leveldb_filterpolicy_destroy*(a1: ptr leveldb_filterpolicy_t) {.importc, - cdecl.} -proc leveldb_filterpolicy_create_bloom*(bits_per_key: cint): ptr leveldb_filterpolicy_t {. - importc, cdecl.} -proc leveldb_readoptions_create*(): ptr leveldb_readoptions_t {.importc, cdecl.} -proc leveldb_readoptions_destroy*(a1: ptr leveldb_readoptions_t) {.importc, - cdecl.} -proc leveldb_readoptions_set_verify_checksums*(a1: ptr leveldb_readoptions_t; - a2: uint8) {.importc, cdecl.} -proc leveldb_readoptions_set_fill_cache*(a1: ptr leveldb_readoptions_t; - a2: uint8) {.importc, cdecl.} -proc leveldb_readoptions_set_snapshot*(a1: ptr leveldb_readoptions_t; - a2: ptr leveldb_snapshot_t) {.importc, - cdecl.} -proc leveldb_writeoptions_create*(): ptr leveldb_writeoptions_t {.importc, cdecl.} -proc leveldb_writeoptions_destroy*(a1: ptr leveldb_writeoptions_t) {.importc, - cdecl.} -proc leveldb_writeoptions_set_sync*(a1: ptr leveldb_writeoptions_t; a2: uint8) {. - importc, cdecl.} -proc leveldb_cache_create_lru*(capacity: uint): ptr leveldb_cache_t {.importc, - cdecl.} -proc leveldb_cache_destroy*(cache: ptr leveldb_cache_t) {.importc, cdecl.} -proc leveldb_create_default_env*(): ptr leveldb_env_t {.importc, cdecl.} -proc leveldb_env_destroy*(a1: ptr leveldb_env_t) {.importc, cdecl.} -proc leveldb_env_get_test_directory*(a1: ptr leveldb_env_t): cstring {.importc, - cdecl.} - ## ``` - ## If not NULL, the returned buffer must be released using leveldb_free(). - ## ``` -proc leveldb_free*(`ptr`: pointer) {.importc, cdecl.} - ## ``` - ## Utility - ## Calls free(ptr). - ## REQUIRES: ptr was malloc()-ed and returned by one of the routines - ## in this file. Note that in certain cases (typically on Windows), you - ## may need to call this routine instead of free(ptr) to dispose of - ## malloc()-ed memory returned by this library. - ## ``` -proc leveldb_major_version*(): cint {.importc, cdecl.} - ## ``` - ## Return the major version number for this release. - ## ``` -proc leveldb_minor_version*(): cint {.importc, cdecl.} - ## ``` - ## Return the minor version number for this release. - ## ``` -{.pop.} diff --git a/src/leveldb/raw.nim b/src/leveldb/raw.nim index 513692b..9b1b554 100644 --- a/src/leveldb/raw.nim +++ b/src/leveldb/raw.nim @@ -1,199 +1,293 @@ -## Copyright (c) 2011 The LevelDB Authors. All rights reserved. -## Use of this source code is governed by a BSD-style license that can be -## found in the LICENSE file. See the AUTHORS file for names of contributors. -## -## C bindings for leveldb. May be useful as a stable ABI that can be -## used by programs that keep leveldb in a shared library, or for -## a JNI api. -## -## Does not support: -## . getters for the option types -## . custom comparators that implement key shortening -## . custom iter, db, env, cache implementations using just the C bindings -## -## Some conventions: -## -## (1) We expose just opaque struct pointers and functions to clients. -## This allows us to change internal representations without having to -## recompile clients. -## -## (2) For simplicity, there is no equivalent to the Slice type. Instead, -## the caller has to pass the pointer and length as separate -## arguments. -## -## (3) Errors are represented by a null-terminated c string. NULL -## means no error. All operations that can raise an error are passed -## a "char** errptr" as the last argument. One of the following must -## be true on entry: -## errptr == NULL -## errptr points to a malloc()ed null-terminated error message -## (On Windows, \*errptr must have been malloc()-ed by this library.) -## On success, a leveldb routine leaves \*errptr unchanged. -## On failure, leveldb frees the old value of \*errptr and -## set \*errptr to a malloc()ed error message. -## -## (4) Bools have the type uint8_t (0 == false; rest == true) -## -## (5) All of the pointer arguments must be non-NULL. -## +when defined(windows): + {.compile: "./sources/util/env_windows.cc".} + {.passc: "-DLEVELDB_PLATFORM_POSIX".} -{.passl: "-lleveldb".} +when defined(posix): + {.compile: "./sources/util/env_posix.cc".} + {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} -## # Exported types +# Generated @ 2024-05-09T14:13:25+02:00 +# Command line: +# /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./sources/helpers/memenv/memenv.cc --compile=./sources/table/table.cc --compile=./sources/table/iterator.cc --compile=./sources/table/merger.cc --compile=./sources/table/block.cc --compile=./sources/table/table_builder.cc --compile=./sources/table/format.cc --compile=./sources/table/two_level_iterator.cc --compile=./sources/table/filter_block.cc --compile=./sources/table/block_builder.cc --compile=./sources/db/write_batch.cc --compile=./sources/db/version_edit.cc --compile=./sources/db/dbformat.cc --compile=./sources/db/builder.cc --compile=./sources/db/repair.cc --compile=./sources/db/db_impl.cc --compile=./sources/db/dumpfile.cc --compile=./sources/db/filename.cc --compile=./sources/db/log_reader.cc --compile=./sources/db/memtable.cc --compile=./sources/db/table_cache.cc --compile=./sources/db/c.cc --compile=./sources/db/log_writer.cc --compile=./sources/db/version_set.cc --compile=./sources/db/db_iter.cc --compile=./sources/util/hash.cc --compile=./sources/util/options.cc --compile=./sources/util/comparator.cc --compile=./sources/util/coding.cc --compile=./sources/util/histogram.cc --compile=./sources/util/logging.cc --compile=./sources/util/cache.cc --compile=./sources/util/env.cc --compile=./sources/util/filter_policy.cc --compile=./sources/util/arena.cc --compile=./sources/util/bloom.cc --compile=./sources/util/crc32c.cc --compile=./sources/util/status.cc --pnim --preprocess --noHeader --includeDirs=./sources --includeDirs=./sources/helpers --includeDirs=./sources/helpers/memenv --includeDirs=./sources/port --includeDirs=./sources/include --includeDirs=./build/include --includeDirs=./build/include/port ./sources/include/leveldb/c.h -type - leveldb_options_t* = object - leveldb_writeoptions_t* = object - leveldb_readoptions_t* = object - leveldb_writebatch_t* = object - leveldb_iterator_t* = object - leveldb_snapshot_t* = object - leveldb_comparator_t* = object - leveldb_filterpolicy_t* = object - leveldb_env_t* = object - leveldb_logger_t* = object - leveldb_cache_t* = object - leveldb_t* = object +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros -## DB operations +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) -proc leveldb_open*(options: ptr leveldb_options_t; name: cstring; errptr: ptr cstring): ptr leveldb_t {.importc.} -proc leveldb_close*(db: ptr leveldb_t) {.importc.} -proc leveldb_put*(db: ptr leveldb_t; options: ptr leveldb_writeoptions_t; key: cstring; - keylen: csize_t; val: cstring; vallen: csize_t; errptr: ptr cstring) {.importc.} -proc leveldb_delete*(db: ptr leveldb_t; options: ptr leveldb_writeoptions_t; - key: cstring; keylen: csize_t; errptr: ptr cstring) {.importc.} -proc leveldb_write*(db: ptr leveldb_t; options: ptr leveldb_writeoptions_t; - batch: ptr leveldb_writebatch_t; errptr: ptr cstring) {.importc.} -## Returns NULL if not found. A malloc()ed array otherwise. -## Stores the length of the array in \*vallen. + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint -proc leveldb_get*(db: ptr leveldb_t; options: ptr leveldb_readoptions_t; key: cstring; - keylen: csize_t; vallen: ptr csize_t; errptr: ptr cstring): cstring {.importc.} -proc leveldb_create_iterator*(db: ptr leveldb_t; options: ptr leveldb_readoptions_t): ptr leveldb_iterator_t {.importc.} -proc leveldb_create_snapshot*(db: ptr leveldb_t): ptr leveldb_snapshot_t {.importc.} -proc leveldb_release_snapshot*(db: ptr leveldb_t; snapshot: ptr leveldb_snapshot_t) {.importc.} -## Returns NULL if property name is unknown. -## Else returns a pointer to a malloc()-ed null-terminated value. + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) -proc leveldb_property_value*(db: ptr leveldb_t; propname: cstring): cstring {.importc.} -proc leveldb_approximate_sizes*(db: ptr leveldb_t; num_ranges: cint; - range_start_key: ptr cstring; - range_start_key_len: ptr csize_t; - range_limit_key: ptr cstring; - range_limit_key_len: ptr csize_t; sizes: ptr uint64) {.importc.} -proc leveldb_compact_range*(db: ptr leveldb_t; start_key: cstring; - start_key_len: csize_t; limit_key: cstring; - limit_key_len: csize_t) {.importc.} -## Management operations + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) -proc leveldb_destroy_db*(options: ptr leveldb_options_t; name: cstring; - errptr: ptr cstring) {.importc.} -proc leveldb_repair_db*(options: ptr leveldb_options_t; name: cstring; - errptr: ptr cstring) {.importc.} -## Iterator + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} -proc leveldb_iter_destroy*(a1: ptr leveldb_iterator_t) {.importc.} -proc leveldb_iter_valid*(a1: ptr leveldb_iterator_t): uint8 {.importc.} -proc leveldb_iter_seek_to_first*(a1: ptr leveldb_iterator_t) {.importc.} -proc leveldb_iter_seek_to_last*(a1: ptr leveldb_iterator_t) {.importc.} -proc leveldb_iter_seek*(a1: ptr leveldb_iterator_t; k: cstring; klen: csize_t) {.importc.} -proc leveldb_iter_next*(a1: ptr leveldb_iterator_t) {.importc.} -proc leveldb_iter_prev*(a1: ptr leveldb_iterator_t) {.importc.} -proc leveldb_iter_key*(a1: ptr leveldb_iterator_t; klen: ptr csize_t): cstring {.importc.} -proc leveldb_iter_value*(a1: ptr leveldb_iterator_t; vlen: ptr csize_t): cstring {.importc.} -proc leveldb_iter_get_error*(a1: ptr leveldb_iterator_t; errptr: ptr cstring) {.importc.} -## Write batch -proc leveldb_writebatch_create*(): ptr leveldb_writebatch_t {.importc.} -proc leveldb_writebatch_destroy*(a1: ptr leveldb_writebatch_t) {.importc.} -proc leveldb_writebatch_clear*(a1: ptr leveldb_writebatch_t) {.importc.} -proc leveldb_writebatch_put*(a1: ptr leveldb_writebatch_t; key: cstring; klen: csize_t; - val: cstring; vlen: csize_t) {.importc.} -proc leveldb_writebatch_delete*(a1: ptr leveldb_writebatch_t; key: cstring; - klen: csize_t) {.importc.} -proc leveldb_writebatch_iterate*(a1: ptr leveldb_writebatch_t; state: pointer; put: proc ( - a1: pointer; k: cstring; klen: csize_t; v: cstring; vlen: csize_t); deleted: proc ( - a1: pointer; k: cstring; klen: csize_t)) {.importc.} -proc leveldb_writebatch_append*(destination: ptr leveldb_writebatch_t; - source: ptr leveldb_writebatch_t) {.importc.} -## Options - -proc leveldb_options_create*(): ptr leveldb_options_t {.importc.} -proc leveldb_options_destroy*(a1: ptr leveldb_options_t) {.importc.} -proc leveldb_options_set_comparator*(a1: ptr leveldb_options_t; - a2: ptr leveldb_comparator_t) {.importc.} -proc leveldb_options_set_filter_policy*(a1: ptr leveldb_options_t; - a2: ptr leveldb_filterpolicy_t) {.importc.} -proc leveldb_options_set_create_if_missing*(a1: ptr leveldb_options_t; a2: uint8) {.importc.} -proc leveldb_options_set_error_if_exists*(a1: ptr leveldb_options_t; a2: uint8) {.importc.} -proc leveldb_options_set_paranoid_checks*(a1: ptr leveldb_options_t; a2: uint8) {.importc.} -proc leveldb_options_set_env*(a1: ptr leveldb_options_t; a2: ptr leveldb_env_t) {.importc.} -proc leveldb_options_set_info_log*(a1: ptr leveldb_options_t; - a2: ptr leveldb_logger_t) {.importc.} -proc leveldb_options_set_write_buffer_size*(a1: ptr leveldb_options_t; a2: csize_t) {.importc.} -proc leveldb_options_set_max_open_files*(a1: ptr leveldb_options_t; a2: cint) {.importc.} -proc leveldb_options_set_cache*(a1: ptr leveldb_options_t; a2: ptr leveldb_cache_t) {.importc.} -proc leveldb_options_set_block_size*(a1: ptr leveldb_options_t; a2: csize_t) {.importc.} -proc leveldb_options_set_block_restart_interval*(a1: ptr leveldb_options_t; a2: cint) {.importc.} -proc leveldb_options_set_max_file_size*(a1: ptr leveldb_options_t; a2: csize_t) {.importc.} +{.experimental: "codeReordering".} +{.passC: "-I./sources".} +{.passC: "-I./sources/helpers".} +{.passC: "-I./sources/helpers/memenv".} +{.passC: "-I./sources/port".} +{.passC: "-I./sources/include".} +{.passC: "-I./build/include".} +{.passC: "-I./build/include/port".} +{.compile: "./sources/helpers/memenv/memenv.cc".} +{.compile: "./sources/table/table.cc".} +{.compile: "./sources/table/iterator.cc".} +{.compile: "./sources/table/merger.cc".} +{.compile: "./sources/table/block.cc".} +{.compile: "./sources/table/table_builder.cc".} +{.compile: "./sources/table/format.cc".} +{.compile: "./sources/table/two_level_iterator.cc".} +{.compile: "./sources/table/filter_block.cc".} +{.compile: "./sources/table/block_builder.cc".} +{.compile: "./sources/db/write_batch.cc".} +{.compile: "./sources/db/version_edit.cc".} +{.compile: "./sources/db/dbformat.cc".} +{.compile: "./sources/db/builder.cc".} +{.compile: "./sources/db/repair.cc".} +{.compile: "./sources/db/db_impl.cc".} +{.compile: "./sources/db/dumpfile.cc".} +{.compile: "./sources/db/filename.cc".} +{.compile: "./sources/db/log_reader.cc".} +{.compile: "./sources/db/memtable.cc".} +{.compile: "./sources/db/table_cache.cc".} +{.compile: "./sources/db/c.cc".} +{.compile: "./sources/db/log_writer.cc".} +{.compile: "./sources/db/version_set.cc".} +{.compile: "./sources/db/db_iter.cc".} +{.compile: "./sources/util/hash.cc".} +{.compile: "./sources/util/options.cc".} +{.compile: "./sources/util/comparator.cc".} +{.compile: "./sources/util/coding.cc".} +{.compile: "./sources/util/histogram.cc".} +{.compile: "./sources/util/logging.cc".} +{.compile: "./sources/util/cache.cc".} +{.compile: "./sources/util/env.cc".} +{.compile: "./sources/util/filter_policy.cc".} +{.compile: "./sources/util/arena.cc".} +{.compile: "./sources/util/bloom.cc".} +{.compile: "./sources/util/crc32c.cc".} +{.compile: "./sources/util/status.cc".} +defineEnum(Enum_ch1) const - leveldb_no_compression* = 0 - leveldb_snappy_compression* = 1 - -proc leveldb_options_set_compression*(a1: ptr leveldb_options_t; a2: cint) {.importc.} -## Comparator - -proc leveldb_comparator_create*(state: pointer; destructor: proc (a1: pointer); compare: proc ( - a1: pointer; a: cstring; alen: csize_t; b: cstring; blen: csize_t): cint; - name: proc (a1: pointer): cstring): ptr leveldb_comparator_t {.importc.} -proc leveldb_comparator_destroy*(a1: ptr leveldb_comparator_t) {.importc.} -## Filter policy - -proc leveldb_filterpolicy_create*(state: pointer; destructor: proc (a1: pointer); + leveldb_no_compression* = (0).cint + leveldb_snappy_compression* = (1).cint +type + leveldb_t* {.incompleteStruct.} = object + leveldb_cache_t* {.incompleteStruct.} = object + leveldb_comparator_t* {.incompleteStruct.} = object + leveldb_env_t* {.incompleteStruct.} = object + leveldb_filelock_t* {.incompleteStruct.} = object + leveldb_filterpolicy_t* {.incompleteStruct.} = object + leveldb_iterator_t* {.incompleteStruct.} = object + leveldb_logger_t* {.incompleteStruct.} = object + leveldb_options_t* {.incompleteStruct.} = object + leveldb_randomfile_t* {.incompleteStruct.} = object + leveldb_readoptions_t* {.incompleteStruct.} = object + leveldb_seqfile_t* {.incompleteStruct.} = object + leveldb_snapshot_t* {.incompleteStruct.} = object + leveldb_writablefile_t* {.incompleteStruct.} = object + leveldb_writebatch_t* {.incompleteStruct.} = object + leveldb_writeoptions_t* {.incompleteStruct.} = object +proc leveldb_open*(options: ptr leveldb_options_t; name: cstring; + errptr: ptr cstring): ptr leveldb_t {.importc, cdecl.} +proc leveldb_close*(db: ptr leveldb_t) {.importc, cdecl.} +proc leveldb_put*(db: ptr leveldb_t; options: ptr leveldb_writeoptions_t; + key: cstring; keylen: uint; val: cstring; vallen: uint; + errptr: ptr cstring) {.importc, cdecl.} +proc leveldb_delete*(db: ptr leveldb_t; options: ptr leveldb_writeoptions_t; + key: cstring; keylen: uint; errptr: ptr cstring) {.importc, + cdecl.} +proc leveldb_write*(db: ptr leveldb_t; options: ptr leveldb_writeoptions_t; + batch: ptr leveldb_writebatch_t; errptr: ptr cstring) {. + importc, cdecl.} +proc leveldb_get*(db: ptr leveldb_t; options: ptr leveldb_readoptions_t; + key: cstring; keylen: uint; vallen: ptr uint; + errptr: ptr cstring): cstring {.importc, cdecl.} + ## ``` + ## Returns NULL if not found. A malloc()ed array otherwise. + ## Stores the length of the array invallen. + ## ``` +proc leveldb_create_iterator*(db: ptr leveldb_t; + options: ptr leveldb_readoptions_t): ptr leveldb_iterator_t {. + importc, cdecl.} +proc leveldb_create_snapshot*(db: ptr leveldb_t): ptr leveldb_snapshot_t {. + importc, cdecl.} +proc leveldb_release_snapshot*(db: ptr leveldb_t; + snapshot: ptr leveldb_snapshot_t) {.importc, + cdecl.} +proc leveldb_property_value*(db: ptr leveldb_t; propname: cstring): cstring {. + importc, cdecl.} + ## ``` + ## Returns NULL if property name is unknown. + ## Else returns a pointer to a malloc()-ed null-terminated value. + ## ``` +proc leveldb_approximate_sizes*(db: ptr leveldb_t; num_ranges: cint; + range_start_key: ptr cstring; + range_start_key_len: ptr uint; + range_limit_key: ptr cstring; + range_limit_key_len: ptr uint; sizes: ptr uint64) {. + importc, cdecl.} +proc leveldb_compact_range*(db: ptr leveldb_t; start_key: cstring; + start_key_len: uint; limit_key: cstring; + limit_key_len: uint) {.importc, cdecl.} +proc leveldb_destroy_db*(options: ptr leveldb_options_t; name: cstring; + errptr: ptr cstring) {.importc, cdecl.} +proc leveldb_repair_db*(options: ptr leveldb_options_t; name: cstring; + errptr: ptr cstring) {.importc, cdecl.} +proc leveldb_iter_destroy*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} +proc leveldb_iter_valid*(a1: ptr leveldb_iterator_t): uint8 {.importc, cdecl.} +proc leveldb_iter_seek_to_first*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} +proc leveldb_iter_seek_to_last*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} +proc leveldb_iter_seek*(a1: ptr leveldb_iterator_t; k: cstring; klen: uint) {. + importc, cdecl.} +proc leveldb_iter_next*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} +proc leveldb_iter_prev*(a1: ptr leveldb_iterator_t) {.importc, cdecl.} +proc leveldb_iter_key*(a1: ptr leveldb_iterator_t; klen: ptr uint): cstring {. + importc, cdecl.} +proc leveldb_iter_value*(a1: ptr leveldb_iterator_t; vlen: ptr uint): cstring {. + importc, cdecl.} +proc leveldb_iter_get_error*(a1: ptr leveldb_iterator_t; errptr: ptr cstring) {. + importc, cdecl.} +proc leveldb_writebatch_create*(): ptr leveldb_writebatch_t {.importc, cdecl.} +proc leveldb_writebatch_destroy*(a1: ptr leveldb_writebatch_t) {.importc, cdecl.} +proc leveldb_writebatch_clear*(a1: ptr leveldb_writebatch_t) {.importc, cdecl.} +proc leveldb_writebatch_put*(a1: ptr leveldb_writebatch_t; key: cstring; + klen: uint; val: cstring; vlen: uint) {.importc, + cdecl.} +proc leveldb_writebatch_delete*(a1: ptr leveldb_writebatch_t; key: cstring; + klen: uint) {.importc, cdecl.} +proc leveldb_writebatch_iterate*(a1: ptr leveldb_writebatch_t; state: pointer; + put: proc (a1: pointer; k: cstring; klen: uint; v: cstring; vlen: uint) {. + cdecl.}; deleted: proc (a1: pointer; k: cstring; klen: uint) {.cdecl.}) {. + importc, cdecl.} +proc leveldb_writebatch_append*(destination: ptr leveldb_writebatch_t; + source: ptr leveldb_writebatch_t) {.importc, + cdecl.} +proc leveldb_options_create*(): ptr leveldb_options_t {.importc, cdecl.} +proc leveldb_options_destroy*(a1: ptr leveldb_options_t) {.importc, cdecl.} +proc leveldb_options_set_comparator*(a1: ptr leveldb_options_t; + a2: ptr leveldb_comparator_t) {.importc, + cdecl.} +proc leveldb_options_set_filter_policy*(a1: ptr leveldb_options_t; + a2: ptr leveldb_filterpolicy_t) {. + importc, cdecl.} +proc leveldb_options_set_create_if_missing*(a1: ptr leveldb_options_t; a2: uint8) {. + importc, cdecl.} +proc leveldb_options_set_error_if_exists*(a1: ptr leveldb_options_t; a2: uint8) {. + importc, cdecl.} +proc leveldb_options_set_paranoid_checks*(a1: ptr leveldb_options_t; a2: uint8) {. + importc, cdecl.} +proc leveldb_options_set_env*(a1: ptr leveldb_options_t; a2: ptr leveldb_env_t) {. + importc, cdecl.} +proc leveldb_options_set_info_log*(a1: ptr leveldb_options_t; + a2: ptr leveldb_logger_t) {.importc, cdecl.} +proc leveldb_options_set_write_buffer_size*(a1: ptr leveldb_options_t; a2: uint) {. + importc, cdecl.} +proc leveldb_options_set_max_open_files*(a1: ptr leveldb_options_t; a2: cint) {. + importc, cdecl.} +proc leveldb_options_set_cache*(a1: ptr leveldb_options_t; + a2: ptr leveldb_cache_t) {.importc, cdecl.} +proc leveldb_options_set_block_size*(a1: ptr leveldb_options_t; a2: uint) {. + importc, cdecl.} +proc leveldb_options_set_block_restart_interval*(a1: ptr leveldb_options_t; + a2: cint) {.importc, cdecl.} +proc leveldb_options_set_max_file_size*(a1: ptr leveldb_options_t; a2: uint) {. + importc, cdecl.} +proc leveldb_options_set_compression*(a1: ptr leveldb_options_t; a2: cint) {. + importc, cdecl.} +proc leveldb_comparator_create*(state: pointer; + destructor: proc (a1: pointer) {.cdecl.}; + compare: proc (a1: pointer; a: cstring; alen: uint; b: cstring; blen: uint): cint {. + cdecl.}; name: proc (a1: pointer): cstring {.cdecl.}): ptr leveldb_comparator_t {. + importc, cdecl.} +proc leveldb_comparator_destroy*(a1: ptr leveldb_comparator_t) {.importc, cdecl.} +proc leveldb_filterpolicy_create*(state: pointer; + destructor: proc (a1: pointer) {.cdecl.}; create_filter: proc (a1: pointer; key_array: ptr cstring; - key_length_array: ptr csize_t; num_keys: cint; - filter_length: ptr csize_t): cstring; key_may_match: proc ( - a1: pointer; key: cstring; length: csize_t; filter: cstring; filter_length: csize_t): uint8; - name: proc (a1: pointer): cstring): ptr leveldb_filterpolicy_t {.importc.} -proc leveldb_filterpolicy_destroy*(a1: ptr leveldb_filterpolicy_t) {.importc.} -proc leveldb_filterpolicy_create_bloom*(bits_per_key: cint): ptr leveldb_filterpolicy_t {.importc.} -## Read options - -proc leveldb_readoptions_create*(): ptr leveldb_readoptions_t {.importc.} -proc leveldb_readoptions_destroy*(a1: ptr leveldb_readoptions_t) {.importc.} + key_length_array: ptr uint; num_keys: cint; + filter_length: ptr uint): cstring {.cdecl.}; + key_may_match: proc (a1: pointer; key: cstring; length: uint; + filter: cstring; filter_length: uint): uint8 {.cdecl.}; + name: proc (a1: pointer): cstring {.cdecl.}): ptr leveldb_filterpolicy_t {. + importc, cdecl.} +proc leveldb_filterpolicy_destroy*(a1: ptr leveldb_filterpolicy_t) {.importc, + cdecl.} +proc leveldb_filterpolicy_create_bloom*(bits_per_key: cint): ptr leveldb_filterpolicy_t {. + importc, cdecl.} +proc leveldb_readoptions_create*(): ptr leveldb_readoptions_t {.importc, cdecl.} +proc leveldb_readoptions_destroy*(a1: ptr leveldb_readoptions_t) {.importc, + cdecl.} proc leveldb_readoptions_set_verify_checksums*(a1: ptr leveldb_readoptions_t; - a2: uint8) {.importc.} -proc leveldb_readoptions_set_fill_cache*(a1: ptr leveldb_readoptions_t; a2: uint8) {.importc.} + a2: uint8) {.importc, cdecl.} +proc leveldb_readoptions_set_fill_cache*(a1: ptr leveldb_readoptions_t; + a2: uint8) {.importc, cdecl.} proc leveldb_readoptions_set_snapshot*(a1: ptr leveldb_readoptions_t; - a2: ptr leveldb_snapshot_t) {.importc.} -## Write options - -proc leveldb_writeoptions_create*(): ptr leveldb_writeoptions_t {.importc.} -proc leveldb_writeoptions_destroy*(a1: ptr leveldb_writeoptions_t) {.importc.} -proc leveldb_writeoptions_set_sync*(a1: ptr leveldb_writeoptions_t; a2: uint8) {.importc.} -## Cache - -proc leveldb_cache_create_lru*(capacity: csize_t): ptr leveldb_cache_t {.importc.} -proc leveldb_cache_destroy*(cache: ptr leveldb_cache_t) {.importc.} -## Env - -proc leveldb_create_default_env*(): ptr leveldb_env_t {.importc.} -proc leveldb_env_destroy*(a1: ptr leveldb_env_t) {.importc.} -## If not NULL, the returned buffer must be released using leveldb_free(). - -proc leveldb_env_get_test_directory*(a1: ptr leveldb_env_t): cstring {.importc.} -## Utility -## Calls free(ptr). -## REQUIRES: ptr was malloc()-ed and returned by one of the routines -## in this file. Note that in certain cases (typically on Windows), you -## may need to call this routine instead of free(ptr) to dispose of -## malloc()-ed memory returned by this library. - -proc leveldb_free*(`ptr`: pointer) {.importc.} -## Return the major version number for this release. - -proc leveldb_major_version*(): cint {.importc.} -## Return the minor version number for this release. - -proc leveldb_minor_version*(): cint {.importc.} + a2: ptr leveldb_snapshot_t) {.importc, + cdecl.} +proc leveldb_writeoptions_create*(): ptr leveldb_writeoptions_t {.importc, cdecl.} +proc leveldb_writeoptions_destroy*(a1: ptr leveldb_writeoptions_t) {.importc, + cdecl.} +proc leveldb_writeoptions_set_sync*(a1: ptr leveldb_writeoptions_t; a2: uint8) {. + importc, cdecl.} +proc leveldb_cache_create_lru*(capacity: uint): ptr leveldb_cache_t {.importc, + cdecl.} +proc leveldb_cache_destroy*(cache: ptr leveldb_cache_t) {.importc, cdecl.} +proc leveldb_create_default_env*(): ptr leveldb_env_t {.importc, cdecl.} +proc leveldb_env_destroy*(a1: ptr leveldb_env_t) {.importc, cdecl.} +proc leveldb_env_get_test_directory*(a1: ptr leveldb_env_t): cstring {.importc, + cdecl.} + ## ``` + ## If not NULL, the returned buffer must be released using leveldb_free(). + ## ``` +proc leveldb_free*(`ptr`: pointer) {.importc, cdecl.} + ## ``` + ## Utility + ## Calls free(ptr). + ## REQUIRES: ptr was malloc()-ed and returned by one of the routines + ## in this file. Note that in certain cases (typically on Windows), you + ## may need to call this routine instead of free(ptr) to dispose of + ## malloc()-ed memory returned by this library. + ## ``` +proc leveldb_major_version*(): cint {.importc, cdecl.} + ## ``` + ## Return the major version number for this release. + ## ``` +proc leveldb_minor_version*(): cint {.importc, cdecl.} + ## ``` + ## Return the minor version number for this release. + ## ``` +{.pop.} From 7a6341ea18a905cb9767c009d77fe423d5f5583c Mon Sep 17 00:00:00 2001 From: ThatBen Date: Thu, 9 May 2024 14:49:59 +0200 Subject: [PATCH 10/31] moves sources to vendor directory --- .gitignore | 2 ++ .gitmodules | 4 ++-- build/include/port/port_config.h | 33 ++++++++++++++++++++++++++++++++ sources | 1 - src/vendor | 1 + 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 build/include/port/port_config.h delete mode 160000 sources create mode 160000 src/vendor diff --git a/.gitignore b/.gitignore index 9cc6f1f..5536487 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ src/htmldocs/ leveldbtool *.html *.css +build + diff --git a/.gitmodules b/.gitmodules index 06101e6..b11fceb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "sources"] - path = sources +[submodule "src/vendor"] + path = src/vendor url = https://github.com/google/leveldb diff --git a/build/include/port/port_config.h b/build/include/port/port_config.h new file mode 100644 index 0000000..5c12e38 --- /dev/null +++ b/build/include/port/port_config.h @@ -0,0 +1,33 @@ +// Copyright 2017 The LevelDB Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. See the AUTHORS file for names of contributors. + +#ifndef STORAGE_LEVELDB_PORT_PORT_CONFIG_H_ +#define STORAGE_LEVELDB_PORT_PORT_CONFIG_H_ + +// Define to 1 if you have a definition for fdatasync() in . +#if !defined(HAVE_FDATASYNC) +#define HAVE_FDATASYNC 1 +#endif // !defined(HAVE_FDATASYNC) + +// Define to 1 if you have a definition for F_FULLFSYNC in . +#if !defined(HAVE_FULLFSYNC) +#define HAVE_FULLFSYNC 0 +#endif // !defined(HAVE_FULLFSYNC) + +// Define to 1 if you have a definition for O_CLOEXEC in . +#if !defined(HAVE_O_CLOEXEC) +#define HAVE_O_CLOEXEC 1 +#endif // !defined(HAVE_O_CLOEXEC) + +// Define to 1 if you have Google CRC32C. +#if !defined(HAVE_CRC32C) +#define HAVE_CRC32C 0 +#endif // !defined(HAVE_CRC32C) + +// Define to 1 if you have Google Snappy. +#if !defined(HAVE_SNAPPY) +#define HAVE_SNAPPY 0 +#endif // !defined(HAVE_SNAPPY) + +#endif // STORAGE_LEVELDB_PORT_PORT_CONFIG_H_ diff --git a/sources b/sources deleted file mode 160000 index 99b3c03..0000000 --- a/sources +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 99b3c03b3284f5886f9ef9a4ef703d57373e61be diff --git a/src/vendor b/src/vendor new file mode 160000 index 0000000..068d5ee --- /dev/null +++ b/src/vendor @@ -0,0 +1 @@ +Subproject commit 068d5ee1a3ac40dabd00d211d5013af44be55bea From b0625f151f0bd0c0a605ee1e63fa0a82ef1caea2 Mon Sep 17 00:00:00 2001 From: ThatBen Date: Thu, 9 May 2024 14:58:31 +0200 Subject: [PATCH 11/31] updates build for new vendor folder --- build.sh | 30 +++++----- build/include/port/port_config.h | 5 ++ prelude.nim | 4 +- src/leveldb/raw.nim | 95 ++++++++++++++++---------------- 4 files changed, 71 insertions(+), 63 deletions(-) diff --git a/build.sh b/build.sh index 4278e35..f7c21f3 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,8 @@ #!/bin/bash root=$(dirname "$0") +sourceDir="${root}/src/vendor" +buildDir="${root}/build" output="${root}/src/leveldb/raw.nim" # install nimterop, if not already installed @@ -11,12 +13,12 @@ fi git submodule deinit -f "${root}" git submodule update --init --recursive --checkout "${root}" -cmake -S "${root}/sources" -B "${root}/build" +cmake -S "${sourceDir}" -B "${buildDir}" # Remove testing, benchmarking, third-party libraries. -rm -Rf "${root}/sources/third_party" -rm -Rf "${root}/sources/benchmarks" -rm "${root}/sources/util/testutil.cc" +rm -Rf "${sourceDir}/third_party" +rm -Rf "${sourceDir}/benchmarks" +rm "${sourceDir}/util/testutil.cc" # Prelude: cat "${root}/prelude.nim" > "${output}" @@ -25,7 +27,7 @@ echo >> "${output}" # assemble files to be compiled: extensions="c cc cpp" for ext in ${extensions}; do - for file in `find "${root}/sources" -type f -name "*.${ext}" \ + for file in `find "${sourceDir}" -type f -name "*.${ext}" \ | grep -v "_test" \ | grep -v "env_windows.cc" \ | grep -v "env_posix.cc" \ @@ -40,12 +42,14 @@ toast \ --pnim \ --preprocess \ --noHeader \ - --includeDirs="${root}/sources" \ - --includeDirs="${root}/sources/helpers" \ - --includeDirs="${root}/sources/helpers/memenv" \ - --includeDirs="${root}/sources/port" \ - --includeDirs="${root}/sources/include" \ - --includeDirs="${root}/build/include" \ - --includeDirs="${root}/build/include/port" \ - "${root}/sources/include/leveldb/c.h" >> "${output}" + --includeDirs="${sourceDir}" \ + --includeDirs="${sourceDir}/helpers" \ + --includeDirs="${sourceDir}/helpers/memenv" \ + --includeDirs="${sourceDir}/port" \ + --includeDirs="${sourceDir}/include" \ + --includeDirs="${buildDir}/include" \ + "${sourceDir}/include/leveldb/c.h" >> "${output}" + +# --includeDirs="${buildDir}/include/port" \ + diff --git a/build/include/port/port_config.h b/build/include/port/port_config.h index 5c12e38..0e80eda 100644 --- a/build/include/port/port_config.h +++ b/build/include/port/port_config.h @@ -30,4 +30,9 @@ #define HAVE_SNAPPY 0 #endif // !defined(HAVE_SNAPPY) +// Define to 1 if you have Zstd. +#if !defined(HAVE_Zstd) +#define HAVE_ZSTD 0 +#endif // !defined(HAVE_ZSTD) + #endif // STORAGE_LEVELDB_PORT_PORT_CONFIG_H_ diff --git a/prelude.nim b/prelude.nim index 8c3394a..21eb4a1 100644 --- a/prelude.nim +++ b/prelude.nim @@ -1,7 +1,7 @@ when defined(windows): - {.compile: "./sources/util/env_windows.cc".} + {.compile: "./src/vendor/util/env_windows.cc".} {.passc: "-DLEVELDB_PLATFORM_POSIX".} when defined(posix): - {.compile: "./sources/util/env_posix.cc".} + {.compile: "./src/vendor/util/env_posix.cc".} {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} diff --git a/src/leveldb/raw.nim b/src/leveldb/raw.nim index 9b1b554..4a1d04b 100644 --- a/src/leveldb/raw.nim +++ b/src/leveldb/raw.nim @@ -1,14 +1,14 @@ when defined(windows): - {.compile: "./sources/util/env_windows.cc".} + {.compile: "./src/vendor/util/env_windows.cc".} {.passc: "-DLEVELDB_PLATFORM_POSIX".} when defined(posix): - {.compile: "./sources/util/env_posix.cc".} + {.compile: "./src/vendor/util/env_posix.cc".} {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} -# Generated @ 2024-05-09T14:13:25+02:00 +# Generated @ 2024-05-09T14:57:19+02:00 # Command line: -# /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./sources/helpers/memenv/memenv.cc --compile=./sources/table/table.cc --compile=./sources/table/iterator.cc --compile=./sources/table/merger.cc --compile=./sources/table/block.cc --compile=./sources/table/table_builder.cc --compile=./sources/table/format.cc --compile=./sources/table/two_level_iterator.cc --compile=./sources/table/filter_block.cc --compile=./sources/table/block_builder.cc --compile=./sources/db/write_batch.cc --compile=./sources/db/version_edit.cc --compile=./sources/db/dbformat.cc --compile=./sources/db/builder.cc --compile=./sources/db/repair.cc --compile=./sources/db/db_impl.cc --compile=./sources/db/dumpfile.cc --compile=./sources/db/filename.cc --compile=./sources/db/log_reader.cc --compile=./sources/db/memtable.cc --compile=./sources/db/table_cache.cc --compile=./sources/db/c.cc --compile=./sources/db/log_writer.cc --compile=./sources/db/version_set.cc --compile=./sources/db/db_iter.cc --compile=./sources/util/hash.cc --compile=./sources/util/options.cc --compile=./sources/util/comparator.cc --compile=./sources/util/coding.cc --compile=./sources/util/histogram.cc --compile=./sources/util/logging.cc --compile=./sources/util/cache.cc --compile=./sources/util/env.cc --compile=./sources/util/filter_policy.cc --compile=./sources/util/arena.cc --compile=./sources/util/bloom.cc --compile=./sources/util/crc32c.cc --compile=./sources/util/status.cc --pnim --preprocess --noHeader --includeDirs=./sources --includeDirs=./sources/helpers --includeDirs=./sources/helpers/memenv --includeDirs=./sources/port --includeDirs=./sources/include --includeDirs=./build/include --includeDirs=./build/include/port ./sources/include/leveldb/c.h +# /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./src/vendor/helpers/memenv/memenv.cc --compile=./src/vendor/table/table.cc --compile=./src/vendor/table/iterator.cc --compile=./src/vendor/table/merger.cc --compile=./src/vendor/table/block.cc --compile=./src/vendor/table/table_builder.cc --compile=./src/vendor/table/format.cc --compile=./src/vendor/table/two_level_iterator.cc --compile=./src/vendor/table/filter_block.cc --compile=./src/vendor/table/block_builder.cc --compile=./src/vendor/db/write_batch.cc --compile=./src/vendor/db/version_edit.cc --compile=./src/vendor/db/dbformat.cc --compile=./src/vendor/db/builder.cc --compile=./src/vendor/db/repair.cc --compile=./src/vendor/db/db_impl.cc --compile=./src/vendor/db/dumpfile.cc --compile=./src/vendor/db/filename.cc --compile=./src/vendor/db/log_reader.cc --compile=./src/vendor/db/memtable.cc --compile=./src/vendor/db/table_cache.cc --compile=./src/vendor/db/c.cc --compile=./src/vendor/db/log_writer.cc --compile=./src/vendor/db/version_set.cc --compile=./src/vendor/db/db_iter.cc --compile=./src/vendor/util/hash.cc --compile=./src/vendor/util/options.cc --compile=./src/vendor/util/comparator.cc --compile=./src/vendor/util/coding.cc --compile=./src/vendor/util/histogram.cc --compile=./src/vendor/util/logging.cc --compile=./src/vendor/util/cache.cc --compile=./src/vendor/util/env.cc --compile=./src/vendor/util/filter_policy.cc --compile=./src/vendor/util/arena.cc --compile=./src/vendor/util/bloom.cc --compile=./src/vendor/util/crc32c.cc --compile=./src/vendor/util/status.cc --pnim --preprocess --noHeader --includeDirs=./src/vendor --includeDirs=./src/vendor/helpers --includeDirs=./src/vendor/helpers/memenv --includeDirs=./src/vendor/port --includeDirs=./src/vendor/include --includeDirs=./build/include ./src/vendor/include/leveldb/c.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} import macros @@ -56,51 +56,50 @@ macro defineEnum(typ: untyped): untyped = {.experimental: "codeReordering".} -{.passC: "-I./sources".} -{.passC: "-I./sources/helpers".} -{.passC: "-I./sources/helpers/memenv".} -{.passC: "-I./sources/port".} -{.passC: "-I./sources/include".} +{.passC: "-I./src/vendor".} +{.passC: "-I./src/vendor/helpers".} +{.passC: "-I./src/vendor/helpers/memenv".} +{.passC: "-I./src/vendor/port".} +{.passC: "-I./src/vendor/include".} {.passC: "-I./build/include".} -{.passC: "-I./build/include/port".} -{.compile: "./sources/helpers/memenv/memenv.cc".} -{.compile: "./sources/table/table.cc".} -{.compile: "./sources/table/iterator.cc".} -{.compile: "./sources/table/merger.cc".} -{.compile: "./sources/table/block.cc".} -{.compile: "./sources/table/table_builder.cc".} -{.compile: "./sources/table/format.cc".} -{.compile: "./sources/table/two_level_iterator.cc".} -{.compile: "./sources/table/filter_block.cc".} -{.compile: "./sources/table/block_builder.cc".} -{.compile: "./sources/db/write_batch.cc".} -{.compile: "./sources/db/version_edit.cc".} -{.compile: "./sources/db/dbformat.cc".} -{.compile: "./sources/db/builder.cc".} -{.compile: "./sources/db/repair.cc".} -{.compile: "./sources/db/db_impl.cc".} -{.compile: "./sources/db/dumpfile.cc".} -{.compile: "./sources/db/filename.cc".} -{.compile: "./sources/db/log_reader.cc".} -{.compile: "./sources/db/memtable.cc".} -{.compile: "./sources/db/table_cache.cc".} -{.compile: "./sources/db/c.cc".} -{.compile: "./sources/db/log_writer.cc".} -{.compile: "./sources/db/version_set.cc".} -{.compile: "./sources/db/db_iter.cc".} -{.compile: "./sources/util/hash.cc".} -{.compile: "./sources/util/options.cc".} -{.compile: "./sources/util/comparator.cc".} -{.compile: "./sources/util/coding.cc".} -{.compile: "./sources/util/histogram.cc".} -{.compile: "./sources/util/logging.cc".} -{.compile: "./sources/util/cache.cc".} -{.compile: "./sources/util/env.cc".} -{.compile: "./sources/util/filter_policy.cc".} -{.compile: "./sources/util/arena.cc".} -{.compile: "./sources/util/bloom.cc".} -{.compile: "./sources/util/crc32c.cc".} -{.compile: "./sources/util/status.cc".} +{.compile: "./src/vendor/helpers/memenv/memenv.cc".} +{.compile: "./src/vendor/table/table.cc".} +{.compile: "./src/vendor/table/iterator.cc".} +{.compile: "./src/vendor/table/merger.cc".} +{.compile: "./src/vendor/table/block.cc".} +{.compile: "./src/vendor/table/table_builder.cc".} +{.compile: "./src/vendor/table/format.cc".} +{.compile: "./src/vendor/table/two_level_iterator.cc".} +{.compile: "./src/vendor/table/filter_block.cc".} +{.compile: "./src/vendor/table/block_builder.cc".} +{.compile: "./src/vendor/db/write_batch.cc".} +{.compile: "./src/vendor/db/version_edit.cc".} +{.compile: "./src/vendor/db/dbformat.cc".} +{.compile: "./src/vendor/db/builder.cc".} +{.compile: "./src/vendor/db/repair.cc".} +{.compile: "./src/vendor/db/db_impl.cc".} +{.compile: "./src/vendor/db/dumpfile.cc".} +{.compile: "./src/vendor/db/filename.cc".} +{.compile: "./src/vendor/db/log_reader.cc".} +{.compile: "./src/vendor/db/memtable.cc".} +{.compile: "./src/vendor/db/table_cache.cc".} +{.compile: "./src/vendor/db/c.cc".} +{.compile: "./src/vendor/db/log_writer.cc".} +{.compile: "./src/vendor/db/version_set.cc".} +{.compile: "./src/vendor/db/db_iter.cc".} +{.compile: "./src/vendor/util/hash.cc".} +{.compile: "./src/vendor/util/options.cc".} +{.compile: "./src/vendor/util/comparator.cc".} +{.compile: "./src/vendor/util/coding.cc".} +{.compile: "./src/vendor/util/histogram.cc".} +{.compile: "./src/vendor/util/logging.cc".} +{.compile: "./src/vendor/util/cache.cc".} +{.compile: "./src/vendor/util/env.cc".} +{.compile: "./src/vendor/util/filter_policy.cc".} +{.compile: "./src/vendor/util/arena.cc".} +{.compile: "./src/vendor/util/bloom.cc".} +{.compile: "./src/vendor/util/crc32c.cc".} +{.compile: "./src/vendor/util/status.cc".} defineEnum(Enum_ch1) const leveldb_no_compression* = (0).cint From b5301c2084e46b3b65eb06337de77d40cde916dd Mon Sep 17 00:00:00 2001 From: ThatBen Date: Thu, 9 May 2024 15:37:37 +0200 Subject: [PATCH 12/31] remove src folder --- .gitmodules | 4 +- build.sh | 4 +- src/leveldb.nim => leveldb.nim | 0 leveldb.nimble | 5 +- {src/leveldb => leveldb}/raw.nim | 100 +++++++++++++------------ src/leveldbtool.nim => leveldbtool.nim | 0 prelude.nim | 10 ++- src/vendor => vendor | 0 8 files changed, 68 insertions(+), 55 deletions(-) rename src/leveldb.nim => leveldb.nim (100%) rename {src/leveldb => leveldb}/raw.nim (77%) rename src/leveldbtool.nim => leveldbtool.nim (100%) rename src/vendor => vendor (100%) diff --git a/.gitmodules b/.gitmodules index b11fceb..7cf389c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "src/vendor"] - path = src/vendor +[submodule "vendor"] + path = vendor url = https://github.com/google/leveldb diff --git a/build.sh b/build.sh index f7c21f3..a62d04a 100755 --- a/build.sh +++ b/build.sh @@ -1,9 +1,9 @@ #!/bin/bash root=$(dirname "$0") -sourceDir="${root}/src/vendor" +sourceDir="${root}/vendor" buildDir="${root}/build" -output="${root}/src/leveldb/raw.nim" +output="${root}/leveldb/raw.nim" # install nimterop, if not already installed if ! [ -x "$(command -v toast)" ]; then diff --git a/src/leveldb.nim b/leveldb.nim similarity index 100% rename from src/leveldb.nim rename to leveldb.nim diff --git a/leveldb.nimble b/leveldb.nimble index d113654..41a06b6 100644 --- a/leveldb.nimble +++ b/leveldb.nimble @@ -4,9 +4,10 @@ version = "0.4.1" author = "Michał Zieliński" description = "LevelDB wrapper for Nim" license = "MIT" -srcDir = "src" -installExt = @["nim"] bin = @["leveldbtool"] +installExt = @["nim", "cc", "h", "c", "cpp"] +skipDirs = @["tests"] + # Dependencies diff --git a/src/leveldb/raw.nim b/leveldb/raw.nim similarity index 77% rename from src/leveldb/raw.nim rename to leveldb/raw.nim index 4a1d04b..3235701 100644 --- a/src/leveldb/raw.nim +++ b/leveldb/raw.nim @@ -1,14 +1,20 @@ +import os + +const root = currentSourcePath.parentDir.parentDir +const envWindows = root/"vendor"/"util"/"env_windows.cc" +const envPosix = root/"vendor"/"util"/"env_posix.cc" + when defined(windows): - {.compile: "./src/vendor/util/env_windows.cc".} + {.compile: envWindows.} {.passc: "-DLEVELDB_PLATFORM_POSIX".} when defined(posix): - {.compile: "./src/vendor/util/env_posix.cc".} + {.compile: envPosix.} {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} -# Generated @ 2024-05-09T14:57:19+02:00 +# Generated @ 2024-05-09T15:32:29+02:00 # Command line: -# /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./src/vendor/helpers/memenv/memenv.cc --compile=./src/vendor/table/table.cc --compile=./src/vendor/table/iterator.cc --compile=./src/vendor/table/merger.cc --compile=./src/vendor/table/block.cc --compile=./src/vendor/table/table_builder.cc --compile=./src/vendor/table/format.cc --compile=./src/vendor/table/two_level_iterator.cc --compile=./src/vendor/table/filter_block.cc --compile=./src/vendor/table/block_builder.cc --compile=./src/vendor/db/write_batch.cc --compile=./src/vendor/db/version_edit.cc --compile=./src/vendor/db/dbformat.cc --compile=./src/vendor/db/builder.cc --compile=./src/vendor/db/repair.cc --compile=./src/vendor/db/db_impl.cc --compile=./src/vendor/db/dumpfile.cc --compile=./src/vendor/db/filename.cc --compile=./src/vendor/db/log_reader.cc --compile=./src/vendor/db/memtable.cc --compile=./src/vendor/db/table_cache.cc --compile=./src/vendor/db/c.cc --compile=./src/vendor/db/log_writer.cc --compile=./src/vendor/db/version_set.cc --compile=./src/vendor/db/db_iter.cc --compile=./src/vendor/util/hash.cc --compile=./src/vendor/util/options.cc --compile=./src/vendor/util/comparator.cc --compile=./src/vendor/util/coding.cc --compile=./src/vendor/util/histogram.cc --compile=./src/vendor/util/logging.cc --compile=./src/vendor/util/cache.cc --compile=./src/vendor/util/env.cc --compile=./src/vendor/util/filter_policy.cc --compile=./src/vendor/util/arena.cc --compile=./src/vendor/util/bloom.cc --compile=./src/vendor/util/crc32c.cc --compile=./src/vendor/util/status.cc --pnim --preprocess --noHeader --includeDirs=./src/vendor --includeDirs=./src/vendor/helpers --includeDirs=./src/vendor/helpers/memenv --includeDirs=./src/vendor/port --includeDirs=./src/vendor/include --includeDirs=./build/include ./src/vendor/include/leveldb/c.h +# /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./vendor/helpers/memenv/memenv.cc --compile=./vendor/table/table.cc --compile=./vendor/table/iterator.cc --compile=./vendor/table/merger.cc --compile=./vendor/table/block.cc --compile=./vendor/table/table_builder.cc --compile=./vendor/table/format.cc --compile=./vendor/table/two_level_iterator.cc --compile=./vendor/table/filter_block.cc --compile=./vendor/table/block_builder.cc --compile=./vendor/db/write_batch.cc --compile=./vendor/db/version_edit.cc --compile=./vendor/db/dbformat.cc --compile=./vendor/db/builder.cc --compile=./vendor/db/repair.cc --compile=./vendor/db/db_impl.cc --compile=./vendor/db/dumpfile.cc --compile=./vendor/db/filename.cc --compile=./vendor/db/log_reader.cc --compile=./vendor/db/memtable.cc --compile=./vendor/db/table_cache.cc --compile=./vendor/db/c.cc --compile=./vendor/db/log_writer.cc --compile=./vendor/db/version_set.cc --compile=./vendor/db/db_iter.cc --compile=./vendor/util/hash.cc --compile=./vendor/util/options.cc --compile=./vendor/util/comparator.cc --compile=./vendor/util/coding.cc --compile=./vendor/util/histogram.cc --compile=./vendor/util/logging.cc --compile=./vendor/util/cache.cc --compile=./vendor/util/env.cc --compile=./vendor/util/filter_policy.cc --compile=./vendor/util/arena.cc --compile=./vendor/util/bloom.cc --compile=./vendor/util/crc32c.cc --compile=./vendor/util/status.cc --pnim --preprocess --noHeader --includeDirs=./vendor --includeDirs=./vendor/helpers --includeDirs=./vendor/helpers/memenv --includeDirs=./vendor/port --includeDirs=./vendor/include --includeDirs=./build/include ./vendor/include/leveldb/c.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} import macros @@ -56,50 +62,50 @@ macro defineEnum(typ: untyped): untyped = {.experimental: "codeReordering".} -{.passC: "-I./src/vendor".} -{.passC: "-I./src/vendor/helpers".} -{.passC: "-I./src/vendor/helpers/memenv".} -{.passC: "-I./src/vendor/port".} -{.passC: "-I./src/vendor/include".} +{.passC: "-I./vendor".} +{.passC: "-I./vendor/helpers".} +{.passC: "-I./vendor/helpers/memenv".} +{.passC: "-I./vendor/port".} +{.passC: "-I./vendor/include".} {.passC: "-I./build/include".} -{.compile: "./src/vendor/helpers/memenv/memenv.cc".} -{.compile: "./src/vendor/table/table.cc".} -{.compile: "./src/vendor/table/iterator.cc".} -{.compile: "./src/vendor/table/merger.cc".} -{.compile: "./src/vendor/table/block.cc".} -{.compile: "./src/vendor/table/table_builder.cc".} -{.compile: "./src/vendor/table/format.cc".} -{.compile: "./src/vendor/table/two_level_iterator.cc".} -{.compile: "./src/vendor/table/filter_block.cc".} -{.compile: "./src/vendor/table/block_builder.cc".} -{.compile: "./src/vendor/db/write_batch.cc".} -{.compile: "./src/vendor/db/version_edit.cc".} -{.compile: "./src/vendor/db/dbformat.cc".} -{.compile: "./src/vendor/db/builder.cc".} -{.compile: "./src/vendor/db/repair.cc".} -{.compile: "./src/vendor/db/db_impl.cc".} -{.compile: "./src/vendor/db/dumpfile.cc".} -{.compile: "./src/vendor/db/filename.cc".} -{.compile: "./src/vendor/db/log_reader.cc".} -{.compile: "./src/vendor/db/memtable.cc".} -{.compile: "./src/vendor/db/table_cache.cc".} -{.compile: "./src/vendor/db/c.cc".} -{.compile: "./src/vendor/db/log_writer.cc".} -{.compile: "./src/vendor/db/version_set.cc".} -{.compile: "./src/vendor/db/db_iter.cc".} -{.compile: "./src/vendor/util/hash.cc".} -{.compile: "./src/vendor/util/options.cc".} -{.compile: "./src/vendor/util/comparator.cc".} -{.compile: "./src/vendor/util/coding.cc".} -{.compile: "./src/vendor/util/histogram.cc".} -{.compile: "./src/vendor/util/logging.cc".} -{.compile: "./src/vendor/util/cache.cc".} -{.compile: "./src/vendor/util/env.cc".} -{.compile: "./src/vendor/util/filter_policy.cc".} -{.compile: "./src/vendor/util/arena.cc".} -{.compile: "./src/vendor/util/bloom.cc".} -{.compile: "./src/vendor/util/crc32c.cc".} -{.compile: "./src/vendor/util/status.cc".} +{.compile: "./vendor/helpers/memenv/memenv.cc".} +{.compile: "./vendor/table/table.cc".} +{.compile: "./vendor/table/iterator.cc".} +{.compile: "./vendor/table/merger.cc".} +{.compile: "./vendor/table/block.cc".} +{.compile: "./vendor/table/table_builder.cc".} +{.compile: "./vendor/table/format.cc".} +{.compile: "./vendor/table/two_level_iterator.cc".} +{.compile: "./vendor/table/filter_block.cc".} +{.compile: "./vendor/table/block_builder.cc".} +{.compile: "./vendor/db/write_batch.cc".} +{.compile: "./vendor/db/version_edit.cc".} +{.compile: "./vendor/db/dbformat.cc".} +{.compile: "./vendor/db/builder.cc".} +{.compile: "./vendor/db/repair.cc".} +{.compile: "./vendor/db/db_impl.cc".} +{.compile: "./vendor/db/dumpfile.cc".} +{.compile: "./vendor/db/filename.cc".} +{.compile: "./vendor/db/log_reader.cc".} +{.compile: "./vendor/db/memtable.cc".} +{.compile: "./vendor/db/table_cache.cc".} +{.compile: "./vendor/db/c.cc".} +{.compile: "./vendor/db/log_writer.cc".} +{.compile: "./vendor/db/version_set.cc".} +{.compile: "./vendor/db/db_iter.cc".} +{.compile: "./vendor/util/hash.cc".} +{.compile: "./vendor/util/options.cc".} +{.compile: "./vendor/util/comparator.cc".} +{.compile: "./vendor/util/coding.cc".} +{.compile: "./vendor/util/histogram.cc".} +{.compile: "./vendor/util/logging.cc".} +{.compile: "./vendor/util/cache.cc".} +{.compile: "./vendor/util/env.cc".} +{.compile: "./vendor/util/filter_policy.cc".} +{.compile: "./vendor/util/arena.cc".} +{.compile: "./vendor/util/bloom.cc".} +{.compile: "./vendor/util/crc32c.cc".} +{.compile: "./vendor/util/status.cc".} defineEnum(Enum_ch1) const leveldb_no_compression* = (0).cint diff --git a/src/leveldbtool.nim b/leveldbtool.nim similarity index 100% rename from src/leveldbtool.nim rename to leveldbtool.nim diff --git a/prelude.nim b/prelude.nim index 21eb4a1..4309bed 100644 --- a/prelude.nim +++ b/prelude.nim @@ -1,7 +1,13 @@ +import os + +const root = currentSourcePath.parentDir.parentDir +const envWindows = root/"vendor"/"util"/"env_windows.cc" +const envPosix = root/"vendor"/"util"/"env_posix.cc" + when defined(windows): - {.compile: "./src/vendor/util/env_windows.cc".} + {.compile: envWindows.} {.passc: "-DLEVELDB_PLATFORM_POSIX".} when defined(posix): - {.compile: "./src/vendor/util/env_posix.cc".} + {.compile: envPosix.} {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} diff --git a/src/vendor b/vendor similarity index 100% rename from src/vendor rename to vendor From 85880f53daefcdaceed8d9cc97bdb1f7d8bf6231 Mon Sep 17 00:00:00 2001 From: ThatBen Date: Fri, 10 May 2024 11:00:51 +0200 Subject: [PATCH 13/31] passes nimble check --- build.sh | 2 +- leveldb.nimble | 7 ++++--- prelude.nim => leveldb/prelude.nim | 0 3 files changed, 5 insertions(+), 4 deletions(-) rename prelude.nim => leveldb/prelude.nim (100%) diff --git a/build.sh b/build.sh index a62d04a..fe21729 100755 --- a/build.sh +++ b/build.sh @@ -21,7 +21,7 @@ rm -Rf "${sourceDir}/benchmarks" rm "${sourceDir}/util/testutil.cc" # Prelude: -cat "${root}/prelude.nim" > "${output}" +cat "${root}/leveldb/prelude.nim" > "${output}" echo >> "${output}" # assemble files to be compiled: diff --git a/leveldb.nimble b/leveldb.nimble index 41a06b6..9ae390f 100644 --- a/leveldb.nimble +++ b/leveldb.nimble @@ -5,9 +5,10 @@ author = "Michał Zieliński" description = "LevelDB wrapper for Nim" license = "MIT" bin = @["leveldbtool"] -installExt = @["nim", "cc", "h", "c", "cpp"] -skipDirs = @["tests"] - +# installExt = @["nim", "cc", "h", "c", "cpp"] +installDirs = @["build", "leveldb", "vendor"] +installFiles = @["leveldb.nim"] +#"leveldbtool.nim", "prelude.nim"] # Dependencies diff --git a/prelude.nim b/leveldb/prelude.nim similarity index 100% rename from prelude.nim rename to leveldb/prelude.nim From 5646f353cf0ff67b57004e109b7da90e8755971a Mon Sep 17 00:00:00 2001 From: ThatBen Date: Fri, 10 May 2024 13:58:25 +0200 Subject: [PATCH 14/31] Fixes pathing issue when installing nimble package --- build.sh | 9 --------- leveldb/prelude.nim | 8 ++++++++ leveldb/raw.nim | 18 ++++++++++-------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/build.sh b/build.sh index fe21729..c81f595 100755 --- a/build.sh +++ b/build.sh @@ -42,14 +42,5 @@ toast \ --pnim \ --preprocess \ --noHeader \ - --includeDirs="${sourceDir}" \ - --includeDirs="${sourceDir}/helpers" \ - --includeDirs="${sourceDir}/helpers/memenv" \ - --includeDirs="${sourceDir}/port" \ - --includeDirs="${sourceDir}/include" \ - --includeDirs="${buildDir}/include" \ "${sourceDir}/include/leveldb/c.h" >> "${output}" -# --includeDirs="${buildDir}/include/port" \ - - diff --git a/leveldb/prelude.nim b/leveldb/prelude.nim index 4309bed..b827657 100644 --- a/leveldb/prelude.nim +++ b/leveldb/prelude.nim @@ -11,3 +11,11 @@ when defined(windows): when defined(posix): {.compile: envPosix.} {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} + +{.passC: "-I" & root/"vendor".} +{.passC: "-I" & root/"vendor"/"helpers".} +{.passC: "-I" & root/"vendor"/"helpers"/"memenv".} +{.passC: "-I" & root/"vendor"/"port".} +{.passC: "-I" & root/"vendor"/"include".} +{.passC: "-I" & root/"build"/"include".} + diff --git a/leveldb/raw.nim b/leveldb/raw.nim index 3235701..32891e9 100644 --- a/leveldb/raw.nim +++ b/leveldb/raw.nim @@ -12,9 +12,17 @@ when defined(posix): {.compile: envPosix.} {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} -# Generated @ 2024-05-09T15:32:29+02:00 +{.passC: "-I" & root/"vendor".} +{.passC: "-I" & root/"vendor"/"helpers".} +{.passC: "-I" & root/"vendor"/"helpers"/"memenv".} +{.passC: "-I" & root/"vendor"/"port".} +{.passC: "-I" & root/"vendor"/"include".} +{.passC: "-I" & root/"build"/"include".} + + +# Generated @ 2024-05-10T13:57:11+02:00 # Command line: -# /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./vendor/helpers/memenv/memenv.cc --compile=./vendor/table/table.cc --compile=./vendor/table/iterator.cc --compile=./vendor/table/merger.cc --compile=./vendor/table/block.cc --compile=./vendor/table/table_builder.cc --compile=./vendor/table/format.cc --compile=./vendor/table/two_level_iterator.cc --compile=./vendor/table/filter_block.cc --compile=./vendor/table/block_builder.cc --compile=./vendor/db/write_batch.cc --compile=./vendor/db/version_edit.cc --compile=./vendor/db/dbformat.cc --compile=./vendor/db/builder.cc --compile=./vendor/db/repair.cc --compile=./vendor/db/db_impl.cc --compile=./vendor/db/dumpfile.cc --compile=./vendor/db/filename.cc --compile=./vendor/db/log_reader.cc --compile=./vendor/db/memtable.cc --compile=./vendor/db/table_cache.cc --compile=./vendor/db/c.cc --compile=./vendor/db/log_writer.cc --compile=./vendor/db/version_set.cc --compile=./vendor/db/db_iter.cc --compile=./vendor/util/hash.cc --compile=./vendor/util/options.cc --compile=./vendor/util/comparator.cc --compile=./vendor/util/coding.cc --compile=./vendor/util/histogram.cc --compile=./vendor/util/logging.cc --compile=./vendor/util/cache.cc --compile=./vendor/util/env.cc --compile=./vendor/util/filter_policy.cc --compile=./vendor/util/arena.cc --compile=./vendor/util/bloom.cc --compile=./vendor/util/crc32c.cc --compile=./vendor/util/status.cc --pnim --preprocess --noHeader --includeDirs=./vendor --includeDirs=./vendor/helpers --includeDirs=./vendor/helpers/memenv --includeDirs=./vendor/port --includeDirs=./vendor/include --includeDirs=./build/include ./vendor/include/leveldb/c.h +# /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./vendor/helpers/memenv/memenv.cc --compile=./vendor/table/table.cc --compile=./vendor/table/iterator.cc --compile=./vendor/table/merger.cc --compile=./vendor/table/block.cc --compile=./vendor/table/table_builder.cc --compile=./vendor/table/format.cc --compile=./vendor/table/two_level_iterator.cc --compile=./vendor/table/filter_block.cc --compile=./vendor/table/block_builder.cc --compile=./vendor/db/write_batch.cc --compile=./vendor/db/version_edit.cc --compile=./vendor/db/dbformat.cc --compile=./vendor/db/builder.cc --compile=./vendor/db/repair.cc --compile=./vendor/db/db_impl.cc --compile=./vendor/db/dumpfile.cc --compile=./vendor/db/filename.cc --compile=./vendor/db/log_reader.cc --compile=./vendor/db/memtable.cc --compile=./vendor/db/table_cache.cc --compile=./vendor/db/c.cc --compile=./vendor/db/log_writer.cc --compile=./vendor/db/version_set.cc --compile=./vendor/db/db_iter.cc --compile=./vendor/util/hash.cc --compile=./vendor/util/options.cc --compile=./vendor/util/comparator.cc --compile=./vendor/util/coding.cc --compile=./vendor/util/histogram.cc --compile=./vendor/util/logging.cc --compile=./vendor/util/cache.cc --compile=./vendor/util/env.cc --compile=./vendor/util/filter_policy.cc --compile=./vendor/util/arena.cc --compile=./vendor/util/bloom.cc --compile=./vendor/util/crc32c.cc --compile=./vendor/util/status.cc --pnim --preprocess --noHeader ./vendor/include/leveldb/c.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} import macros @@ -62,12 +70,6 @@ macro defineEnum(typ: untyped): untyped = {.experimental: "codeReordering".} -{.passC: "-I./vendor".} -{.passC: "-I./vendor/helpers".} -{.passC: "-I./vendor/helpers/memenv".} -{.passC: "-I./vendor/port".} -{.passC: "-I./vendor/include".} -{.passC: "-I./build/include".} {.compile: "./vendor/helpers/memenv/memenv.cc".} {.compile: "./vendor/table/table.cc".} {.compile: "./vendor/table/iterator.cc".} From 9cc7d94f1afdd98792672828cd5c359e95370fa6 Mon Sep 17 00:00:00 2001 From: ThatBen Date: Fri, 10 May 2024 14:04:27 +0200 Subject: [PATCH 15/31] cleanup nimble file --- leveldb.nimble | 3 --- 1 file changed, 3 deletions(-) diff --git a/leveldb.nimble b/leveldb.nimble index 9ae390f..cfe1a78 100644 --- a/leveldb.nimble +++ b/leveldb.nimble @@ -5,11 +5,8 @@ author = "Michał Zieliński" description = "LevelDB wrapper for Nim" license = "MIT" bin = @["leveldbtool"] -# installExt = @["nim", "cc", "h", "c", "cpp"] installDirs = @["build", "leveldb", "vendor"] installFiles = @["leveldb.nim"] -#"leveldbtool.nim", "prelude.nim"] # Dependencies - requires "nim >= 1.4.0" From 85a36c48a1304bda22aa4f80a0461b4f289f0710 Mon Sep 17 00:00:00 2001 From: benbierens Date: Fri, 10 May 2024 14:09:58 +0200 Subject: [PATCH 16/31] bumps iffy/install action --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 55c9e9d..d30bfd6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/checkout@v2 with: submodules: true - - uses: iffy/install-nim@v3 + - uses: iffy/install-nim@v4 - name: Build run: nimble install -y - name: Test From dfb41a9062e022453bc9c1828500b09a9dbcf23f Mon Sep 17 00:00:00 2001 From: benbierens Date: Fri, 10 May 2024 14:28:55 +0200 Subject: [PATCH 17/31] Fixes tests for windows --- tests/packagetest/src/packagetest.nim | 6 +++++- tests/test.nim | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/packagetest/src/packagetest.nim b/tests/packagetest/src/packagetest.nim index 45c0b79..3e12356 100644 --- a/tests/packagetest/src/packagetest.nim +++ b/tests/packagetest/src/packagetest.nim @@ -1,10 +1,14 @@ +import os import options import leveldb when isMainModule: - let db = leveldb.open("/tmp/testleveldb/tooldb") + let tempDir = getTempDir() / "testleveldb" / "tooldb" + createdir(tempDir) + let db = leveldb.open(tempDir) db.put("hello", "world") let val = db.get("hello") if val.isSome() and val.get() == "world": echo "leveldb works." db.close() + removedir(tempDir) diff --git a/tests/test.nim b/tests/test.nim index 935fbd5..af12346 100644 --- a/tests/test.nim +++ b/tests/test.nim @@ -2,7 +2,7 @@ import unittest, options, os, osproc, sequtils, strutils import leveldb, leveldb/raw const - tmpDir = "/tmp/testleveldb" + tmpDir = getTempDir() / "testleveldb" tmpNimbleDir = tmpDir / "nimble" tmpDbDir = tmpDir / "testdb" @@ -31,7 +31,7 @@ proc execTool(args: varargs[string]): tuple[output: string, exitCode: int] = var quotedArgs = @args quotedArgs.insert(tmpDbDir) quotedArgs.insert("--database") - quotedArgs.insert(tmpNimbleDir / "bin" / "leveldbtool") + quotedArgs.insert(findExe(tmpNimbleDir / "bin" / "leveldbtool")) quotedArgs = quotedArgs.map(proc (x: string): string = "\"" & x & "\"") if not dirExists(tmpDbDir): @@ -214,7 +214,7 @@ suite "package": check exitCode == QuitSuccess check output.contains("leveldb installed successfully.") - cd "tests/packagetest": + cd "tests"/"packagetest": var (output, exitCode) = execNimble("build") check exitCode == QuitSuccess check output.contains("Building") From 49f87285597a2bd726a82976665f0fa70365c9b9 Mon Sep 17 00:00:00 2001 From: benbierens Date: Sat, 11 May 2024 08:04:15 +0200 Subject: [PATCH 18/31] pins leveldb to v1.23 --- vendor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor b/vendor index 068d5ee..99b3c03 160000 --- a/vendor +++ b/vendor @@ -1 +1 @@ -Subproject commit 068d5ee1a3ac40dabd00d211d5013af44be55bea +Subproject commit 99b3c03b3284f5886f9ef9a4ef703d57373e61be From 3e3e9520260e33ec467ca9b138d05fa103399e95 Mon Sep 17 00:00:00 2001 From: ThatBen Date: Sat, 11 May 2024 08:07:33 +0200 Subject: [PATCH 19/31] updates to leveldb 1.23 --- build/include/port/port_config.h | 5 ----- leveldb/raw.nim | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/build/include/port/port_config.h b/build/include/port/port_config.h index 0e80eda..5c12e38 100644 --- a/build/include/port/port_config.h +++ b/build/include/port/port_config.h @@ -30,9 +30,4 @@ #define HAVE_SNAPPY 0 #endif // !defined(HAVE_SNAPPY) -// Define to 1 if you have Zstd. -#if !defined(HAVE_Zstd) -#define HAVE_ZSTD 0 -#endif // !defined(HAVE_ZSTD) - #endif // STORAGE_LEVELDB_PORT_PORT_CONFIG_H_ diff --git a/leveldb/raw.nim b/leveldb/raw.nim index 32891e9..e6a1d58 100644 --- a/leveldb/raw.nim +++ b/leveldb/raw.nim @@ -20,7 +20,7 @@ when defined(posix): {.passC: "-I" & root/"build"/"include".} -# Generated @ 2024-05-10T13:57:11+02:00 +# Generated @ 2024-05-11T08:06:14+02:00 # Command line: # /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./vendor/helpers/memenv/memenv.cc --compile=./vendor/table/table.cc --compile=./vendor/table/iterator.cc --compile=./vendor/table/merger.cc --compile=./vendor/table/block.cc --compile=./vendor/table/table_builder.cc --compile=./vendor/table/format.cc --compile=./vendor/table/two_level_iterator.cc --compile=./vendor/table/filter_block.cc --compile=./vendor/table/block_builder.cc --compile=./vendor/db/write_batch.cc --compile=./vendor/db/version_edit.cc --compile=./vendor/db/dbformat.cc --compile=./vendor/db/builder.cc --compile=./vendor/db/repair.cc --compile=./vendor/db/db_impl.cc --compile=./vendor/db/dumpfile.cc --compile=./vendor/db/filename.cc --compile=./vendor/db/log_reader.cc --compile=./vendor/db/memtable.cc --compile=./vendor/db/table_cache.cc --compile=./vendor/db/c.cc --compile=./vendor/db/log_writer.cc --compile=./vendor/db/version_set.cc --compile=./vendor/db/db_iter.cc --compile=./vendor/util/hash.cc --compile=./vendor/util/options.cc --compile=./vendor/util/comparator.cc --compile=./vendor/util/coding.cc --compile=./vendor/util/histogram.cc --compile=./vendor/util/logging.cc --compile=./vendor/util/cache.cc --compile=./vendor/util/env.cc --compile=./vendor/util/filter_policy.cc --compile=./vendor/util/arena.cc --compile=./vendor/util/bloom.cc --compile=./vendor/util/crc32c.cc --compile=./vendor/util/status.cc --pnim --preprocess --noHeader ./vendor/include/leveldb/c.h From 1c6442d630d35655d9a10685abbb74bce8684b6a Mon Sep 17 00:00:00 2001 From: benbierens Date: Sat, 11 May 2024 08:08:38 +0200 Subject: [PATCH 20/31] Revert "updates to leveldb 1.23" This reverts commit 3e3e9520260e33ec467ca9b138d05fa103399e95. --- build/include/port/port_config.h | 5 +++++ leveldb/raw.nim | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/build/include/port/port_config.h b/build/include/port/port_config.h index 5c12e38..0e80eda 100644 --- a/build/include/port/port_config.h +++ b/build/include/port/port_config.h @@ -30,4 +30,9 @@ #define HAVE_SNAPPY 0 #endif // !defined(HAVE_SNAPPY) +// Define to 1 if you have Zstd. +#if !defined(HAVE_Zstd) +#define HAVE_ZSTD 0 +#endif // !defined(HAVE_ZSTD) + #endif // STORAGE_LEVELDB_PORT_PORT_CONFIG_H_ diff --git a/leveldb/raw.nim b/leveldb/raw.nim index e6a1d58..32891e9 100644 --- a/leveldb/raw.nim +++ b/leveldb/raw.nim @@ -20,7 +20,7 @@ when defined(posix): {.passC: "-I" & root/"build"/"include".} -# Generated @ 2024-05-11T08:06:14+02:00 +# Generated @ 2024-05-10T13:57:11+02:00 # Command line: # /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./vendor/helpers/memenv/memenv.cc --compile=./vendor/table/table.cc --compile=./vendor/table/iterator.cc --compile=./vendor/table/merger.cc --compile=./vendor/table/block.cc --compile=./vendor/table/table_builder.cc --compile=./vendor/table/format.cc --compile=./vendor/table/two_level_iterator.cc --compile=./vendor/table/filter_block.cc --compile=./vendor/table/block_builder.cc --compile=./vendor/db/write_batch.cc --compile=./vendor/db/version_edit.cc --compile=./vendor/db/dbformat.cc --compile=./vendor/db/builder.cc --compile=./vendor/db/repair.cc --compile=./vendor/db/db_impl.cc --compile=./vendor/db/dumpfile.cc --compile=./vendor/db/filename.cc --compile=./vendor/db/log_reader.cc --compile=./vendor/db/memtable.cc --compile=./vendor/db/table_cache.cc --compile=./vendor/db/c.cc --compile=./vendor/db/log_writer.cc --compile=./vendor/db/version_set.cc --compile=./vendor/db/db_iter.cc --compile=./vendor/util/hash.cc --compile=./vendor/util/options.cc --compile=./vendor/util/comparator.cc --compile=./vendor/util/coding.cc --compile=./vendor/util/histogram.cc --compile=./vendor/util/logging.cc --compile=./vendor/util/cache.cc --compile=./vendor/util/env.cc --compile=./vendor/util/filter_policy.cc --compile=./vendor/util/arena.cc --compile=./vendor/util/bloom.cc --compile=./vendor/util/crc32c.cc --compile=./vendor/util/status.cc --pnim --preprocess --noHeader ./vendor/include/leveldb/c.h From f825f0d9a8ba5a94fe084b1791490622ba563edf Mon Sep 17 00:00:00 2001 From: benbierens Date: Sat, 11 May 2024 08:08:44 +0200 Subject: [PATCH 21/31] Revert "pins leveldb to v1.23" This reverts commit 49f87285597a2bd726a82976665f0fa70365c9b9. --- vendor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor b/vendor index 99b3c03..068d5ee 160000 --- a/vendor +++ b/vendor @@ -1 +1 @@ -Subproject commit 99b3c03b3284f5886f9ef9a4ef703d57373e61be +Subproject commit 068d5ee1a3ac40dabd00d211d5013af44be55bea From 40400a784c8316346b4269baddc552d8850cb567 Mon Sep 17 00:00:00 2001 From: ThatBen Date: Mon, 13 May 2024 11:01:43 +0200 Subject: [PATCH 22/31] applies sed to passc and compile --- build.sh | 20 ++++++++++ leveldb/prelude.nim | 6 --- leveldb/raw.nim | 92 ++++++++++++++++++++++----------------------- 3 files changed, 66 insertions(+), 52 deletions(-) diff --git a/build.sh b/build.sh index c81f595..5128be9 100755 --- a/build.sh +++ b/build.sh @@ -42,5 +42,25 @@ toast \ --pnim \ --preprocess \ --noHeader \ + --includeDirs="${sourceDir}" \ + --includeDirs="${sourceDir}/helpers" \ + --includeDirs="${sourceDir}/helpers/memenv" \ + --includeDirs="${sourceDir}/port" \ + --includeDirs="${sourceDir}/include" \ + --includeDirs="${buildDir}/include" \ "${sourceDir}/include/leveldb/c.h" >> "${output}" +# {.compile: "./vendor +# {.compile: root & "/vendor + +# {.passC: "-I./vendor".} +# {.passC: "-I./build/include".} +# {.passC: "-I" & root/"vendor + + + +sed -i 's/\bpassC\b/passc/g' "${output}" + +sed -i 's/{\.compile\:\ \"\./{\.compile\:\ root\ \&\ \"/g' "${output}" +sed -i 's/{\.passc\:\ \"-I\./{\.passc\:\ \"-I\"\ \&\ root\ \&\ \"/g' "${output}" + diff --git a/leveldb/prelude.nim b/leveldb/prelude.nim index b827657..c5cc946 100644 --- a/leveldb/prelude.nim +++ b/leveldb/prelude.nim @@ -12,10 +12,4 @@ when defined(posix): {.compile: envPosix.} {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} -{.passC: "-I" & root/"vendor".} -{.passC: "-I" & root/"vendor"/"helpers".} -{.passC: "-I" & root/"vendor"/"helpers"/"memenv".} -{.passC: "-I" & root/"vendor"/"port".} -{.passC: "-I" & root/"vendor"/"include".} -{.passC: "-I" & root/"build"/"include".} diff --git a/leveldb/raw.nim b/leveldb/raw.nim index 32891e9..8557131 100644 --- a/leveldb/raw.nim +++ b/leveldb/raw.nim @@ -12,17 +12,11 @@ when defined(posix): {.compile: envPosix.} {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} -{.passC: "-I" & root/"vendor".} -{.passC: "-I" & root/"vendor"/"helpers".} -{.passC: "-I" & root/"vendor"/"helpers"/"memenv".} -{.passC: "-I" & root/"vendor"/"port".} -{.passC: "-I" & root/"vendor"/"include".} -{.passC: "-I" & root/"build"/"include".} -# Generated @ 2024-05-10T13:57:11+02:00 +# Generated @ 2024-05-13T10:59:44+02:00 # Command line: -# /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./vendor/helpers/memenv/memenv.cc --compile=./vendor/table/table.cc --compile=./vendor/table/iterator.cc --compile=./vendor/table/merger.cc --compile=./vendor/table/block.cc --compile=./vendor/table/table_builder.cc --compile=./vendor/table/format.cc --compile=./vendor/table/two_level_iterator.cc --compile=./vendor/table/filter_block.cc --compile=./vendor/table/block_builder.cc --compile=./vendor/db/write_batch.cc --compile=./vendor/db/version_edit.cc --compile=./vendor/db/dbformat.cc --compile=./vendor/db/builder.cc --compile=./vendor/db/repair.cc --compile=./vendor/db/db_impl.cc --compile=./vendor/db/dumpfile.cc --compile=./vendor/db/filename.cc --compile=./vendor/db/log_reader.cc --compile=./vendor/db/memtable.cc --compile=./vendor/db/table_cache.cc --compile=./vendor/db/c.cc --compile=./vendor/db/log_writer.cc --compile=./vendor/db/version_set.cc --compile=./vendor/db/db_iter.cc --compile=./vendor/util/hash.cc --compile=./vendor/util/options.cc --compile=./vendor/util/comparator.cc --compile=./vendor/util/coding.cc --compile=./vendor/util/histogram.cc --compile=./vendor/util/logging.cc --compile=./vendor/util/cache.cc --compile=./vendor/util/env.cc --compile=./vendor/util/filter_policy.cc --compile=./vendor/util/arena.cc --compile=./vendor/util/bloom.cc --compile=./vendor/util/crc32c.cc --compile=./vendor/util/status.cc --pnim --preprocess --noHeader ./vendor/include/leveldb/c.h +# /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./vendor/db/log_writer.cc --compile=./vendor/db/db_impl.cc --compile=./vendor/db/db_iter.cc --compile=./vendor/db/dumpfile.cc --compile=./vendor/db/c.cc --compile=./vendor/db/builder.cc --compile=./vendor/db/filename.cc --compile=./vendor/db/write_batch.cc --compile=./vendor/db/table_cache.cc --compile=./vendor/db/version_edit.cc --compile=./vendor/db/dbformat.cc --compile=./vendor/db/log_reader.cc --compile=./vendor/db/memtable.cc --compile=./vendor/db/version_set.cc --compile=./vendor/db/repair.cc --compile=./vendor/table/block.cc --compile=./vendor/table/two_level_iterator.cc --compile=./vendor/table/table_builder.cc --compile=./vendor/table/iterator.cc --compile=./vendor/table/block_builder.cc --compile=./vendor/table/merger.cc --compile=./vendor/table/format.cc --compile=./vendor/table/filter_block.cc --compile=./vendor/table/table.cc --compile=./vendor/util/hash.cc --compile=./vendor/util/arena.cc --compile=./vendor/util/options.cc --compile=./vendor/util/histogram.cc --compile=./vendor/util/crc32c.cc --compile=./vendor/util/env.cc --compile=./vendor/util/filter_policy.cc --compile=./vendor/util/bloom.cc --compile=./vendor/util/logging.cc --compile=./vendor/util/coding.cc --compile=./vendor/util/status.cc --compile=./vendor/util/cache.cc --compile=./vendor/util/comparator.cc --compile=./vendor/helpers/memenv/memenv.cc --pnim --preprocess --noHeader --includeDirs=./vendor --includeDirs=./vendor/helpers --includeDirs=./vendor/helpers/memenv --includeDirs=./vendor/port --includeDirs=./vendor/include --includeDirs=./build/include ./vendor/include/leveldb/c.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} import macros @@ -70,44 +64,50 @@ macro defineEnum(typ: untyped): untyped = {.experimental: "codeReordering".} -{.compile: "./vendor/helpers/memenv/memenv.cc".} -{.compile: "./vendor/table/table.cc".} -{.compile: "./vendor/table/iterator.cc".} -{.compile: "./vendor/table/merger.cc".} -{.compile: "./vendor/table/block.cc".} -{.compile: "./vendor/table/table_builder.cc".} -{.compile: "./vendor/table/format.cc".} -{.compile: "./vendor/table/two_level_iterator.cc".} -{.compile: "./vendor/table/filter_block.cc".} -{.compile: "./vendor/table/block_builder.cc".} -{.compile: "./vendor/db/write_batch.cc".} -{.compile: "./vendor/db/version_edit.cc".} -{.compile: "./vendor/db/dbformat.cc".} -{.compile: "./vendor/db/builder.cc".} -{.compile: "./vendor/db/repair.cc".} -{.compile: "./vendor/db/db_impl.cc".} -{.compile: "./vendor/db/dumpfile.cc".} -{.compile: "./vendor/db/filename.cc".} -{.compile: "./vendor/db/log_reader.cc".} -{.compile: "./vendor/db/memtable.cc".} -{.compile: "./vendor/db/table_cache.cc".} -{.compile: "./vendor/db/c.cc".} -{.compile: "./vendor/db/log_writer.cc".} -{.compile: "./vendor/db/version_set.cc".} -{.compile: "./vendor/db/db_iter.cc".} -{.compile: "./vendor/util/hash.cc".} -{.compile: "./vendor/util/options.cc".} -{.compile: "./vendor/util/comparator.cc".} -{.compile: "./vendor/util/coding.cc".} -{.compile: "./vendor/util/histogram.cc".} -{.compile: "./vendor/util/logging.cc".} -{.compile: "./vendor/util/cache.cc".} -{.compile: "./vendor/util/env.cc".} -{.compile: "./vendor/util/filter_policy.cc".} -{.compile: "./vendor/util/arena.cc".} -{.compile: "./vendor/util/bloom.cc".} -{.compile: "./vendor/util/crc32c.cc".} -{.compile: "./vendor/util/status.cc".} +{.passc: "-I" & root & "/vendor".} +{.passc: "-I" & root & "/vendor/helpers".} +{.passc: "-I" & root & "/vendor/helpers/memenv".} +{.passc: "-I" & root & "/vendor/port".} +{.passc: "-I" & root & "/vendor/include".} +{.passc: "-I" & root & "/build/include".} +{.compile: root & "/vendor/db/log_writer.cc".} +{.compile: root & "/vendor/db/db_impl.cc".} +{.compile: root & "/vendor/db/db_iter.cc".} +{.compile: root & "/vendor/db/dumpfile.cc".} +{.compile: root & "/vendor/db/c.cc".} +{.compile: root & "/vendor/db/builder.cc".} +{.compile: root & "/vendor/db/filename.cc".} +{.compile: root & "/vendor/db/write_batch.cc".} +{.compile: root & "/vendor/db/table_cache.cc".} +{.compile: root & "/vendor/db/version_edit.cc".} +{.compile: root & "/vendor/db/dbformat.cc".} +{.compile: root & "/vendor/db/log_reader.cc".} +{.compile: root & "/vendor/db/memtable.cc".} +{.compile: root & "/vendor/db/version_set.cc".} +{.compile: root & "/vendor/db/repair.cc".} +{.compile: root & "/vendor/table/block.cc".} +{.compile: root & "/vendor/table/two_level_iterator.cc".} +{.compile: root & "/vendor/table/table_builder.cc".} +{.compile: root & "/vendor/table/iterator.cc".} +{.compile: root & "/vendor/table/block_builder.cc".} +{.compile: root & "/vendor/table/merger.cc".} +{.compile: root & "/vendor/table/format.cc".} +{.compile: root & "/vendor/table/filter_block.cc".} +{.compile: root & "/vendor/table/table.cc".} +{.compile: root & "/vendor/util/hash.cc".} +{.compile: root & "/vendor/util/arena.cc".} +{.compile: root & "/vendor/util/options.cc".} +{.compile: root & "/vendor/util/histogram.cc".} +{.compile: root & "/vendor/util/crc32c.cc".} +{.compile: root & "/vendor/util/env.cc".} +{.compile: root & "/vendor/util/filter_policy.cc".} +{.compile: root & "/vendor/util/bloom.cc".} +{.compile: root & "/vendor/util/logging.cc".} +{.compile: root & "/vendor/util/coding.cc".} +{.compile: root & "/vendor/util/status.cc".} +{.compile: root & "/vendor/util/cache.cc".} +{.compile: root & "/vendor/util/comparator.cc".} +{.compile: root & "/vendor/helpers/memenv/memenv.cc".} defineEnum(Enum_ch1) const leveldb_no_compression* = (0).cint From 935a8569a73892528e58bf8caed40111d0f0abb3 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 13 May 2024 11:22:49 +0200 Subject: [PATCH 23/31] CI for different nim versions --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d30bfd6..bc86b01 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,11 +8,14 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest, windows-latest] + nim: [stable, 1.6.18] steps: - uses: actions/checkout@v2 with: submodules: true - uses: iffy/install-nim@v4 + with: + version: ${{ matrix.nim }} - name: Build run: nimble install -y - name: Test From c923f31e3148aab83f8716ab04ca3c5e5aac5f33 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 13 May 2024 11:28:58 +0200 Subject: [PATCH 24/31] checking build for mac --- build/include/port/port_config.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build/include/port/port_config.h b/build/include/port/port_config.h index 0e80eda..3a646b3 100644 --- a/build/include/port/port_config.h +++ b/build/include/port/port_config.h @@ -6,9 +6,10 @@ #define STORAGE_LEVELDB_PORT_PORT_CONFIG_H_ // Define to 1 if you have a definition for fdatasync() in . -#if !defined(HAVE_FDATASYNC) -#define HAVE_FDATASYNC 1 -#endif // !defined(HAVE_FDATASYNC) +// check mac build +// #if !defined(HAVE_FDATASYNC) +// #define HAVE_FDATASYNC 1 +// #endif // !defined(HAVE_FDATASYNC) // Define to 1 if you have a definition for F_FULLFSYNC in . #if !defined(HAVE_FULLFSYNC) From 1538f9a1dad5f27fd48088cba3d1e4004b5858f0 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 13 May 2024 11:38:49 +0200 Subject: [PATCH 25/31] fixes wrong LEVELDB_PLATFORM define --- leveldb/prelude.nim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/leveldb/prelude.nim b/leveldb/prelude.nim index c5cc946..d04a6ae 100644 --- a/leveldb/prelude.nim +++ b/leveldb/prelude.nim @@ -6,10 +6,11 @@ const envPosix = root/"vendor"/"util"/"env_posix.cc" when defined(windows): {.compile: envWindows.} - {.passc: "-DLEVELDB_PLATFORM_POSIX".} + {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} + {.passc: "-D_UNICODE".} + {.passc: "-DUNICODE".} when defined(posix): {.compile: envPosix.} - {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} - + {.passc: "-DLEVELDB_PLATFORM_POSIX".} From d3ba10232c3e2f237d1a070bd9c64befbda676eb Mon Sep 17 00:00:00 2001 From: ThatBen Date: Mon, 13 May 2024 11:40:03 +0200 Subject: [PATCH 26/31] rebuilds --- build/include/port/port_config.h | 7 +++---- leveldb/raw.nim | 9 +++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build/include/port/port_config.h b/build/include/port/port_config.h index 3a646b3..0e80eda 100644 --- a/build/include/port/port_config.h +++ b/build/include/port/port_config.h @@ -6,10 +6,9 @@ #define STORAGE_LEVELDB_PORT_PORT_CONFIG_H_ // Define to 1 if you have a definition for fdatasync() in . -// check mac build -// #if !defined(HAVE_FDATASYNC) -// #define HAVE_FDATASYNC 1 -// #endif // !defined(HAVE_FDATASYNC) +#if !defined(HAVE_FDATASYNC) +#define HAVE_FDATASYNC 1 +#endif // !defined(HAVE_FDATASYNC) // Define to 1 if you have a definition for F_FULLFSYNC in . #if !defined(HAVE_FULLFSYNC) diff --git a/leveldb/raw.nim b/leveldb/raw.nim index 8557131..ea4682a 100644 --- a/leveldb/raw.nim +++ b/leveldb/raw.nim @@ -6,15 +6,16 @@ const envPosix = root/"vendor"/"util"/"env_posix.cc" when defined(windows): {.compile: envWindows.} - {.passc: "-DLEVELDB_PLATFORM_POSIX".} + {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} + {.passc: "-D_UNICODE".} + {.passc: "-DUNICODE".} when defined(posix): {.compile: envPosix.} - {.passc: "-DLEVELDB_PLATFORM_WINDOWS".} + {.passc: "-DLEVELDB_PLATFORM_POSIX".} - -# Generated @ 2024-05-13T10:59:44+02:00 +# Generated @ 2024-05-13T11:39:14+02:00 # Command line: # /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./vendor/db/log_writer.cc --compile=./vendor/db/db_impl.cc --compile=./vendor/db/db_iter.cc --compile=./vendor/db/dumpfile.cc --compile=./vendor/db/c.cc --compile=./vendor/db/builder.cc --compile=./vendor/db/filename.cc --compile=./vendor/db/write_batch.cc --compile=./vendor/db/table_cache.cc --compile=./vendor/db/version_edit.cc --compile=./vendor/db/dbformat.cc --compile=./vendor/db/log_reader.cc --compile=./vendor/db/memtable.cc --compile=./vendor/db/version_set.cc --compile=./vendor/db/repair.cc --compile=./vendor/table/block.cc --compile=./vendor/table/two_level_iterator.cc --compile=./vendor/table/table_builder.cc --compile=./vendor/table/iterator.cc --compile=./vendor/table/block_builder.cc --compile=./vendor/table/merger.cc --compile=./vendor/table/format.cc --compile=./vendor/table/filter_block.cc --compile=./vendor/table/table.cc --compile=./vendor/util/hash.cc --compile=./vendor/util/arena.cc --compile=./vendor/util/options.cc --compile=./vendor/util/histogram.cc --compile=./vendor/util/crc32c.cc --compile=./vendor/util/env.cc --compile=./vendor/util/filter_policy.cc --compile=./vendor/util/bloom.cc --compile=./vendor/util/logging.cc --compile=./vendor/util/coding.cc --compile=./vendor/util/status.cc --compile=./vendor/util/cache.cc --compile=./vendor/util/comparator.cc --compile=./vendor/helpers/memenv/memenv.cc --pnim --preprocess --noHeader --includeDirs=./vendor --includeDirs=./vendor/helpers --includeDirs=./vendor/helpers/memenv --includeDirs=./vendor/port --includeDirs=./vendor/include --includeDirs=./build/include ./vendor/include/leveldb/c.h From 6b9e1a651b0ebecc4ad38f54f046e263a9fd8e56 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 13 May 2024 11:43:16 +0200 Subject: [PATCH 27/31] speed up ci by using binary --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bc86b01..26846b2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest, windows-latest] - nim: [stable, 1.6.18] + nim: ["binary:stable", "binary:1.6.18"] steps: - uses: actions/checkout@v2 with: From 2496c6814995fb4519a1c82e56fcce311840324f Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 13 May 2024 11:45:29 +0200 Subject: [PATCH 28/31] Revert "speed up ci by using binary" This reverts commit 6b9e1a651b0ebecc4ad38f54f046e263a9fd8e56. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 26846b2..bc86b01 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest, windows-latest] - nim: ["binary:stable", "binary:1.6.18"] + nim: [stable, 1.6.18] steps: - uses: actions/checkout@v2 with: From db0239b2ec4ea0ce80bc547782ff51e5f282a06c Mon Sep 17 00:00:00 2001 From: ThatBen Date: Mon, 13 May 2024 12:01:50 +0200 Subject: [PATCH 29/31] Disables all optional flags --- leveldb/prelude.nim | 9 +++++++++ leveldb/raw.nim | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/leveldb/prelude.nim b/leveldb/prelude.nim index d04a6ae..82223b5 100644 --- a/leveldb/prelude.nim +++ b/leveldb/prelude.nim @@ -14,3 +14,12 @@ when defined(posix): {.compile: envPosix.} {.passc: "-DLEVELDB_PLATFORM_POSIX".} + +{.passc: "-DHAVE_FDATASYNC=0".} +{.passc: "-DHAVE_FULLFSYNC=0".} +{.passc: "-DHAVE_O_CLOEXEC=0".} +{.passc: "-DHAVE_CRC32C=0".} +{.passc: "-DHAVE_SNAPPY=0".} +{.passc: "-DHAVE_ZSTD=0".} +{.passc: "-DHAVE_Zstd=0".} + diff --git a/leveldb/raw.nim b/leveldb/raw.nim index ea4682a..2a95fb4 100644 --- a/leveldb/raw.nim +++ b/leveldb/raw.nim @@ -15,7 +15,16 @@ when defined(posix): {.passc: "-DLEVELDB_PLATFORM_POSIX".} -# Generated @ 2024-05-13T11:39:14+02:00 +{.passc: "-DHAVE_FDATASYNC=0".} +{.passc: "-DHAVE_FULLFSYNC=0".} +{.passc: "-DHAVE_O_CLOEXEC=0".} +{.passc: "-DHAVE_CRC32C=0".} +{.passc: "-DHAVE_SNAPPY=0".} +{.passc: "-DHAVE_ZSTD=0".} +{.passc: "-DHAVE_Zstd=0".} + + +# Generated @ 2024-05-13T12:00:58+02:00 # Command line: # /home/ben/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./vendor/db/log_writer.cc --compile=./vendor/db/db_impl.cc --compile=./vendor/db/db_iter.cc --compile=./vendor/db/dumpfile.cc --compile=./vendor/db/c.cc --compile=./vendor/db/builder.cc --compile=./vendor/db/filename.cc --compile=./vendor/db/write_batch.cc --compile=./vendor/db/table_cache.cc --compile=./vendor/db/version_edit.cc --compile=./vendor/db/dbformat.cc --compile=./vendor/db/log_reader.cc --compile=./vendor/db/memtable.cc --compile=./vendor/db/version_set.cc --compile=./vendor/db/repair.cc --compile=./vendor/table/block.cc --compile=./vendor/table/two_level_iterator.cc --compile=./vendor/table/table_builder.cc --compile=./vendor/table/iterator.cc --compile=./vendor/table/block_builder.cc --compile=./vendor/table/merger.cc --compile=./vendor/table/format.cc --compile=./vendor/table/filter_block.cc --compile=./vendor/table/table.cc --compile=./vendor/util/hash.cc --compile=./vendor/util/arena.cc --compile=./vendor/util/options.cc --compile=./vendor/util/histogram.cc --compile=./vendor/util/crc32c.cc --compile=./vendor/util/env.cc --compile=./vendor/util/filter_policy.cc --compile=./vendor/util/bloom.cc --compile=./vendor/util/logging.cc --compile=./vendor/util/coding.cc --compile=./vendor/util/status.cc --compile=./vendor/util/cache.cc --compile=./vendor/util/comparator.cc --compile=./vendor/helpers/memenv/memenv.cc --pnim --preprocess --noHeader --includeDirs=./vendor --includeDirs=./vendor/helpers --includeDirs=./vendor/helpers/memenv --includeDirs=./vendor/port --includeDirs=./vendor/include --includeDirs=./build/include ./vendor/include/leveldb/c.h From 2d399e324700dc324b783fb5d2006f2e495d12df Mon Sep 17 00:00:00 2001 From: ThatBen Date: Mon, 13 May 2024 14:08:17 +0200 Subject: [PATCH 30/31] renames to leveldbstatic --- build.sh | 12 +----------- leveldb.nimble | 12 ------------ leveldb.nim => leveldbstatic.nim | 6 +++--- leveldbstatic.nimble | 12 ++++++++++++ {leveldb => leveldbstatic}/prelude.nim | 0 {leveldb => leveldbstatic}/raw.nim | 0 leveldbtool.nim | 2 +- tests/packagetest/packagetest.nimble | 2 +- tests/packagetest/src/packagetest.nim | 2 +- tests/test.nim | 5 +++-- 10 files changed, 22 insertions(+), 31 deletions(-) delete mode 100644 leveldb.nimble rename leveldb.nim => leveldbstatic.nim (99%) create mode 100644 leveldbstatic.nimble rename {leveldb => leveldbstatic}/prelude.nim (100%) rename {leveldb => leveldbstatic}/raw.nim (100%) diff --git a/build.sh b/build.sh index 5128be9..20c045f 100755 --- a/build.sh +++ b/build.sh @@ -3,7 +3,7 @@ root=$(dirname "$0") sourceDir="${root}/vendor" buildDir="${root}/build" -output="${root}/leveldb/raw.nim" +output="${root}/leveldbstatic/raw.nim" # install nimterop, if not already installed if ! [ -x "$(command -v toast)" ]; then @@ -50,17 +50,7 @@ toast \ --includeDirs="${buildDir}/include" \ "${sourceDir}/include/leveldb/c.h" >> "${output}" -# {.compile: "./vendor -# {.compile: root & "/vendor - -# {.passC: "-I./vendor".} -# {.passC: "-I./build/include".} -# {.passC: "-I" & root/"vendor - - - sed -i 's/\bpassC\b/passc/g' "${output}" - sed -i 's/{\.compile\:\ \"\./{\.compile\:\ root\ \&\ \"/g' "${output}" sed -i 's/{\.passc\:\ \"-I\./{\.passc\:\ \"-I\"\ \&\ root\ \&\ \"/g' "${output}" diff --git a/leveldb.nimble b/leveldb.nimble deleted file mode 100644 index cfe1a78..0000000 --- a/leveldb.nimble +++ /dev/null @@ -1,12 +0,0 @@ -# Package - -version = "0.4.1" -author = "Michał Zieliński" -description = "LevelDB wrapper for Nim" -license = "MIT" -bin = @["leveldbtool"] -installDirs = @["build", "leveldb", "vendor"] -installFiles = @["leveldb.nim"] - -# Dependencies -requires "nim >= 1.4.0" diff --git a/leveldb.nim b/leveldbstatic.nim similarity index 99% rename from leveldb.nim rename to leveldbstatic.nim index 2c58810..7bc69ab 100644 --- a/leveldb.nim +++ b/leveldbstatic.nim @@ -9,7 +9,7 @@ ## Create a database: ## ## .. code-block:: Nim -## import leveldb +## import leveldbstatic ## import options ## ## var db = leveldb.open("/tmp/mydata") @@ -52,7 +52,7 @@ ## db.close() import options, os, strutils -import leveldb/raw +import leveldbstatic/raw type LevelDb* = ref object @@ -78,7 +78,7 @@ type const version* = block: - const configFile = "leveldb.nimble" + const configFile = "leveldbstatic.nimble" const sourcePath = currentSourcePath() const parentConfig = sourcePath.parentDir.parentDir / configFile const localConfig = sourcePath.parentDir / configFile diff --git a/leveldbstatic.nimble b/leveldbstatic.nimble new file mode 100644 index 0000000..a185674 --- /dev/null +++ b/leveldbstatic.nimble @@ -0,0 +1,12 @@ +# Package + +version = "0.1.0" +author = "leveldbstatic authors" +description = "Statically linked LevelDB wrapper for Nim" +license = "MIT" +bin = @["leveldbtool"] +installDirs = @["build", "leveldbstatic", "vendor"] +installFiles = @["leveldbstatic.nim"] + +# Dependencies +requires "nim >= 1.4.0" diff --git a/leveldb/prelude.nim b/leveldbstatic/prelude.nim similarity index 100% rename from leveldb/prelude.nim rename to leveldbstatic/prelude.nim diff --git a/leveldb/raw.nim b/leveldbstatic/raw.nim similarity index 100% rename from leveldb/raw.nim rename to leveldbstatic/raw.nim diff --git a/leveldbtool.nim b/leveldbtool.nim index 1a485cf..27dbc5e 100644 --- a/leveldbtool.nim +++ b/leveldbtool.nim @@ -1,5 +1,5 @@ import options, os, strutils -import leveldb +import leveldbstatic as leveldb proc tool() = proc usage() = diff --git a/tests/packagetest/packagetest.nimble b/tests/packagetest/packagetest.nimble index a3e1c7d..59441c7 100644 --- a/tests/packagetest/packagetest.nimble +++ b/tests/packagetest/packagetest.nimble @@ -12,4 +12,4 @@ bin = @["packagetest"] # Dependencies requires "nim >= 0.18.0" -requires "leveldb" +requires "leveldbstatic" diff --git a/tests/packagetest/src/packagetest.nim b/tests/packagetest/src/packagetest.nim index 3e12356..3f379b7 100644 --- a/tests/packagetest/src/packagetest.nim +++ b/tests/packagetest/src/packagetest.nim @@ -1,6 +1,6 @@ import os import options -import leveldb +import leveldbstatic as leveldb when isMainModule: let tempDir = getTempDir() / "testleveldb" / "tooldb" diff --git a/tests/test.nim b/tests/test.nim index af12346..1a7d19f 100644 --- a/tests/test.nim +++ b/tests/test.nim @@ -1,5 +1,6 @@ import unittest, options, os, osproc, sequtils, strutils -import leveldb, leveldb/raw +import leveldbstatic as leveldb +import leveldbstatic/raw const tmpDir = getTempDir() / "testleveldb" @@ -212,7 +213,7 @@ suite "package": test "import as package": let (output, exitCode) = execNimble("install") check exitCode == QuitSuccess - check output.contains("leveldb installed successfully.") + check output.contains("leveldbstatic installed successfully.") cd "tests"/"packagetest": var (output, exitCode) = execNimble("build") From 1519c7cf6c96f59fba8a1ee6ed2f988d5825dae5 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 13 May 2024 14:14:27 +0200 Subject: [PATCH 31/31] updates readme --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a594d70..d21a517 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # leveldb.nim -[![docs](https://img.shields.io/badge/docs-leveldb.nim-green)](https://zielmicha.github.io/leveldb.nim/) +A self-contained LevelDB wrapper for Nim in a Nim friendly way. Uses git-submodule and nimterop so that no external libraries have to be installed or linked. -A LevelDB wrapper for Nim in a Nim friendly way. +Original nim LevelDB wrapper: [HERE](https://github.com/zielmicha/leveldb.nim) + +Replacing of system library dependency with self-contained C/CPP interoperability by (Codex.Storage)[https://codex.storage] Create a database: ```Nim - import leveldb + import leveldbstatic import options var db = leveldb.open("/tmp/mydata")