Skip to content

feat: multiple versions for the wrappers extension #1663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
run: |
cat << 'EOF' | sudo tee /etc/nix/upload-to-cache.sh > /dev/null
#!/usr/bin/env bash
set -eouf
set -euf
export IFS=' '
/nix/var/nix/profiles/default/bin/nix copy --to 's3://nix-postgres-artifacts?secret-key=/etc/nix/nix-secret-key' $OUT_PATHS
EOF
Expand All @@ -77,10 +77,34 @@ jobs:
extra-conf: |
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
- name: Aggressive disk cleanup for DuckDB build
if: matrix.runner == 'macos-latest-xlarge'
run: |
echo "=== BEFORE CLEANUP ==="
df -h
# Remove major space consumers
sudo rm -rf /usr/share/dotnet || true
sudo rm -rf /usr/local/lib/android || true
sudo rm -rf /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform || true
sudo rm -rf /Applications/Xcode.app/Contents/Developer/Platforms/watchOS.platform || true
sudo rm -rf /Applications/Xcode.app/Contents/Developer/Platforms/tvOS.platform || true
# Clean everything possible
sudo rm -rf /opt/ghc || true
sudo rm -rf /usr/local/share/boost || true
sudo rm -rf /opt/homebrew || true
sudo xcrun simctl delete all 2>/dev/null || true
# Aggressive cache cleanup
sudo rm -rf /System/Library/Caches/* 2>/dev/null || true
sudo rm -rf /Library/Caches/* 2>/dev/null || true
sudo rm -rf ~/Library/Caches/* 2>/dev/null || true
sudo rm -rf /private/var/log/* 2>/dev/null || true
sudo rm -rf /tmp/* 2>/dev/null || true
echo "=== AFTER CLEANUP ==="
df -h
- name: Build psql bundle
run: >
nix run "github:Mic92/nix-fast-build?rev=b1dae483ab7d4139a6297e02b6de9e5d30e43d48"
-- --skip-cached --no-nom
-- --skip-cached --no-nom ${{ matrix.runner == 'macos-latest-xlarge' && '--max-jobs 1' || '' }}
--flake ".#checks.$(nix eval --raw --impure --expr 'builtins.currentSystem')"
env:
AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
Expand Down
6 changes: 3 additions & 3 deletions ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ postgres_major:

# Full version strings for each major version
postgres_release:
postgresorioledb-17: "17.0.1.098-orioledb"
postgres17: "17.4.1.048"
postgres15: "15.8.1.105"
postgresorioledb-17: "17.0.1.098-orioledb-mw-1"
postgres17: "17.4.1.48-mw-1"
postgres15: "15.8.1.105-mw-1"

# Non Postgres Extensions
pgbouncer_release: "1.19.0"
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1377,13 +1377,15 @@
# The list of exported 'checks' that are run with every run of 'nix
# flake check'. This is run in the CI system, as well.
checks = {
psql_15 = makeCheckHarness basePackages.psql_15.bin;
psql_17 = makeCheckHarness basePackages.psql_17.bin;
psql_orioledb-17 = makeCheckHarness basePackages.psql_orioledb-17.bin;
psql_15 = basePackages.psql_15.bin;
psql_17 = basePackages.psql_17.bin;
psql_orioledb-17 = basePackages.psql_orioledb-17.bin;
inherit (basePackages) wal-g-2 wal-g-3 dbmate-tool pg_regress;
devShell = devShells.default;
} // pkgs.lib.optionalAttrs (system == "aarch64-linux") {
inherit (basePackages) postgresql_15_debug postgresql_15_src postgresql_orioledb-17_debug postgresql_orioledb-17_src postgresql_17_debug postgresql_17_src;
} // pkgs.lib.optionalAttrs (system == "x86_64-linux") {
wrappers = import ./nix/ext/tests/wrappers.nix { inherit self; inherit pkgs; };
devShell = devShells.default;
};

# Apps is a list of names of things that can be executed with 'nix run';
Expand Down
97 changes: 61 additions & 36 deletions nix/cargo-pgrx/buildPgrxExtension.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
# 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,
darwin,
writeShellScriptBin,
}:

# The idea behind: Use it mostly like rustPlatform.buildRustPackage and so
Expand All @@ -47,26 +48,31 @@
# 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:
{
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 []);
rustfmtInNativeBuildInputs = lib.lists.any (dep: lib.getName dep == "rustfmt") (
args.nativeBuildInputs or [ ]
);
in

assert lib.asserts.assertMsg ((args.installPhase or "") == "")
"buildPgrxExtensions overwrites the installPhase, so providing one does nothing";
assert lib.asserts.assertMsg ((args.buildPhase or "") == "")
"buildPgrxExtensions overwrites the buildPhase, so providing one does nothing";
assert lib.asserts.assertMsg (
(args.installPhase or "") == ""
) "buildPgrxExtensions overwrites the installPhase, so providing one does nothing";
assert lib.asserts.assertMsg (
(args.buildPhase or "") == ""
) "buildPgrxExtensions overwrites the buildPhase, so providing one does nothing";
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)
Expand All @@ -75,7 +81,7 @@ assert lib.asserts.assertMsg (!useFakeRustfmt -> rustfmtInNativeBuildInputs)
let
fakeRustfmt = writeShellScriptBin "rustfmt" ''
exit 0
'';
'';
maybeDebugFlag = lib.optionalString (buildType != "release") "--debug";
maybeEnterBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) ''
export CARGO_TARGET_DIR="$(pwd)/target"
Expand All @@ -88,7 +94,13 @@ let
export PGRX_HOME=$(mktemp -d)
export PGDATA="$PGRX_HOME/data-${pgrxPostgresMajor}/"
cargo-pgrx pgrx init "--pg${pgrxPostgresMajor}" ${lib.getDev postgresql}/bin/pg_config
echo "unix_socket_directories = '$(mktemp -d)'" > "$PGDATA/postgresql.conf"

# unix sockets work in sandbox, too.
export PGHOST="$(mktemp -d)"
cat > "$PGDATA/postgresql.conf" <<EOF
listen_addresses = '''
unix_socket_directories = '$PGHOST'
EOF

# This is primarily for Mac or other Nix systems that don't use the nixbld user.
export USER="$(whoami)"
Expand All @@ -97,19 +109,28 @@ 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 ];

nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
cargo-pgrx
postgresql
pkg-config
rustPlatform.bindgenHook
] ++ lib.optionals useFakeRustfmt [ fakeRustfmt ];
buildInputs =
(args.buildInputs or [ ])
++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.apple_sdk.frameworks.Security ];

nativeBuildInputs =
(args.nativeBuildInputs or [ ])
++ [
cargo-pgrx
postgresql
pkg-config
rustPlatform.bindgenHook
]
++ lib.optionals useFakeRustfmt [ fakeRustfmt ];

buildPhase = ''
runHook preBuild
Expand Down Expand Up @@ -143,6 +164,7 @@ let
cargo-pgrx pgrx stop all

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

${maybeLeaveBuildAndTestSubdir}
Expand All @@ -155,7 +177,10 @@ let
RUST_BACKTRACE = "full";

checkNoDefaultFeatures = true;
checkFeatures = (args.checkFeatures or [ ]) ++ (lib.optionals usePgTestCheckFeature [ "pg_test" ]) ++ [ "pg${pgrxPostgresMajor}" ];
checkFeatures =
(args.checkFeatures or [ ])
++ (lib.optionals usePgTestCheckFeature [ "pg_test" ])
++ [ "pg${pgrxPostgresMajor}" ];
};
in
rustPlatform.buildRustPackage finalArgs
38 changes: 20 additions & 18 deletions nix/cargo-pgrx/default.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
{ lib
, darwin
, fetchCrate
, openssl
, pkg-config
, makeRustPlatform
, stdenv
, rust-bin
{
lib,
darwin,
fetchCrate,
openssl,
pkg-config,
makeRustPlatform,
stdenv,
rust-bin,
rustVersion ? "1.85.1",
}:
let
rustVersion = "1.85.1";
rustPlatform = makeRustPlatform {
cargo = rust-bin.stable.${rustVersion}.default;
rustc = rust-bin.stable.${rustVersion}.default;
};
generic =
{ version
, hash
, cargoHash
mkCargoPgrx =
{
version,
hash,
cargoHash,
}:
rustPlatform.buildRustPackage rec {
# rust-overlay uses 'cargo-auditable' wrapper for 'cargo' command, but it
Expand Down Expand Up @@ -61,25 +63,25 @@ let
};
in
{
cargo-pgrx_0_11_3 = generic {
cargo-pgrx_0_11_3 = mkCargoPgrx {
version = "0.11.3";
hash = "sha256-UHIfwOdXoJvR4Svha6ud0FxahP1wPwUtviUwUnTmLXU=";
cargoHash = "sha256-j4HnD8Zt9uhlV5N7ldIy9564o9qFEqs5KfXHmnQ1WEw=";
};
cargo-pgrx_0_12_6 = generic {
cargo-pgrx_0_12_6 = mkCargoPgrx {
version = "0.12.6";
hash = "sha256-7aQkrApALZe6EoQGVShGBj0UIATnfOy2DytFj9IWdEA=";
cargoHash = "sha256-Di4UldQwAt3xVyvgQT1gUhdvYUVp7n/a72pnX45kP0w=";
};
cargo-pgrx_0_12_9 = generic {
cargo-pgrx_0_12_9 = mkCargoPgrx {
version = "0.12.9";
hash = "sha256-aR3DZAjeEEAjLQfZ0ZxkjLqTVMIEbU0UiZ62T4BkQq8=";
cargoHash = "sha256-KTKcol9qSNLQZGW32e6fBb6cPkUGItknyVpLdBYqrBY=";
};
cargo-pgrx_0_14_3 = generic {
cargo-pgrx_0_14_3 = mkCargoPgrx {
version = "0.14.3";
hash = "sha256-3TsNpEqNm3Uol5XPW1i0XEbP2fF2+RKB2d7lO6BDnvQ=";
cargoHash = "sha256-Ny7j56pwB+2eEK62X0nWfFKQy5fBz+Q1oyvecivxLkk=";
};
inherit rustPlatform;
inherit mkCargoPgrx;
}
45 changes: 45 additions & 0 deletions nix/cargo-pgrx/mkPgrxExtension.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
callPackage,
rustVersion,
pgrxVersion,
makeRustPlatform,
rust-bin,
}:
let
inherit
(
(callPackage ./default.nix {
inherit rustVersion;
})
)
mkCargoPgrx
;

rustPlatform = makeRustPlatform {
cargo = rust-bin.stable.${rustVersion}.default;
rustc = rust-bin.stable.${rustVersion}.default;
};

versions = builtins.fromJSON (builtins.readFile ./versions.json);

cargo-pgrx =
let
pgrx =
versions.${pgrxVersion}
or (throw "Unsupported pgrx version ${pgrxVersion}. Available versions: ${builtins.toString (builtins.attrNames versions)}. Change 'nix/cargo-pgrx/versions.json' to add support for new versions.");
mapping = {
inherit (pgrx) hash;
cargoHash =
pgrx.rust."${rustVersion}".cargoHash
or (throw "Unsupported rust version ${rustVersion} for pgrx version ${pgrxVersion}. Available Rust versions: ${builtins.toString (builtins.attrNames pgrx.rust)}. Change 'nix/cargo-pgrx/versions.json' to add support for new versions.");
};
in
mkCargoPgrx {
inherit (mapping) hash cargoHash;
version = pgrxVersion;
};
in
callPackage ./buildPgrxExtension.nix {
inherit rustPlatform;
inherit cargo-pgrx;
}
Loading