pgcentralfoundation / pgrx

Build Postgres Extensions with Rust!
Other
3.68k stars 247 forks source link

(Mac) error: failed to run custom build command for `pgx-pg-sys v0.1.21` #151

Closed leizongmin closed 1 year ago

leizongmin commented 3 years ago

I following this Getting Started guide, when running command cargo pgx run pg13 got this errors:

(macOS 11.3.1, Xcode 12.5, rustc 1.54.0-nightly)

error: failed to run custom build command for `pgx-pg-sys v0.1.21`

Caused by:
  process didn't exit successfully: `/Users/hello/work/lab/myfile_fdw/target/debug/build/pgx-pg-sys-7e5dcc9e92761c9a/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=/Users/hello/.pgx/config.toml
  cargo:rerun-if-changed=include/pg10.h
  cargo:rerun-if-changed=include/pg11.h
  cargo:rerun-if-changed=include/pg12.h
  cargo:rerun-if-changed=include/pg13.h
  cargo:rerun-if-changed=cshim/pgx-cshim.c
  cargo:rerun-if-changed=cshim/Makefile

  --- stderr
  manifest_dir=/Users/hello/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.1.21
  shim_dir=/Users/hello/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.1.21/cshim
  Generating bindings for pg13
  Generating bindings for pg10
  Generating bindings for pg11
  Generating bindings for pg12
  /Users/hello/.pgx/13.3/pgx-install/include/postgresql/server/c.h:59:10: fatal error: 'stdio.h' file not found
  /Users/hello/.pgx/13.3/pgx-install/include/postgresql/server/c.h:59:10: fatal error: 'stdio.h' file not found, err: true
  thread '<unnamed>' panicked at 'Unable to generate bindings for pg13: ()', /Users/hello/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.1.21/build.rs:486:13
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
  /Users/hello/.pgx/11.12/pgx-install/include/postgresql/server/c.h:59:10: fatal error: 'stdio.h' file not found
  /Users/hello/.pgx/11.12/pgx-install/include/postgresql/server/c.h:59:10: fatal error: 'stdio.h' file not found, err: true
  thread '<unnamed>' panicked at 'Unable to generate bindings for pg11: ()', /Users/hello/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.1.21/build.rs:486:13
  /Users/hello/.pgx/12.7/pgx-install/include/postgresql/server/c.h:59:10: fatal error: 'stdio.h' file not found
  /Users/hello/.pgx/12.7/pgx-install/include/postgresql/server/c.h:59:10: fatal error: 'stdio.h' file not found, err: true
  thread '<unnamed>' panicked at 'Unable to generate bindings for pg12: ()', /Users/hello/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.1.21/build.rs:486:13
  /Users/hello/.pgx/10.17/pgx-install/include/postgresql/server/c.h:81:10: fatal error: 'stdio.h' file not found
  /Users/hello/.pgx/10.17/pgx-install/include/postgresql/server/c.h:81:10: fatal error: 'stdio.h' file not found, err: true
  thread '<unnamed>' panicked at 'Unable to generate bindings for pg10: ()', /Users/hello/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.1.21/build.rs:486:13
      [error] failed to build extension

The command cargo pgx init was successful:

  Discovered Postgres v13.3, v12.7, v11.12, v10.17
  Downloading Postgres v10.17 from https://ftp.postgresql.org/pub/source/v10.17/postgresql-10.17.tar.bz2
  Downloading Postgres v11.12 from https://ftp.postgresql.org/pub/source/v11.12/postgresql-11.12.tar.bz2
  Downloading Postgres v12.7 from https://ftp.postgresql.org/pub/source/v12.7/postgresql-12.7.tar.bz2
  Downloading Postgres v13.3 from https://ftp.postgresql.org/pub/source/v13.3/postgresql-13.3.tar.bz2
     Removing /Users/hello/.pgx/13.3
     Removing /Users/hello/.pgx/12.7
    Untarring Postgres v13.3 to /Users/hello/.pgx/13.3
    Untarring Postgres v12.7 to /Users/hello/.pgx/12.7
  Configuring Postgres v12.7
  Configuring Postgres v13.3
     Removing /Users/hello/.pgx/11.12
    Untarring Postgres v11.12 to /Users/hello/.pgx/11.12
  Configuring Postgres v11.12
     Removing /Users/hello/.pgx/10.17
    Untarring Postgres v10.17 to /Users/hello/.pgx/10.17
  Configuring Postgres v10.17
    Compiling Postgres v13.3
    Compiling Postgres v11.12
    Compiling Postgres v12.7
    Compiling Postgres v10.17
   Installing Postgres v11.12 to /Users/hello/.pgx/11.12/pgx-install
   Installing Postgres v12.7 to /Users/hello/.pgx/12.7/pgx-install
   Installing Postgres v13.3 to /Users/hello/.pgx/13.3/pgx-install
   Installing Postgres v10.17 to /Users/hello/.pgx/10.17/pgx-install
   Validating /Users/hello/.pgx/10.17/pgx-install/bin/pg_config
   Validating /Users/hello/.pgx/11.12/pgx-install/bin/pg_config
   Validating /Users/hello/.pgx/12.7/pgx-install/bin/pg_config
   Validating /Users/hello/.pgx/13.3/pgx-install/bin/pg_config
