Restores build.sh

This commit is contained in:
ThatBen 2024-05-21 13:50:03 +02:00
parent 37af6e5b9b
commit a2ee78dcd4
3 changed files with 110 additions and 11 deletions

55
build.sh Executable file
View File

@ -0,0 +1,55 @@
#!/bin/bash
root=$(dirname "$0")
sourceDir="${root}/vendor"
buildDir="${root}/build"
output="${root}/leveldbstatic/raw.nim"
# install nimterop, if not already installed
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 "${sourceDir}" -B "${buildDir}"
# Remove testing, benchmarking, third-party libraries.
rm -Rf "${sourceDir}/third_party"
rm -Rf "${sourceDir}/benchmarks"
rm "${sourceDir}/util/testutil.cc"
# Prelude:
cat "${root}/leveldbstatic/prelude.nim" > "${output}"
echo >> "${output}"
# assemble files to be compiled:
extensions="c cc cpp"
for ext in ${extensions}; do
for file in `find "${sourceDir}" -type f -name "*.${ext}" \
| grep -v "_test" \
| grep -v "env_windows.cc" \
| grep -v "env_posix.cc" \
| grep -v "leveldbutil.cc"`; do
compile="${compile} --compile=${file}"
done
done
# generate nim wrapper with nimterop
toast \
$compile \
--pnim \
--preprocess \
--noHeader \
--includeDirs="${sourceDir}" \
--includeDirs="${sourceDir}/helpers" \
--includeDirs="${sourceDir}/helpers/memenv" \
--includeDirs="${sourceDir}/port" \
--includeDirs="${sourceDir}/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}"

44
leveldbstatic/prelude.nim Normal file
View File

@ -0,0 +1,44 @@
import os
const
root = currentSourcePath.parentDir.parentDir
envWindows = root/"vendor"/"util"/"env_windows.cc"
envPosix = root/"vendor"/"util"/"env_posix.cc"
LevelDbCMakeFlags {.strdefine.} =
when defined(macosx):
"-DCMAKE_BUILD_TYPE=Release"
elif defined(windows):
"-G\"MSYS Makefiles\" -DCMAKE_BUILD_TYPE=Release"
else:
"-DCMAKE_BUILD_TYPE=Release"
LevelDbDir {.strdefine.} = $(root/"vendor")
buildDir = $(root/"build")
static:
echo "Initializing submodule..."
discard gorge "git submodule deinit -f \"" & root & "\""
discard gorge "git submodule update --init --recursive --checkout \"" & root & "\""
echo "\nClean dir: \"" & buildDir & "\""
discard gorge "rm -rf " & buildDir
discard gorge "mkdir -p " & buildDir
let cmd = "cmake -S \"" & LevelDbDir & "\" -B \"" & buildDir & "\" " & LevelDbCmakeFlags
echo "\nBuilding LevelDB: " & cmd
let (output, exitCode) = gorgeEx cmd
if exitCode != 0:
discard gorge "rm -rf " & buildDir
echo output
raise (ref Defect)(msg: "Failed to build LevelDB")
when defined(windows):
{.compile: envWindows.}
{.passc: "-DLEVELDB_PLATFORM_WINDOWS".}
{.passc: "-D_UNICODE".}
{.passc: "-DUNICODE".}
when defined(posix):
{.compile: envPosix.}
{.passc: "-DLEVELDB_PLATFORM_POSIX".}

View File

@ -1,36 +1,36 @@
import os
const root = currentSourcePath.parentDir.parentDir
const envWindows = root/"vendor"/"util"/"env_windows.cc"
const envPosix = root/"vendor"/"util"/"env_posix.cc"
const
LevelDbCmakeFlags {.strdefine.} =
root = currentSourcePath.parentDir.parentDir
envWindows = root/"vendor"/"util"/"env_windows.cc"
envPosix = root/"vendor"/"util"/"env_posix.cc"
LevelDbCMakeFlags {.strdefine.} =
when defined(macosx):
"-DCMAKE_BUILD_TYPE=Release"
elif defined(windows):
"-G\"MSYS Makefiles\" -DCMAKE_BUILD_TYPE=Release"
else:
"-DCMAKE_BUILD_TYPE=Release"
LevelDbDir {.strdefine.} = $(root/"vendor")
buildDir = $(root/"build")
static:
echo "Initialize submodule"
echo "Initializing submodule..."
discard gorge "git submodule deinit -f \"" & root & "\""
discard gorge "git submodule update --init --recursive --checkout \"" & root & "\""
echo "Clean dir: \"" & buildDir & "\""
echo "\nClean dir: \"" & buildDir & "\""
discard gorge "rm -rf " & buildDir
discard gorge "mkdir -p " & buildDir
let cmd = "cmake -S \"" & LevelDbDir & "\" -B \"" & buildDir & "\" " & LevelDbCmakeFlags
echo "\nBuilding LevelDB: " & cmd
let (output, exitCode) = gorgeEx cmd
echo output
if exitCode != 0:
discard gorge "rm -rf " & buildDir
echo output
raise (ref Defect)(msg: "Failed to build LevelDB")
when defined(windows):
@ -43,7 +43,7 @@ when defined(posix):
{.compile: envPosix.}
{.passc: "-DLEVELDB_PLATFORM_POSIX".}
# Generated @ 2024-05-16T10:57:24+02:00
# Generated @ 2024-05-21T13:49:00+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=./leveldbstatic/include ./vendor/include/leveldb/c.h