Unverified Commit 52f11dd9 authored by Anderson Torres's avatar Anderson Torres Committed by GitHub
Browse files

Merge pull request #208389 from sternenseemann/cbqn-lib

 cbqn: install headers and shared library 
parents a3463841 c7667f19
Loading
Loading
Loading
Loading
+22 −7
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@
, bqn-path ? null
, mbqn-source ? null
, enableReplxx ? false
  # No support for macOS' .dylib on the CBQN side
, enableLibcbqn ? stdenv.hostPlatform.isLinux
, libffi
, pkg-config
}:
@@ -43,7 +45,6 @@ stdenv.mkDerivation rec {
    pkg-config
  ];

  # TODO(@sternenseemann): allow building against dzaima's replxx fork
  buildInputs = [
    libffi
  ];
@@ -59,6 +60,14 @@ stdenv.mkDerivation rec {
  ]
  ++ lib.optional enableReplxx "REPLXX=1";

  buildFlags = [
    # interpreter binary
    "o3"
  ] ++ lib.optionals enableLibcbqn [
    # embeddable interpreter as a shared lib
    "shared-o3"
  ];

  preBuild = ''
    # Purity: avoids git downloading bytecode files
    mkdir -p build/bytecodeLocal/gen
@@ -69,13 +78,14 @@ stdenv.mkDerivation rec {
  '')
  + lib.optionalString enableReplxx ''
    cp -r ${replxx-submodule} build/replxxLocal/
  ''
  # Need to adjust ld flags for darwin manually
  # https://github.com/dzaima/CBQN/issues/26
  + lib.optionalString stdenv.hostPlatform.isDarwin ''
    makeFlagsArray+=(LD_LIBS="-ldl -lffi")
  '';

  outputs = [
    "out"
    "lib"
    "dev"
  ];

  installPhase = ''
     runHook preInstall

@@ -84,7 +94,12 @@ stdenv.mkDerivation rec {
     # note guard condition for case-insensitive filesystems
     [ -e $out/bin/bqn ] || ln -s $out/bin/BQN $out/bin/bqn
     [ -e $out/bin/cbqn ] || ln -s $out/bin/BQN $out/bin/cbqn

  ''
  + lib.optionalString enableLibcbqn ''
     install -Dm644 include/bqnffi.h -t "$dev/include"
     install -Dm755 libcbqn${stdenv.hostPlatform.extensions.sharedLibrary} -t "$lib/lib"
  ''
  + ''
     runHook postInstall
  '';