The last command took 418.053 seconds.
leizongmin commented 3 years ago

I have trying to set the BINDGEN_EXTRA_CLANG_ARGS environment variable (refer to rust-bindgen - environment-variables):

export BINDGEN_EXTRA_CLANG_ARGS="-I /Library/Developer/CommandLineTools/usr/include/c++/v1 -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"

Now cargo pgx run pg13 is successful running.

I don't know if this should be a problem of pgx?

gunplar commented 3 years ago

I can testify export BINDGEN_EXTRA_CLANG_ARGS="-I path to missing header files" works. But true, if this can also be included automatically when running cargo pgx init, that would help a lot. I'm totally new to both Rust and know little about Postgres, so just an idea ๐Ÿ˜ƒ

eeeebbbbrrrr commented 3 years ago

Weโ€™ll take a look at this. I use a Mac for development and have never run into this. I wonder if my setup is non-standard or yโ€™allโ€™s? Haha.

workingjubilee commented 2 years ago

Is this still an issue on recent MacOS with a recent PGX (like 0.4.x)? Also was this an M1 or x86-64 Mac?

olirice commented 2 years ago

Is this still an issue on recent MacOS with a recent PGX (like 0.4.x)? Also was this an M1 or x86-64 Mac?

yes, I just hit it with an M1 Mac running MacOS 12.4 + pgx-pg-sys v0.4.5

workingjubilee commented 2 years ago

๐Ÿซ 

thomcc commented 2 years ago

It sounds like we (or bindgen) are failing to locate the currently active SDK. I'll look into our code here since I have a lot of experience in this area and it might be a simple fix (often this involves invoking xcrun or xcconfig).

thomcc commented 2 years ago

I suspect this is due to bindgen finding some version of libclang that isn't provided by the system. If so, we could probably pull the -isysroot arg out of pg_config --cppflags and give it to bindgen as a cppflag, but it's plausible we'd hit other issues too.

Do you have a special LLVM version installed, that didn't come with the OS?

noahlias commented 1 year ago

I got the same error. environment: (macOS 13.3.1 22E261 arm64, rustc 1.71.0-nightly)

pgvecto.rs on ๎‚  main is ๐Ÿ“ฆ vvectors@0.0.0 via ๐Ÿฆ€ v1.71.0 via ๐Ÿ…’ base
โžœ cargo pgrx run -v
  2023-04-20T15:52:59.728368Z DEBUG cargo_pgrx::manifest: Found root package, manifest_path: /Users/alias/Desktop/m/pgvecto.rs/Cargo.toml
    at /Users/alias/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-pgrx-0.7.4/src/manifest.rs:63
    in cargo_pgrx::manifest::manifest_path
    in cargo_pgrx::command::run::execute

       Using DefaultFeature("pg13") and `pg_config` from /Users/alias/.pgrx/13.10/pgrx-install/bin/pg_config
  2023-04-20T15:52:59.741181Z DEBUG cargo_pgrx::command::status: Running, command: "/Users/alias/.pgrx/13.10/pgrx-install/bin/pg_ctl" "status" "-D" "/Users/alias/.pgrx/data-13"
    at /Users/alias/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-pgrx-0.7.4/src/command/status.rs:72
    in cargo_pgrx::command::status::status_postgres with pg_version: 13.10
    in cargo_pgrx::command::stop::stop_postgres with pg_version: 13.10
    in cargo_pgrx::command::run::run with pg_version: 13.10, profile: Dev
    in cargo_pgrx::command::run::execute

  2023-04-20T15:52:59.742309Z DEBUG cargo_pgrx::command::stop: Already stopped
    at /Users/alias/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-pgrx-0.7.4/src/command/stop.rs:73
    in cargo_pgrx::command::stop::stop_postgres with pg_version: 13.10
    in cargo_pgrx::command::run::run with pg_version: 13.10, profile: Dev
    in cargo_pgrx::command::run::execute

    Building extension with features pg13
     Running command "/Users/alias/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo" "build" "--features" "pg13" "--no-default-features" "--message-format=json-render-diagnostics"
   Compiling bindgen v0.60.1
   Compiling pgrx-pg-sys v0.7.4
error: failed to run custom build command for `pgrx-pg-sys v0.7.4`

