2021-10-01 09:20:50 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchFromGitHub
|
2021-10-04 12:37:57 +00:00
|
|
|
, genBytecode ? false
|
2021-10-01 09:20:50 +00:00
|
|
|
, bqn-path ? null
|
2021-10-04 12:37:57 +00:00
|
|
|
, mbqn-source ? null
|
2022-12-28 21:21:41 +00:00
|
|
|
, enableReplxx ? false
|
2022-10-21 18:38:19 +00:00
|
|
|
, libffi
|
2022-12-02 08:20:57 +00:00
|
|
|
, pkg-config
|
2021-10-01 09:20:50 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2022-12-28 21:21:41 +00:00
|
|
|
# TODO: these submodules should be separated libraries
|
2021-10-04 12:37:57 +00:00
|
|
|
cbqn-bytecode-files = fetchFromGitHub {
|
|
|
|
name = "cbqn-bytecode-files";
|
|
|
|
owner = "dzaima";
|
|
|
|
repo = "CBQN";
|
2022-10-21 18:38:19 +00:00
|
|
|
rev = "3df8ae563a626ff7ae0683643092f0c3bc2481e5";
|
|
|
|
hash = "sha256:0rh9qp1bdm9aa77l0kn9n4jdy08gl6l7898lncskxiq9id6xvyb8";
|
2021-10-01 09:20:50 +00:00
|
|
|
};
|
2022-12-28 21:21:41 +00:00
|
|
|
replxx-submodule = fetchFromGitHub {
|
|
|
|
name = "replxx-submodule";
|
|
|
|
owner = "dzaima";
|
|
|
|
repo = "replxx";
|
|
|
|
rev = "ba94c293caad52486df8712e808783df9a8f4501";
|
|
|
|
hash = "sha256-pMLvURksj/5k5b6BTwWxjomoROMOE5+GRjyaoqu/iYE=";
|
|
|
|
};
|
2021-10-01 09:20:50 +00:00
|
|
|
in
|
2021-10-04 12:37:57 +00:00
|
|
|
assert genBytecode -> ((bqn-path != null) && (mbqn-source != null));
|
2021-10-07 14:46:35 +00:00
|
|
|
|
2021-10-01 09:20:50 +00:00
|
|
|
stdenv.mkDerivation rec {
|
2021-10-04 12:37:57 +00:00
|
|
|
pname = "cbqn" + lib.optionalString (!genBytecode) "-standalone";
|
2022-12-02 08:20:57 +00:00
|
|
|
version = "0.pre+date=2022-11-27";
|
2021-10-01 09:20:50 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "dzaima";
|
|
|
|
repo = "CBQN";
|
2022-12-28 21:21:41 +00:00
|
|
|
rev = "49c0d9a355698f54fff2c0caa177e2b341fabb45";
|
|
|
|
hash = "sha256-jm2ZzFxhr9o4nFR2rjYJz/4GH+WFnfU4QDovrOPI3jQ=";
|
2021-10-01 09:20:50 +00:00
|
|
|
};
|
|
|
|
|
2022-12-02 08:20:57 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
pkg-config
|
|
|
|
];
|
|
|
|
|
|
|
|
# TODO(@sternenseemann): allow building against dzaima's replxx fork
|
2022-10-21 18:38:19 +00:00
|
|
|
buildInputs = [
|
|
|
|
libffi
|
|
|
|
];
|
|
|
|
|
2021-10-01 09:20:50 +00:00
|
|
|
dontConfigure = true;
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
sed -i '/SHELL =.*/ d' makefile
|
|
|
|
'';
|
|
|
|
|
2021-10-11 16:52:03 +00:00
|
|
|
makeFlags = [
|
|
|
|
"CC=${stdenv.cc.targetPrefix}cc"
|
2022-12-28 21:21:41 +00:00
|
|
|
]
|
|
|
|
++ lib.optional enableReplxx "REPLXX=1";
|
2021-10-07 14:46:35 +00:00
|
|
|
|
2021-10-11 16:52:03 +00:00
|
|
|
preBuild = ''
|
|
|
|
# Purity: avoids git downloading bytecode files
|
2022-12-02 08:20:57 +00:00
|
|
|
mkdir -p build/bytecodeLocal/gen
|
2021-10-06 13:57:05 +00:00
|
|
|
'' + (if genBytecode then ''
|
2022-12-02 08:20:57 +00:00
|
|
|
${bqn-path} ./build/genRuntime ${mbqn-source} build/bytecodeLocal/
|
2021-10-06 13:57:05 +00:00
|
|
|
'' else ''
|
2022-12-02 08:20:57 +00:00
|
|
|
cp ${cbqn-bytecode-files}/src/gen/{compiles,explain,formatter,runtime0,runtime1,src} build/bytecodeLocal/gen/
|
2022-12-28 21:21:41 +00:00
|
|
|
'')
|
|
|
|
+ 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")
|
|
|
|
'';
|
2021-10-01 09:20:50 +00:00
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
mkdir -p $out/bin/
|
|
|
|
cp BQN -t $out/bin/
|
2021-12-06 16:07:01 +00:00
|
|
|
# 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
|
2021-10-01 09:20:50 +00:00
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
homepage = "https://github.com/dzaima/CBQN/";
|
|
|
|
description = "BQN implementation in C";
|
|
|
|
license = licenses.gpl3Plus;
|
2022-05-18 14:49:53 +00:00
|
|
|
maintainers = with maintainers; [ AndersonTorres sternenseemann synthetica shnarazk ];
|
2021-10-01 09:20:50 +00:00
|
|
|
platforms = platforms.all;
|
|
|
|
};
|
|
|
|
}
|
2021-10-07 14:46:35 +00:00
|
|
|
# TODO: version cbqn-bytecode-files
|
2021-10-04 12:37:57 +00:00
|
|
|
# TODO: test suite
|