Skip to content

postgresqlPackages.postgis: fix cross-compilation#424800

Merged
onny merged 1 commit intoNixOS:masterfrom
onny:postgis-cross
Jul 21, 2025
Merged

postgresqlPackages.postgis: fix cross-compilation#424800
onny merged 1 commit intoNixOS:masterfrom
onny:postgis-cross

Conversation

@onny
Copy link
Contributor

@onny onny commented Jul 13, 2025

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Nixpkgs 25.11 Release Notes (or backporting 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 25.05 NixOS Release notes)
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other contributing documentation in corresponding paths.

Add a 👍 reaction to pull requests you find important.

@ofborg ofborg bot added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Jul 13, 2025
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Jul 13, 2025
@onny onny marked this pull request as ready for review July 17, 2025 13:57
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprising: json_c doesn't work on RiscV?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is looking for the json libraries or header files but I couldn't get it to work. So this feature is missing but at least cross-compilation will work :)

@sikmir
Copy link
Member

sikmir commented Jul 18, 2025

error: builder for '/nix/store/m24vv0aga6fqcvpam66wkv9153rsyb91-postgis-aarch64-unknown-linux-gnu-3.5.3.drv' failed with exit code 1;
       last 25 log lines:
       > checking for CUNIT... no
       > configure: WARNING: could not locate CUnit required for unit tests
       > checking for iconv.h... yes
       > checking for libiconv_open in -liconv... no
       > checking for iconv_open in -lc... yes
       > checking for iconvctl... no
       > checking for libiconvctl... no
       > Using user-specified pg_config file: /nix/store/r1ln26jp7whqszz2jvfzrxj1r8gq4g1y-pg_config/bin/pg_config
       > checking PostgreSQL version... PostgreSQL 17.5
       > checking for libpq-fe.h... yes
       > checking for PQserverVersion in -lpq... yes
       > ------------------------------------------------------------------------
       >   WARNING: You have set the --prefix to '/nix/store/7s4sxcxjzhb9hgkwdl8g69kcyhdjjkxj-postgis-aarch64-unknown-linux-gnu-3.5.3'. But we mostly
       >   ignore the --prefix. For your info, using the values determined from
       >   /nix/store/r1ln26jp7whqszz2jvfzrxj1r8gq4g1y-pg_config/bin/pg_config we will be installing:
       >     * postgis shared library in /nix/store/gbalc300kv6dn7dpvanfh6yr31cqaikj-postgresql-aarch64-unknown-linux-gnu-17.5-lib/lib
       >     * postgis SQL files in /nix/store/qw05cl957d0axvldjwl9fqa340i7fxxg-postgresql-aarch64-unknown-linux-gnu-17.5/share/postgresql/contrib/postgis-3.5
       > ------------------------------------------------------------------------
       > checking for xml2-config... /nix/store/j2gi38k4h3hr2mrqaqisv774p2kypyqm-libxml2-2.14.4-unstable-2025-06-20-dev/bin/xml2-config
       > checking for libxml/tree.h... yes
       > checking for libxml/parser.h... yes
       > checking for libxml/xpath.h... yes
       > checking for libxml/xpathInternals.h... yes
       > checking for xmlInitParser in -lxml2... no
       > configure: error: could not find libxml2

@onny
Copy link
Contributor Author

onny commented Jul 18, 2025

error: builder for '/nix/store/m24vv0aga6fqcvpam66wkv9153rsyb91-postgis-aarch64-unknown-linux-gnu-3.5.3.drv' failed with exit code 1;
       last 25 log lines:
       > checking for CUNIT... no
       > configure: WARNING: could not locate CUnit required for unit tests
       > checking for iconv.h... yes
       > checking for libiconv_open in -liconv... no
       > checking for iconv_open in -lc... yes
       > checking for iconvctl... no
       > checking for libiconvctl... no
       > Using user-specified pg_config file: /nix/store/r1ln26jp7whqszz2jvfzrxj1r8gq4g1y-pg_config/bin/pg_config
       > checking PostgreSQL version... PostgreSQL 17.5
       > checking for libpq-fe.h... yes
       > checking for PQserverVersion in -lpq... yes
       > ------------------------------------------------------------------------
       >   WARNING: You have set the --prefix to '/nix/store/7s4sxcxjzhb9hgkwdl8g69kcyhdjjkxj-postgis-aarch64-unknown-linux-gnu-3.5.3'. But we mostly
       >   ignore the --prefix. For your info, using the values determined from
       >   /nix/store/r1ln26jp7whqszz2jvfzrxj1r8gq4g1y-pg_config/bin/pg_config we will be installing:
       >     * postgis shared library in /nix/store/gbalc300kv6dn7dpvanfh6yr31cqaikj-postgresql-aarch64-unknown-linux-gnu-17.5-lib/lib
       >     * postgis SQL files in /nix/store/qw05cl957d0axvldjwl9fqa340i7fxxg-postgresql-aarch64-unknown-linux-gnu-17.5/share/postgresql/contrib/postgis-3.5
       > ------------------------------------------------------------------------
       > checking for xml2-config... /nix/store/j2gi38k4h3hr2mrqaqisv774p2kypyqm-libxml2-2.14.4-unstable-2025-06-20-dev/bin/xml2-config
       > checking for libxml/tree.h... yes
       > checking for libxml/parser.h... yes
       > checking for libxml/xpath.h... yes
       > checking for libxml/xpathInternals.h... yes
       > checking for xmlInitParser in -lxml2... no
       > configure: error: could not find libxml2

