Revert "crystal: build using Makefile or shards if available"

This reverts commit 2ec0ad59849ee1a652a6534a2d2672fdb7b5fed5.
This commit is contained in:
Michael Fellinger 2020-04-17 18:18:36 +02:00
parent 85897a4423
commit dce6dd3345
No known key found for this signature in database
GPG Key ID: F4D029589C005F89

View File

@ -1,9 +1,6 @@
{ stdenv, lib, crystal, shards, git, pkgconfig, which, linkFarm, fetchFromGitHub }: { stdenv, lib, crystal, linkFarm, fetchFromGitHub }:
{ { # Generate shards.nix with `nix-shell -p crystal2nix --run crystal2nix` in the projects root
# Some projects do not include a lock file, so you can pass one shardsFile ? null
lockFile ? null
# Generate shards.nix with `nix-shell -p crystal2nix --run crystal2nix` in the projects root
, shardsFile ? null
# Specify binaries to build in the form { foo.src = "src/foo.cr"; } # Specify binaries to build in the form { foo.src = "src/foo.cr"; }
# The default `crystal build` options can be overridden with { foo.options = [ "--no-debug" ]; } # The default `crystal build` options can be overridden with { foo.options = [ "--no-debug" ]; }
, crystalBinaries ? {} , crystalBinaries ? {}
@ -12,102 +9,45 @@
let let
mkDerivationArgs = builtins.removeAttrs args [ "shardsFile" "crystalBinaries" ]; mkDerivationArgs = builtins.removeAttrs args [ "shardsFile" "crystalBinaries" ];
crystalLib = linkFarm "crystal-lib" ( crystalLib = linkFarm "crystal-lib" (lib.mapAttrsToList (name: value: {
lib.mapAttrsToList (
name: value: {
inherit name; inherit name;
path = fetchFromGitHub value; path = fetchFromGitHub value;
} }) (import shardsFile));
) (import shardsFile)
);
# we previously had --no-debug here but that is not recommended by upstream defaultOptions = [ "--release" "--progress" "--no-debug" "--verbose" ];
defaultOptions = [ "--release" "--progress" "--verbose" ];
buildDirectly = shardsFile == null || crystalBinaries != {}; in stdenv.mkDerivation (mkDerivationArgs // {
in
stdenv.mkDerivation (
mkDerivationArgs // {
configurePhase = args.configurePhase or '' configurePhase = args.configurePhase or ''
runHook preConfigure runHook preConfigure
${lib.optionalString (lockFile != null) "ln -s ${lockFile} ./shard.lock"}
${lib.optionalString (shardsFile != null) "ln -s ${crystalLib} lib"} ${lib.optionalString (shardsFile != null) "ln -s ${crystalLib} lib"}
runHook postConfigure runHook postConfigure
''; '';
CRFLAGS = lib.concatStringsSep " " defaultOptions; buildInputs = args.buildInputs or [] ++ [ crystal ];
buildInputs = args.buildInputs or [] ++ [ crystal shards ]; buildPhase = args.buildPhase or ''
nativeBuildInputs = args.nativeBuildInputs or [] ++ [ git pkgconfig which ];
buildPhase = args.buildPhase or (
''
runHook preBuild runHook preBuild
${lib.concatStringsSep "\n" (lib.mapAttrsToList (bin: attrs: ''
if [ -e Makefile ]; then crystal ${lib.escapeShellArgs ([
echo " ** building with make"
make ''${buildTargets:-build} $buildFlags
else
'' + (
if buildDirectly then ''
echo " ** building with crystal"
${lib.concatStringsSep "\n" (
lib.mapAttrsToList (
bin: attrs: ''
crystal ${lib.escapeShellArgs (
[
"build" "build"
"-o" "-o" bin
bin
(attrs.src or (throw "No source file for crystal binary ${bin} provided")) (attrs.src or (throw "No source file for crystal binary ${bin} provided"))
] ++ attrs.options or defaultOptions ] ++ attrs.options or defaultOptions)}
)} '') crystalBinaries)}
''
) crystalBinaries
)}
'' else ''
echo " ** building with shards"
shards build --local --production ${lib.concatStringsSep " " defaultOptions}
''
) + ''
fi
runHook postBuild runHook postBuild
'' '';
);
installPhase = args.installPhase or ( installPhase = args.installPhase or ''
''
runHook preInstall runHook preInstall
mkdir -p "$out/bin"
if [ -e Makefile ]; then ${lib.concatMapStringsSep "\n" (bin: ''
make ''${installTargets:-install} $installFlags mv ${lib.escapeShellArgs [ bin "${placeholder "out"}/bin/${bin}" ]}
else '') (lib.attrNames crystalBinaries)}
'' + (
if buildDirectly then
lib.concatMapStringsSep "\n" (
bin: ''
install -Dm555 ${lib.escapeShellArgs [ bin "${placeholder "out"}/bin/${bin}" ]}
''
) (lib.attrNames crystalBinaries)
else ''
shards install
''
) + ''
fi
runHook postInstall runHook postInstall
'' '';
);
meta = args.meta or {} // { meta = args.meta or {} // {
platforms = args.meta.platforms or crystal.meta.platforms; platforms = args.meta.platforms or crystal.meta.platforms;
}; };
} })
)