Unverified Commit b9f01612 authored by Maximilian Bosch's avatar Maximilian Bosch
Browse files

buildPgrxExtension: enable building workspaces

Doing

    cargoBuildFlags = [ "-p" "foo" ]

doesn't work here since this gets only passed to PGRX_BUILD_FLAGS which
in turn is used by `cargo build`.

This means that pgrx itself doesn't know of the workspace setup and
fails with

    Error:
    0: Couldn't get manifest path
    1: `pgrx` requires a root package in a workspace when `--package` is not specified.

This patch introduces another flag called `cargoPgrxFlags` to do the
right thing, i.e. to pass this to each pgrx invocation.

Using `cargoBuildFlags` is not reasonable here since `cargo build`
accepts flags that may not be valid when invoking `cargo pgrx` (e.g. `-r`).
parent d95226c4
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@
  buildType ? "release",
  buildFeatures ? [ ],
  cargoBuildFlags ? [ ],
  cargoPgrxFlags ? [ ],
  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.
@@ -115,6 +116,8 @@ let
    "usePgTestCheckFeature"
  ];

  cargoPgrxFlags' = lib.escapeShellArgs cargoPgrxFlags;

  # so we don't accidentally `(rustPlatform.buildRustPackage argsForBuildRustPackage) // { ... }` because
  # we forgot parentheses
  finalArgs = argsForBuildRustPackage // {
@@ -140,6 +143,7 @@ let
      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 \
        ${cargoPgrxFlags'} \
        --pg-config ${lib.getDev postgresql}/bin/pg_config \
        ${maybeDebugFlag} \
        --features "${builtins.concatStringsSep " " buildFeatures}" \
@@ -159,7 +163,7 @@ let

      ${maybeEnterBuildAndTestSubdir}

      cargo-pgrx pgrx stop all
      cargo-pgrx pgrx stop all ${cargoPgrxFlags'}

      mv $out/${postgresql}/* $out
      rm -rf $out/nix