how did you build it? this should fix: nix build .#pkgsCross.riscv64.postgis

@sikmir
Copy link
Member

sikmir commented Jul 18, 2025

how did you build it? this should fix: nix build .#pkgsCross.riscv64.postgis

I mean the same error for other platforms pkgsCross.aarch64-multiplatform.postgis.

Copy link
Member

@sikmir sikmir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update commit message to postgresqlPackages.postgis: fix cross-compilation.

@sikmir
Copy link
Member

sikmir commented Jul 18, 2025

A bit refactored:

diff --git i/pkgs/servers/sql/postgresql/ext/postgis.nix w/pkgs/servers/sql/postgresql/ext/postgis.nix
index 09c547075135..39b5329c993d 100644
--- i/pkgs/servers/sql/postgresql/ext/postgis.nix
+++ w/pkgs/servers/sql/postgresql/ext/postgis.nix
@@ -91,12 +91,19 @@ postgresqlBuildExtension (finalAttrs: {
     ./autogen.sh
   '';

-  configureFlags = [
-    "--with-pgconfig=${postgresql.pg_config}/bin/pg_config"
-    "--with-gdalconfig=${gdal}/bin/gdal-config"
-    "--with-jsondir=${json_c.dev}"
-    "--disable-extension-upgrades-install"
-  ] ++ lib.optional withSfcgal "--with-sfcgal=${sfcgal}/bin/sfcgal-config";
+  configureFlags =
+    let
+      isCross = stdenv.hostPlatform != stdenv.buildPlatform;
+    in
+    [
+      (lib.enableFeature false "extension-upgrades-install")
+      (lib.withFeatureAs true "pgconfig" "${postgresql.pg_config}/bin/pg_config")
+      (lib.withFeatureAs true "gdalconfig" "${gdal}/bin/gdal-config")
+      (lib.withFeatureAs true "jsondir" (lib.getDev json_c))
+      (lib.withFeatureAs true "xml2config" (lib.getExe' (lib.getDev libxml2) "xml2-config"))
+      (lib.withFeatureAs withSfcgal "sfcgal" "${sfcgal}/bin/sfcgal-config")
+      (lib.withFeature (!isCross) "json") # configure: error: cannot check for file existence when cross compiling
+    ];

   makeFlags = [
     "PERL=${perl}/bin/perl"

@onny onny changed the title postgis: Fix RiscV cross-compilation postgresqlPackages.postgis: fix cross-compilation Jul 19, 2025
@onny onny requested a review from sikmir July 19, 2025 09:44
@onny
Copy link
Contributor Author

onny commented Jul 19, 2025

Thank you, added it!

@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Jul 19, 2025
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing full platforms with == and != is a bit of an anti-pattern. Can we be any more specific? Why does cross fail in this case - is it because the build platform can't execute the host version of a dependency? Or what exactly is the reason?

Also see discussion in #380005.

Copy link
Member

@sikmir sikmir Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or what exactly is the reason?

configure: error: cannot check for file existence when cross compiling

I didn't dig deeper.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this error comes from the AC_CHECK_FILE macro in:

https://github.com/postgis/postgis/blob/f987b7316de4b047c99a08a1765dd47045cf90e4/configure.ac#L1103-L1140

The macro is defined upstream here:

https://github.com/autotools-mirror/autoconf/blob/1f38316f6af7bf63e5e7dd187ff6456e07ad743e/lib/autoconf/general.m4#L3052-L3070

The cross_compiling thing is set here:

https://github.com/autotools-mirror/autoconf/blob/1f38316f6af7bf63e5e7dd187ff6456e07ad743e/lib/autoconf/general.m4#L974-L981

It looks like autoconf compares the triples it gets passed for that case.

Thus, I suggest this:

Suggested change
isCross = stdenv.hostPlatform != stdenv.buildPlatform;
isCross = stdenv.hostPlatform.config != stdenv.buildPlatform.config;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the changes and it's working. Thank you

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. labels Jul 19, 2025
@onny onny merged commit 7988364 into NixOS:master Jul 21, 2025
17 checks passed
@onny
Copy link
Contributor Author

onny commented Jul 21, 2025

Thank you!

@nixpkgs-ci
Copy link
Contributor

nixpkgs-ci bot commented Jul 21, 2025

Successfully created backport PR for release-25.05:

@github-actions github-actions bot added the 8.has: port to stable This PR already has a backport to the stable release. label Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: cross-compilation Building packages on a different platform than they will be used on 8.has: port to stable This PR already has a backport to the stable release. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants