2023-03-24 00:07:29 +00:00
|
|
|
{ callPackage
|
|
|
|
, lib
|
2021-10-01 09:20:50 +00:00
|
|
|
, stdenv
|
2023-03-24 00:07:29 +00:00
|
|
|
, stdenvNoCC
|
2021-10-01 09:20:50 +00:00
|
|
|
, fetchFromGitHub
|
2023-05-24 13:37:59 +00:00
|
|
|
, fixDarwinDylibNames
|
2021-10-04 12:37:57 +00:00
|
|
|
, genBytecode ? false
|
2021-10-01 09:20:50 +00:00
|
|
|
, bqn-path ? null
|
2023-05-24 13:37:59 +00:00
|
|
|
, mbqn-source
|
2022-12-28 21:21:41 +00:00
|
|
|
, enableReplxx ? false
|
2023-05-24 13:37:59 +00:00
|
|
|
, enableLibcbqn ? ((stdenv.hostPlatform.isLinux || stdenv.hostPlatform.isDarwin) && !enableReplxx)
|
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
|
2023-03-24 00:07:29 +00:00
|
|
|
cbqn-bytecode-submodule =
|
|
|
|
callPackage ./cbqn-bytecode.nix { inherit lib fetchFromGitHub stdenvNoCC; };
|
|
|
|
replxx-submodule = callPackage ./replxx.nix { inherit lib fetchFromGitHub stdenvNoCC; };
|
|
|
|
singeli-submodule = callPackage ./singeli.nix { inherit lib fetchFromGitHub stdenvNoCC; };
|
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";
|
2023-05-24 13:37:59 +00:00
|
|
|
version = "0.3.0";
|
2021-10-01 09:20:50 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "dzaima";
|
|
|
|
repo = "CBQN";
|
2023-05-24 13:37:59 +00:00
|
|
|
rev = "v${version}";
|
|
|
|
hash = "sha256-LoxwNxuadbYJgIkr1+bZoErTc9WllN2siAsKnxoom3Y=";
|
2021-10-01 09:20:50 +00:00
|
|
|
};
|
|
|
|
|
2022-12-02 08:20:57 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
pkg-config
|
2023-05-24 13:37:59 +00:00
|
|
|
] ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
|
2022-12-02 08:20:57 +00:00
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
buildInputs = [
|
|
|
|
libffi
|
|
|
|
];
|
|
|
|
|
2021-10-01 09:20:50 +00:00
|
|
|
dontConfigure = true;
|
2023-05-24 13:37:59 +00:00
|
|
|
doInstallCheck = true;
|
2021-10-01 09:20:50 +00:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
sed -i '/SHELL =.*/ d' makefile
|
2023-05-24 13:37:59 +00:00
|
|
|
patchShebangs build/build
|
2021-10-01 09:20:50 +00:00
|
|
|
'';
|
|
|
|
|
2021-10-11 16:52:03 +00:00
|
|
|
makeFlags = [
|
|
|
|
"CC=${stdenv.cc.targetPrefix}cc"
|
2023-05-24 13:37:59 +00:00
|
|
|
];
|
2021-10-07 14:46:35 +00:00
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
buildFlags = [
|
|
|
|
# interpreter binary
|
2023-05-24 13:37:59 +00:00
|
|
|
"o3"
|
|
|
|
"notui=1" # display build progress in a plain-text format
|
|
|
|
"REPLXX=${if enableReplxx then "1" else "0"}"
|
|
|
|
] ++ lib.optionals stdenv.hostPlatform.avx2Support [
|
|
|
|
"has=avx2"
|
2023-01-11 07:51:40 +00:00
|
|
|
] ++ lib.optionals enableLibcbqn [
|
|
|
|
# embeddable interpreter as a shared lib
|
|
|
|
"shared-o3"
|
|
|
|
];
|
|
|
|
|
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
|
2023-05-24 13:37:59 +00:00
|
|
|
cp -r ${singeli-submodule}/dev/* build/singeliLocal/
|
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 ''
|
2023-03-24 00:07:29 +00:00
|
|
|
cp -r ${cbqn-bytecode-submodule}/dev/* build/bytecodeLocal/gen/
|
2022-12-28 21:21:41 +00:00
|
|
|
'')
|
|
|
|
+ lib.optionalString enableReplxx ''
|
2023-03-24 00:07:29 +00:00
|
|
|
cp -r ${replxx-submodule}/dev/* build/replxxLocal/
|
2023-05-24 13:37:59 +00:00
|
|
|
'';
|
2021-10-01 09:20:50 +00:00
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
outputs = [
|
|
|
|
"out"
|
2023-02-02 18:25:31 +00:00
|
|
|
] ++ lib.optionals enableLibcbqn [
|
2023-01-11 07:51:40 +00:00
|
|
|
"lib"
|
|
|
|
"dev"
|
|
|
|
];
|
|
|
|
|
2021-10-01 09:20:50 +00:00
|
|
|
installPhase = ''
|
2023-03-24 00:07:29 +00:00
|
|
|
runHook preInstall
|
2021-10-01 09:20:50 +00:00
|
|
|
|
2023-03-24 00:07:29 +00:00
|
|
|
mkdir -p $out/bin/
|
|
|
|
cp BQN -t $out/bin/
|
|
|
|
# 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
|
2023-01-11 07:51:40 +00:00
|
|
|
''
|
|
|
|
+ lib.optionalString enableLibcbqn ''
|
2023-03-24 00:07:29 +00:00
|
|
|
install -Dm644 include/bqnffi.h -t "$dev/include"
|
|
|
|
install -Dm755 libcbqn${stdenv.hostPlatform.extensions.sharedLibrary} -t "$lib/lib"
|
2023-01-11 07:51:40 +00:00
|
|
|
''
|
|
|
|
+ ''
|
2023-03-24 00:07:29 +00:00
|
|
|
runHook postInstall
|
2021-10-01 09:20:50 +00:00
|
|
|
'';
|
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
installCheckPhase = ''
|
|
|
|
runHook preInstallCheck
|
|
|
|
|
|
|
|
# main test suite from mlochbaum/BQN
|
|
|
|
$out/bin/BQN ${mbqn-source}/test/this.bqn
|
|
|
|
|
|
|
|
# CBQN tests that do not require compiling with test-only flags
|
|
|
|
$out/bin/BQN test/cmp.bqn
|
|
|
|
$out/bin/BQN test/equal.bqn
|
|
|
|
$out/bin/BQN test/copy.bqn
|
|
|
|
$out/bin/BQN test/bit.bqn
|
|
|
|
$out/bin/BQN test/hash.bqn
|
|
|
|
$out/bin/BQN test/squeezeValid.bqn
|
|
|
|
$out/bin/BQN test/squeezeExact.bqn
|
|
|
|
$out/bin/BQN test/various.bqn
|
|
|
|
$out/bin/BQN test/random.bqn
|
|
|
|
|
|
|
|
runHook postInstallCheck
|
|
|
|
'';
|
|
|
|
|
2021-10-01 09:20:50 +00:00
|
|
|
meta = with lib; {
|
|
|
|
homepage = "https://github.com/dzaima/CBQN/";
|
|
|
|
description = "BQN implementation in C";
|
|
|
|
license = licenses.gpl3Plus;
|
2023-05-24 13:37:59 +00:00
|
|
|
maintainers = with maintainers; [ AndersonTorres sternenseemann synthetica shnarazk detegr ];
|
2021-10-01 09:20:50 +00:00
|
|
|
platforms = platforms.all;
|
|
|
|
};
|
|
|
|
}
|