nixpkgs/pkgs/development/interpreters/bqn/cbqn/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
2.9 KiB
Nix
Raw Normal View History

2023-03-16 19:34:31 +00:00
{ callPackage
, lib
, stdenv
2023-03-16 19:34:31 +00:00
, stdenvNoCC
, fetchFromGitHub
2023-05-02 07:50:44 +00:00
, fixDarwinDylibNames
, genBytecode ? false
, bqn-path ? null
, mbqn-source ? null
2022-12-01 19:06:49 +00:00
, enableReplxx ? false
2023-03-16 19:34:31 +00:00
, enableSingeli ? stdenv.hostPlatform.avx2Support
2023-05-02 07:50:44 +00:00
, enableLibcbqn ? ((stdenv.hostPlatform.isLinux || stdenv.hostPlatform.isDarwin) && !enableReplxx)
, libffi
, pkg-config
}:
let
2023-03-16 19:34:31 +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; };
in
assert genBytecode -> ((bqn-path != null) && (mbqn-source != null));
stdenv.mkDerivation rec {
pname = "cbqn" + lib.optionalString (!genBytecode) "-standalone";
2023-05-02 07:50:44 +00:00
version = "0.2.0";
src = fetchFromGitHub {
owner = "dzaima";
repo = "CBQN";
2023-05-02 07:50:44 +00:00
rev = "v${version}";
hash = "sha256-M9GTsm65DySLcMk9QDEhImHnUvWtYGPwiG657wHg3KA=";
};
nativeBuildInputs = [
pkg-config
2023-05-02 07:50:44 +00:00
] ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
buildInputs = [
libffi
];
dontConfigure = true;
postPatch = ''
sed -i '/SHELL =.*/ d' makefile
2023-05-02 07:50:44 +00:00
patchShebangs build/build
'';
makeFlags = [
"CC=${stdenv.cc.targetPrefix}cc"
];
buildFlags = [
# interpreter binary
2023-03-16 19:34:31 +00:00
(lib.flatten (if enableSingeli then ["o3n-singeli" "f='-mavx2'"] else ["o3"]))
"REPLXX=${if enableReplxx then "1" else "0"}"
] ++ lib.optionals enableLibcbqn [
# embeddable interpreter as a shared lib
"shared-o3"
];
preBuild = ''
# Purity: avoids git downloading bytecode files
mkdir -p build/bytecodeLocal/gen
'' + (if genBytecode then ''
${bqn-path} ./build/genRuntime ${mbqn-source} build/bytecodeLocal/
'' else ''
2023-03-16 19:34:31 +00:00
cp -r ${cbqn-bytecode-submodule}/dev/* build/bytecodeLocal/gen/
2022-12-01 19:06:49 +00:00
'')
+ lib.optionalString enableReplxx ''
2023-03-16 19:34:31 +00:00
cp -r ${replxx-submodule}/dev/* build/replxxLocal/
''
+ lib.optionalString enableSingeli ''
cp -r ${singeli-submodule}/dev/* build/singeliLocal/
'';
outputs = [
"out"
] ++ lib.optionals enableLibcbqn [
"lib"
"dev"
];
installPhase = ''
2023-03-16 19:34:31 +00:00
runHook preInstall
2023-03-16 19:34:31 +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
''
+ lib.optionalString enableLibcbqn ''
2023-03-16 19:34:31 +00:00
install -Dm644 include/bqnffi.h -t "$dev/include"
install -Dm755 libcbqn${stdenv.hostPlatform.extensions.sharedLibrary} -t "$lib/lib"
''
+ ''
2023-03-16 19:34:31 +00:00
runHook postInstall
'';
meta = with lib; {
homepage = "https://github.com/dzaima/CBQN/";
description = "BQN implementation in C";
license = licenses.gpl3Plus;
2023-05-02 07:50:44 +00:00
maintainers = with maintainers; [ AndersonTorres sternenseemann synthetica shnarazk detegr ];
platforms = platforms.all;
};
}
# TODO: test suite