Remove -linkshared & update Nix file to be consistent

This commit is contained in:
kdeme 2019-11-27 11:06:58 +01:00
parent 2705826cc2
commit 9472cf31a9
No known key found for this signature in database
GPG Key ID: 4E8DD21420AF43F5
3 changed files with 15 additions and 10 deletions

View File

@ -86,9 +86,9 @@ wrappers: | build deps libnimbus.so go-checks
echo -e $(BUILD_MSG) "build/C_wrapper_example" && \
$(CC) wrappers/wrapper_example.c -Wl,-rpath,'$$ORIGIN' -Lbuild -lnimbus -lm -g -o build/C_wrapper_example
echo -e $(BUILD_MSG) "build/go_wrapper_example" && \
go build -linkshared -o build/go_wrapper_example wrappers/wrapper_example.go wrappers/cfuncs.go
go build -o build/go_wrapper_example wrappers/wrapper_example.go wrappers/cfuncs.go
echo -e $(BUILD_MSG) "build/go_wrapper_whisper_example" && \
go build -linkshared -o build/go_wrapper_whisper_example wrappers/wrapper_whisper_example.go wrappers/cfuncs.go
go build -o build/go_wrapper_whisper_example wrappers/wrapper_whisper_example.go wrappers/cfuncs.go
libnimbus.a: | build deps
echo -e $(BUILD_MSG) "build/$@" && \

View File

@ -40,7 +40,7 @@ stdenv.mkDerivation rec {
LD_LIBRARY_PATH = "${makeLibraryPath buildInputs}";
buildPhase = ''
mkdir -p $TMPDIR/.nimcache ./build
mkdir -p $TMPDIR/.nimcache $TMPDIR/.nimcache_static ./build
BUILD_MSG="\\e[92mBuilding:\\e[39m"
export CC="${clang}/bin/clang"
@ -50,13 +50,11 @@ stdenv.mkDerivation rec {
vendorPathOpts="${concatMapStringsSep " " (dep: "--path:./vendor/${dep}") vendorDeps}"
echo -e $BUILD_MSG "build/libnimbus.so" && \
${nim}/bin/nim c --app:lib --noMain --nimcache:$TMPDIR/.nimcache -d:release ''${vendorPathOpts} -o:./build/libnimbus.so wrappers/libnimbus.nim
# For some reason nim doesn't output anything if we pass -o option when building the static lib
# so we just move it from the default location after it's built
echo -e $BUILD_MSG "build/libnimbus.a" && \
${nim}/bin/nim c --app:staticlib --noMain --nimcache:$TMPDIR/.nimcache -d:release ''${vendorPathOpts} wrappers/libnimbus.nim && \
mv libnimbus build/libnimbus.a
${nim}/bin/nim c --app:staticlib --noMain --nimcache:$TMPDIR/.nimcache_static -d:release ''${vendorPathOpts} -o:build/libnimbus.a wrappers/libnimbus.nim && \
[[ -e "libnimbus.a" ]] && mv "libnimbus.a" build/ # workaround for https://github.com/nim-lang/Nim/issues/12745
rm -rf $TMPDIR/.nimcache
rm -rf $TMPDIR/.nimcache $TMPDIR/.nimcache_static
'' +
optionalString buildSamples ''
mkdir -p $TMPDIR/.home/.cache
@ -65,9 +63,9 @@ stdenv.mkDerivation rec {
echo -e $BUILD_MSG "build/C_wrapper_example" && \
$CC wrappers/wrapper_example.c -Wl,-rpath,'$$ORIGIN' -Lbuild -lnimbus -lm -g -o build/C_wrapper_example
echo -e $BUILD_MSG "build/go_wrapper_example" && \
${go}/bin/go build -linkshared -o build/go_wrapper_example wrappers/wrapper_example.go wrappers/cfuncs.go
${go}/bin/go build -o build/go_wrapper_example wrappers/wrapper_example.go wrappers/cfuncs.go
echo -e $BUILD_MSG "build/go_wrapper_whisper_example" && \
${go}/bin/go build -linkshared -o build/go_wrapper_whisper_example wrappers/wrapper_whisper_example.go wrappers/cfuncs.go
${go}/bin/go build -o build/go_wrapper_whisper_example wrappers/wrapper_whisper_example.go wrappers/cfuncs.go
rm -rf $TMPDIR/.home/.cache
'';

View File

@ -26,6 +26,13 @@ To build statically linked versions:
make wrappers-static
```
You can also build the wrappers with the Nix build file (Need to
[install](https://nixos.org/nix/download.html) Nix first):
```bash
nix-build -A wrappers
```
# Notes on usage
Before any of the API calls are done, `NimMain()` needs to be run.