Caused by:
  process didn't exit successfully: `/Users/alias/Desktop/m/pgvecto.rs/target/debug/build/pgrx-pg-sys-c00f9aff79e58fea/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=PGRX_PG_SYS_GENERATE_BINDINGS_FOR_RELEASE
  cargo:rerun-if-changed=/Users/alias/.pgrx/config.toml
  cargo:rerun-if-changed=include
  cargo:rerun-if-changed=cshim
  cargo:rerun-if-env-changed=PGRX_PG_CONFIG_PATH
  cargo:rerun-if-env-changed=PGRX_PG_CONFIG_AS_ENV
  cargo:rerun-if-env-changed=LLVM_CONFIG_PATH
  cargo:rerun-if-env-changed=LIBCLANG_PATH
  cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_aarch64-apple-darwin
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_aarch64_apple_darwin
  cargo:rerun-if-env-changed=PGRX_TARGET_INFO_PATH_PG13_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PGRX_TARGET_INFO_PATH_PG13
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER_PG13_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER_PG13
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER
  cargo:rerun-if-env-changed=PGRX_BINDGEN_NO_DETECT_INCLUDES_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PGRX_BINDGEN_NO_DETECT_INCLUDES

  --- stderr
  build_paths=BuildPaths { manifest_dir: "/Users/alias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.7.4", out_dir: "/Users/alias/Desktop/m/pgvecto.rs/target/debug/build/pgrx-pg-sys-1a158101658daf54/out", src_dir: "/Users/alias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.7.4/src", shim_src: "/Users/alias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.7.4/cshim", shim_dst: "/Users/alias/Desktop/m/pgvecto.rs/target/debug/build/pgrx-pg-sys-1a158101658daf54/out/cshim" }
  Generating bindings for pg13
  thread '<unnamed>' panicked at '"wait_struct_(unnamed_at_/Applications/Xcode_app/Contents/Developer/Platforms/MacOSX_platform/Developer/SDKs/MacOSX13_3_sdk/usr/include/sys/wait_h_199_2)" is not a valid Ident', /Users/alias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.56/src/fallback.rs:811:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
  thread 'main' panicked at 'thread panicked while generating bindings: Any { .. }', /Users/alias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.7.4/build.rs:200:41

The command cargo pgx init was successful:

pgvecto.rs on ๎‚  main is ๐Ÿ“ฆ vvectors@0.0.0 via ๐Ÿฆ€ v1.71.0 via ๐Ÿ…’ base
โžœ cd ~/.pgrx
(base)
~/.pgrx via ๐Ÿ…’ base
โžœ ll
total 8
drwxr-xr-x  24 alias  staff   768B Apr 20 23:23 11.19
drwxr-xr-x  24 alias  staff   768B Apr 20 23:23 12.14
drwxr-xr-x  25 alias  staff   800B Apr 20 23:24 13.10
drwxr-xr-x  25 alias  staff   800B Apr 20 23:24 14.7
drwxr-xr-x  26 alias  staff   832B Apr 20 23:24 15.2
-rw-r--r--   1 alias  staff   303B Apr 20 23:25 config.toml
drwx------  24 alias  staff   768B Apr 20 23:25 data-11
drwx------  24 alias  staff   768B Apr 20 23:25 data-12
drwx------  24 alias  staff   768B Apr 20 23:25 data-13
drwx------  24 alias  staff   768B Apr 20 23:25 data-14
drwx------  24 alias  staff   768B Apr 20 23:25 data-15

And I tried this bindgen_args it causes

 --- stderr
  build_paths=BuildPaths { manifest_dir: "/Users/alias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.7.4", out_dir: "/Users/alias/Desktop/m/pgvecto.rs/target/debug/build/pgrx-pg-sys-1a158101658daf54/out", src_dir: "/Users/alias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.7.4/src", shim_src: "/Users/alias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.7.4/cshim", shim_dst: "/Users/alias/Desktop/m/pgvecto.rs/target/debug/build/pgrx-pg-sys-1a158101658daf54/out/cshim" }
  Generating bindings for pg13
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:69:21: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:82:18: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:83:41: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:83:53: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:84:43: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:85:23: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:86:24: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:87:31: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:87:53: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:88:24: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:89:26: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:90:25: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:94:32: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:96:25: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:97:37: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:97:60: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:100:31: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:101:28: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:101:46: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:103:39: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:106:31: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  clang diag: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/signal.h:106:48: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  thread '<unnamed>' panicked at '"wait_struct_(unnamed_at_/Library/Developer/CommandLineTools/SDKs/MacOSX_sdk/usr/include/sys/wait_h_199_2)" is not a valid Ident', /Users/alias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.56/src/fallback.rs:811:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
  thread 'main' panicked at 'thread panicked while generating bindings: Any { .. }', /Users/alias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.7.4/build.rs:200:41
TennyZhuang commented 1 year ago

I fix the problem by brew uninstall llvm, but I don't know how to indicate the bindgen to find the correct LLVM without uninstalling other llvms.

thomcc commented 1 year ago

I'll look into this. I have other LLVMs installed without this issue.

thomcc commented 1 year ago

Do you have the LLVM items on your path too? That might be the difference, I have them installed, but don't add them to my path except when I need them (homebrew is right for once not to do this for you).

noahlias commented 1 year ago

It fixed by uninstall llvm. yeah it is on my path

image

and there is my llvm version(only one)

image
workingjubilee commented 1 year ago

It looks like this has been taken care of? Mildly unfortunate that it requires so much additional twiddling sometimes, but functional at least.