diff --git a/README.md b/README.md index d21a517..31f8ddf 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ 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] +## Usage + Create a database: ```Nim import leveldbstatic @@ -49,3 +51,13 @@ Iterate over subset of database content: db.close() ``` + +## Compiling with optimizations + +This library can be compiled with the following optimization options. By default these are disabled. Provide the following nim compiler flags to enable them: + - fdatasync from `--passC:-DHAVE_FDATASYNC=1` + - F_FULLSYNC from `--passC:-DHAVE_FULLFSYNC=1` + - O_CLOEXEC from `--passC:-DHAVE_O_CLOEXEC=1` + - crc32c from `--passC:-DHAVE_CRC32C=1` + - snappy from `--passC:-DHAVE_SNAPPY=1` + - zstd from `--passC:-DHAVE_ZSTD=1` diff --git a/build.sh b/build.sh index 55bbe9c..dd683df 100755 --- a/build.sh +++ b/build.sh @@ -47,10 +47,9 @@ toast \ --includeDirs="${sourceDir}/helpers/memenv" \ --includeDirs="${sourceDir}/port" \ --includeDirs="${sourceDir}/include" \ - --includeDirs="${buildDir}/include" \ + --includeDirs="${root}/leveldbstatic/include" \ "${sourceDir}/include/leveldb/c.h" >> "${output}" 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/build/.keep b/build/.keep new file mode 100644 index 0000000..e69de29 diff --git a/checkers/check_crc32c.c b/checkers/check_crc32c.c deleted file mode 100644 index 4eca8f1..0000000 --- a/checkers/check_crc32c.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int main(int argc, char** argv) -{ - char* buffer; - size_t size; - ::crc32c::Extend(0, buffer, size); - return 0; -} diff --git a/checkers/check_fdatasync.c b/checkers/check_fdatasync.c deleted file mode 100644 index 63d1ed1..0000000 --- a/checkers/check_fdatasync.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(int argc, char** argv) -{ - fdatasync(-1); - return 0; -} diff --git a/checkers/check_fullfsync.c b/checkers/check_fullfsync.c deleted file mode 100644 index 7632eed..0000000 --- a/checkers/check_fullfsync.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(int argc, char** argv) -{ - int i = F_FULLSYNC; - return 0; -} diff --git a/checkers/check_ocloexec.c b/checkers/check_ocloexec.c deleted file mode 100644 index c719871..0000000 --- a/checkers/check_ocloexec.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(int argc, char** argv) -{ - int i = O_CLOEXEC; - return 0; -} diff --git a/checkers/check_snappy.c b/checkers/check_snappy.c deleted file mode 100644 index 21b8111..0000000 --- a/checkers/check_snappy.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int main(int argc, char** argv) -{ - char* input; - size_t length; - size_t result; - snappy::GetUncompressedLength(input, length, &result); - return 0; -} diff --git a/checkers/check_zstd.c b/checkers/check_zstd.c deleted file mode 100644 index 837cdb0..0000000 --- a/checkers/check_zstd.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int main(int argc, char** argv) -{ - size_t length; - ZSTD_compressBound(length); - return 0; -} diff --git a/build/include/port/port_config.h b/leveldbstatic/include/port/port_config.h similarity index 93% rename from build/include/port/port_config.h rename to leveldbstatic/include/port/port_config.h index 0e80eda..a1b8c7a 100644 --- a/build/include/port/port_config.h +++ b/leveldbstatic/include/port/port_config.h @@ -7,7 +7,7 @@ // Define to 1 if you have a definition for fdatasync() in . #if !defined(HAVE_FDATASYNC) -#define HAVE_FDATASYNC 1 +#define HAVE_FDATASYNC 0 #endif // !defined(HAVE_FDATASYNC) // Define to 1 if you have a definition for F_FULLFSYNC in . @@ -17,7 +17,7 @@ // Define to 1 if you have a definition for O_CLOEXEC in . #if !defined(HAVE_O_CLOEXEC) -#define HAVE_O_CLOEXEC 1 +#define HAVE_O_CLOEXEC 0 #endif // !defined(HAVE_O_CLOEXEC) // Define to 1 if you have Google CRC32C. @@ -31,7 +31,7 @@ #endif // !defined(HAVE_SNAPPY) // Define to 1 if you have Zstd. -#if !defined(HAVE_Zstd) +#if !defined(HAVE_ZSTD) #define HAVE_ZSTD 0 #endif // !defined(HAVE_ZSTD) diff --git a/leveldbstatic/prelude.nim b/leveldbstatic/prelude.nim index 377685c..b000f9c 100644 --- a/leveldbstatic/prelude.nim +++ b/leveldbstatic/prelude.nim @@ -3,7 +3,6 @@ import os const root = currentSourcePath.parentDir.parentDir const envWindows = root/"vendor"/"util"/"env_windows.cc" const envPosix = root/"vendor"/"util"/"env_posix.cc" -const checkers = root/"checkers" when defined(windows): {.compile: envWindows.} @@ -14,20 +13,3 @@ when defined(windows): when defined(posix): {.compile: envPosix.} {.passc: "-DLEVELDB_PLATFORM_POSIX".} - - -static: - proc doesCompile(cfile: string): int = - let rv = gorgeEx("gcc " & cfile) - if rv[1] == 0: - return 1 - return 0 - - {.passc: "-DHAVE_FDATASYNC=" & $doesCompile(checkers/"check_fdatasync.c").} - {.passc: "-DHAVE_FULLFSYNC=" & $doesCompile(checkers/"check_fullfsync.c").} - {.passc: "-DHAVE_O_CLOEXEC=" & $doesCompile(checkers/"check_ocloexec.c").} - {.passc: "-DHAVE_CRC32C=" & $doesCompile(checkers/"check_crc32c.c").} - {.passc: "-DHAVE_SNAPPY=" & $doesCompile(checkers/"check_snappy.c").} - {.passc: "-DHAVE_ZSTD=" & $doesCompile(checkers/"check_zstd.c").} - {.passc: "-DHAVE_Zstd=" & $doesCompile(checkers/"check_zstd.c").} -