Merge branch 'master' of github.com:hectic-lab/util.nix
This commit is contained in:
@@ -26,16 +26,15 @@
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
{ lib
|
||||
, cargo-pgrx
|
||||
, pkg-config
|
||||
, rustPlatform
|
||||
, stdenv
|
||||
, Security
|
||||
, writeShellScriptBin
|
||||
{
|
||||
lib,
|
||||
cargo-pgrx,
|
||||
pkg-config,
|
||||
rustPlatform,
|
||||
stdenv,
|
||||
Security,
|
||||
writeShellScriptBin,
|
||||
}:
|
||||
|
||||
# The idea behind: Use it mostly like rustPlatform.buildRustPackage and so
|
||||
# we hand most of the arguments down.
|
||||
#
|
||||
@@ -46,42 +45,38 @@
|
||||
# If the generated rust bindings aren't needed to use the extension, its a
|
||||
# unnecessary and heavy dependency. If you set this to true, you also
|
||||
# have to add `rustfmt` to `nativeBuildInputs`.
|
||||
|
||||
{ buildAndTestSubdir ? null
|
||||
, buildType ? "release"
|
||||
, buildFeatures ? [ ]
|
||||
, cargoBuildFlags ? [ ]
|
||||
, postgresql
|
||||
# cargo-pgrx calls rustfmt on generated bindings, this is not strictly necessary, so we avoid the
|
||||
# dependency here. Set to false and provide rustfmt in nativeBuildInputs, if you need it, e.g.
|
||||
# if you include the generated code in the output via postInstall.
|
||||
, useFakeRustfmt ? true
|
||||
, usePgTestCheckFeature ? true
|
||||
, ...
|
||||
} @ args:
|
||||
let
|
||||
{
|
||||
buildAndTestSubdir ? null,
|
||||
buildType ? "release",
|
||||
buildFeatures ? [],
|
||||
cargoBuildFlags ? [],
|
||||
postgresql,
|
||||
# cargo-pgrx calls rustfmt on generated bindings, this is not strictly necessary, so we avoid the
|
||||
# dependency here. Set to false and provide rustfmt in nativeBuildInputs, if you need it, e.g.
|
||||
# if you include the generated code in the output via postInstall.
|
||||
useFakeRustfmt ? true,
|
||||
usePgTestCheckFeature ? true,
|
||||
...
|
||||
} @ args: let
|
||||
rustfmtInNativeBuildInputs = lib.lists.any (dep: lib.getName dep == "rustfmt") (args.nativeBuildInputs or []);
|
||||
in
|
||||
|
||||
assert lib.asserts.assertMsg ((args.installPhase or "") == "")
|
||||
assert lib.asserts.assertMsg ((args.installPhase or "") == "")
|
||||
"buildPgrxExtensions overwrites the installPhase, so providing one does nothing";
|
||||
assert lib.asserts.assertMsg ((args.buildPhase or "") == "")
|
||||
assert lib.asserts.assertMsg ((args.buildPhase or "") == "")
|
||||
"buildPgrxExtensions overwrites the buildPhase, so providing one does nothing";
|
||||
assert lib.asserts.assertMsg (useFakeRustfmt -> !rustfmtInNativeBuildInputs)
|
||||
assert lib.asserts.assertMsg (useFakeRustfmt -> !rustfmtInNativeBuildInputs)
|
||||
"The parameter useFakeRustfmt is set to true, but rustfmt is included in nativeBuildInputs. Either set useFakeRustfmt to false or remove rustfmt from nativeBuildInputs.";
|
||||
assert lib.asserts.assertMsg (!useFakeRustfmt -> rustfmtInNativeBuildInputs)
|
||||
"The parameter useFakeRustfmt is set to false, but rustfmt is not included in nativeBuildInputs. Either set useFakeRustfmt to true or add rustfmt from nativeBuildInputs.";
|
||||
|
||||
let
|
||||
fakeRustfmt = writeShellScriptBin "rustfmt" ''
|
||||
exit 0
|
||||
assert lib.asserts.assertMsg (!useFakeRustfmt -> rustfmtInNativeBuildInputs)
|
||||
"The parameter useFakeRustfmt is set to false, but rustfmt is not included in nativeBuildInputs. Either set useFakeRustfmt to true or add rustfmt from nativeBuildInputs."; let
|
||||
fakeRustfmt = writeShellScriptBin "rustfmt" ''
|
||||
exit 0
|
||||
'';
|
||||
maybeDebugFlag = lib.optionalString (buildType != "release") "--debug";
|
||||
maybeEnterBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) ''
|
||||
export CARGO_TARGET_DIR="$(pwd)/target"
|
||||
pushd "${buildAndTestSubdir}"
|
||||
'';
|
||||
maybeLeaveBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) "popd";
|
||||
maybeDebugFlag = lib.optionalString (buildType != "release") "--debug";
|
||||
maybeEnterBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) ''
|
||||
export CARGO_TARGET_DIR="$(pwd)/target"
|
||||
pushd "${buildAndTestSubdir}"
|
||||
'';
|
||||
maybeLeaveBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) "popd";
|
||||
|
||||
pgrxPostgresMajor = lib.versions.major postgresql.version;
|
||||
preBuildAndTest = ''
|
||||
@@ -97,65 +92,70 @@ let
|
||||
pg_ctl stop
|
||||
'';
|
||||
|
||||
argsForBuildRustPackage = builtins.removeAttrs args [ "postgresql" "useFakeRustfmt" "usePgTestCheckFeature" ];
|
||||
argsForBuildRustPackage = builtins.removeAttrs args ["postgresql" "useFakeRustfmt" "usePgTestCheckFeature"];
|
||||
|
||||
# so we don't accidentally `(rustPlatform.buildRustPackage argsForBuildRustPackage) // { ... }` because
|
||||
# we forgot parentheses
|
||||
finalArgs = argsForBuildRustPackage // {
|
||||
buildInputs = (args.buildInputs or [ ]) ++ lib.optionals stdenv.hostPlatform.isDarwin [ Security ];
|
||||
# so we don't accidentally `(rustPlatform.buildRustPackage argsForBuildRustPackage) // { ... }` because
|
||||
# we forgot parentheses
|
||||
finalArgs =
|
||||
argsForBuildRustPackage
|
||||
// {
|
||||
buildInputs = (args.buildInputs or []) ++ lib.optionals stdenv.hostPlatform.isDarwin [Security];
|
||||
|
||||
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
|
||||
cargo-pgrx
|
||||
postgresql
|
||||
pkg-config
|
||||
rustPlatform.bindgenHook
|
||||
] ++ lib.optionals useFakeRustfmt [ fakeRustfmt ];
|
||||
nativeBuildInputs =
|
||||
(args.nativeBuildInputs or [])
|
||||
++ [
|
||||
cargo-pgrx
|
||||
postgresql
|
||||
pkg-config
|
||||
rustPlatform.bindgenHook
|
||||
]
|
||||
++ lib.optionals useFakeRustfmt [fakeRustfmt];
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
echo "Executing cargo-pgrx buildPhase"
|
||||
${preBuildAndTest}
|
||||
${maybeEnterBuildAndTestSubdir}
|
||||
echo "Executing cargo-pgrx buildPhase"
|
||||
${preBuildAndTest}
|
||||
${maybeEnterBuildAndTestSubdir}
|
||||
|
||||
PGRX_BUILD_FLAGS="--frozen -j $NIX_BUILD_CORES ${builtins.concatStringsSep " " cargoBuildFlags}" \
|
||||
${lib.optionalString stdenv.hostPlatform.isDarwin ''RUSTFLAGS="''${RUSTFLAGS:+''${RUSTFLAGS} }-Clink-args=-Wl,-undefined,dynamic_lookup"''} \
|
||||
cargo pgrx package \
|
||||
--pg-config ${postgresql.pg_config}/bin/pg_config \
|
||||
${maybeDebugFlag} \
|
||||
--features "${builtins.concatStringsSep " " buildFeatures}" \
|
||||
--out-dir "$out"
|
||||
PGRX_BUILD_FLAGS="--frozen -j $NIX_BUILD_CORES ${builtins.concatStringsSep " " cargoBuildFlags}" \
|
||||
${lib.optionalString stdenv.hostPlatform.isDarwin ''RUSTFLAGS="''${RUSTFLAGS:+''${RUSTFLAGS} }-Clink-args=-Wl,-undefined,dynamic_lookup"''} \
|
||||
cargo pgrx package \
|
||||
--pg-config ${postgresql.pg_config}/bin/pg_config \
|
||||
${maybeDebugFlag} \
|
||||
--features "${builtins.concatStringsSep " " buildFeatures}" \
|
||||
--out-dir "$out"
|
||||
|
||||
${maybeLeaveBuildAndTestSubdir}
|
||||
${maybeLeaveBuildAndTestSubdir}
|
||||
|
||||
runHook postBuild
|
||||
'';
|
||||
runHook postBuild
|
||||
'';
|
||||
|
||||
preCheck = preBuildAndTest + args.preCheck or "";
|
||||
preCheck = preBuildAndTest + args.preCheck or "";
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
echo "Executing buildPgrxExtension install"
|
||||
echo "Executing buildPgrxExtension install"
|
||||
|
||||
${maybeEnterBuildAndTestSubdir}
|
||||
${maybeEnterBuildAndTestSubdir}
|
||||
|
||||
cargo-pgrx pgrx stop all
|
||||
cargo-pgrx pgrx stop all
|
||||
|
||||
mv $out/${postgresql}/* $out
|
||||
rm -rf $out/nix
|
||||
mv $out/${postgresql}/* $out
|
||||
rm -rf $out/nix
|
||||
|
||||
${maybeLeaveBuildAndTestSubdir}
|
||||
${maybeLeaveBuildAndTestSubdir}
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
PGRX_PG_SYS_SKIP_BINDING_REWRITE = "1";
|
||||
CARGO_BUILD_INCREMENTAL = "false";
|
||||
RUST_BACKTRACE = "full";
|
||||
PGRX_PG_SYS_SKIP_BINDING_REWRITE = "1";
|
||||
CARGO_BUILD_INCREMENTAL = "false";
|
||||
RUST_BACKTRACE = "full";
|
||||
|
||||
checkNoDefaultFeatures = true;
|
||||
checkFeatures = (args.checkFeatures or [ ]) ++ (lib.optionals usePgTestCheckFeature [ "pg_test" ]) ++ [ "pg${pgrxPostgresMajor}" ];
|
||||
};
|
||||
in
|
||||
rustPlatform.buildRustPackage finalArgs
|
||||
checkNoDefaultFeatures = true;
|
||||
checkFeatures = (args.checkFeatures or []) ++ (lib.optionals usePgTestCheckFeature ["pg_test"]) ++ ["pg${pgrxPostgresMajor}"];
|
||||
};
|
||||
in
|
||||
rustPlatform.buildRustPackage finalArgs
|
||||
|
||||
Reference in New Issue
Block a user