Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@
};
src = ./.;

# Build Go wallet library separately with proper dependency management
goWalletLib = import ./nix/go-wallet-lib.nix {
inherit pkgs goWalletSdk;
};

# Library package
lib = import ./nix/lib.nix {
inherit pkgs common src goWalletSdk logosSdk;
inherit pkgs common src goWalletSdk logosSdk goWalletLib;
};

# Include package (generated headers from plugin)
Expand Down
44 changes: 44 additions & 0 deletions nix/go-wallet-lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Builds the Go wallet library using buildGoModule
# This properly handles Go dependencies with vendoring
{ pkgs, goWalletSdk }:

pkgs.buildGoModule {
pname = "go-wallet-sdk-lib";
version = "0.0.1";

src = goWalletSdk;

# Hash of the Go dependencies
vendorHash = "sha256-4aiUWRiXRUgLntKvOPCuR8fJpzS+OKKh5oe5B7V74j4=";

# Ignore the existing vendor directory since it's out of sync
proxyVendor = true;

# Build flags for C shared library
buildPhase = ''
runHook preBuild

export CGO_ENABLED=1
export GOOS=${if pkgs.stdenv.isDarwin then "darwin" else "linux"}

mkdir -p $out/lib

# Build the C shared library using -mod=mod to ignore vendor directory
go build -mod=mod -buildmode=c-shared -o $out/lib/libgowalletsdk${if pkgs.stdenv.isDarwin then ".dylib" else ".so"} ./cshared

runHook postBuild
'';

# Skip default install phase since we handle it in buildPhase
installPhase = ''
# Already installed in buildPhase
echo "Library installed to $out/lib"
ls -la $out/lib/
'';

meta = with pkgs.lib; {
description = "Go Wallet SDK C shared library";
platforms = platforms.unix;
};
}

40 changes: 10 additions & 30 deletions nix/lib.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Builds the logos-wallet-module library
{ pkgs, common, src, goWalletSdk, logosSdk }:
{ pkgs, common, src, goWalletSdk, logosSdk, goWalletLib }:

pkgs.stdenv.mkDerivation {
pname = "${common.pname}-lib";
Expand All @@ -17,37 +17,17 @@ pkgs.stdenv.mkDerivation {
# Create generated_code directory for generated files
mkdir -p ./generated_code

# Set up vendor directory with go-wallet-sdk
echo "Setting up vendor directory with go-wallet-sdk"
mkdir -p vendor
cp -r ${goWalletSdk} vendor/go-wallet-sdk
chmod -R u+w vendor/go-wallet-sdk

# Build wallet library from go-wallet-sdk
echo "Building wallet library from go-wallet-sdk"

# Set up Go build environment
export HOME=$TMPDIR
export GOCACHE=$TMPDIR/go-cache
export GOPATH=$TMPDIR/go
export CGO_ENABLED=1
mkdir -p $GOCACHE $GOPATH

cd vendor/go-wallet-sdk
echo "Go version: $(go version)"
make build-c-lib
cd ../..

# Use the prebuilt Go wallet library from goWalletLib
echo "Using prebuilt Go wallet library from goWalletLib"
mkdir -p lib
echo "Checking what was built in go-wallet-sdk:"
ls -la vendor/go-wallet-sdk/build/ || echo "No build directory found"
cp vendor/go-wallet-sdk/build/libgowalletsdk.* lib/ 2>/dev/null || {
echo "Warning: No libgowalletsdk files found in vendor/go-wallet-sdk/build/"
echo "Contents of vendor/go-wallet-sdk/build/:"
ls -la vendor/go-wallet-sdk/build/ 2>/dev/null || echo "Build directory does not exist"
cp -L ${goWalletLib}/lib/libgowalletsdk.* lib/ || {
echo "Error: Could not copy prebuilt Go wallet library"
echo "Contents of ${goWalletLib}/lib/:"
ls -la ${goWalletLib}/lib/ || echo "Directory not found"
exit 1
}
echo "Wallet C library copied into lib/"
echo "Contents of lib/ after copy:"
echo "Go wallet library copied to lib/"
echo "Contents of lib/:"
ls -la lib/

# Run logos-cpp-generator with metadata.json and --general-only flag
Expand Down