pganalyze / pg_query.rs

Rust library to parse, deparse and normalize SQL queries using the PostgreSQL query parser
MIT License
139 stars 13 forks source link

fatal error: sys/types.h not found #33

Open jkhall opened 11 months ago

jkhall commented 11 months ago

Hello. I'm trying to get set up on an M1 mac with the Getting started snippet. On running cargo build I get the error:

/Projects/simple_pgquery/pgquerytest/target/debug/build/pg_query-8200207fd30b02f3/out/pg_query.h:5:10: fatal error: 'sys/types.h' file not found

Wanted to ask if this was a known issue with a workaround. If not, I will assume it's an issue on my machine and keep trying to fix it. Thanks.

seanlinsley commented 11 months ago

I think that's from a missing system dependency. brew install cmake might fix it.

Once you do get it working, feel free to open a PR to update the documentation!

jkhall commented 11 months ago

Will do! For what it's worth, I already had cmake installed. I even uninstalled and reinstalled and it didn't seem to fix anything. That said pg_query = "0.7" in Cargo.toml does build successfully, so I'm trying track down what the difference is.

SteveLauC commented 4 months ago

Hi, I got a quite similar error, when building this crate:

error: failed to run custom build command for `pg_query v5.1.0`
note: To improve backtraces for build dependencies, set the CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG=true environment variable to enable debug information generation.

Caused by:
  process didn't exit successfully: `/home/steve/Documents/workspace/rust/target/debug/build/pg_query-0af8deb85cd56b05/build-script-build` (exit status: 1)
  --- stdout
  cargo:rustc-link-search=native=/home/steve/Documents/workspace/rust/target/debug/build/pg_query-ea3135317016c144/out
  cargo:rustc-link-lib=static=pg_query
  TARGET = Some("x86_64-unknown-linux-gnu")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
  CC_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
  CC_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-gnu
  CFLAGS_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
  CFLAGS_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=AR_x86_64-unknown-linux-gnu
  AR_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=AR_x86_64_unknown_linux_gnu
  AR_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_AR
  HOST_AR = None
  cargo:rerun-if-env-changed=AR
  AR = None
  cargo:rerun-if-env-changed=ARFLAGS_x86_64-unknown-linux-gnu
  ARFLAGS_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=ARFLAGS_x86_64_unknown_linux_gnu
  ARFLAGS_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_ARFLAGS
  HOST_ARFLAGS = None
  cargo:rerun-if-env-changed=ARFLAGS
  ARFLAGS = None
  cargo:rustc-link-lib=static=pg_query
  cargo:rustc-link-search=native=/home/steve/Documents/workspace/rust/target/debug/build/pg_query-ea3135317016c144/out

  --- stderr
  /usr/include/sys/types.h:144:10: fatal error: 'stddef.h' file not found
  Error: "Unable to generate bindings"

Environments

$ uname -a           
Linux fedora 6.2.9-300.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Mar 30 22:32:58 UTC 2023 x86_64 GNU/Linux

$ postgres -V      
postgres (PostgreSQL) 17beta1

$ rustc --version    
rustc 1.79.0 (129f3b996 2024-06-10)

$ rg pg Cargo.toml         
29:pg_query = "5.1.0"
morigs commented 2 months ago

Same problem here

Output ``` error: failed to run custom build command for `pg_query v5.1.0` Caused by: process didn't exit successfully: `~/projects/pg-query-wasm/target/debug/build/pg_query-90f797ffa5b335f7/build-script-build` (exit status: 1) --- stdout cargo:rustc-link-search=native=~/projects/pg-query-wasm/target/wasm32-wasip1/debug/build/pg_query-3bb5cd9751e243b8/out cargo:rustc-link-lib=static=pg_query OUT_DIR = Some(~/projects/pg-query-wasm/target/wasm32-wasip1/debug/build/pg_query-3bb5cd9751e243b8/out) TARGET = Some(wasm32-wasip1) OPT_LEVEL = Some(0) HOST = Some(aarch64-apple-darwin) cargo:rerun-if-env-changed=CC_wasm32-wasip1 CC_wasm32-wasip1 = None cargo:rerun-if-env-changed=CC_wasm32_wasip1 CC_wasm32_wasip1 = None cargo:rerun-if-env-changed=TARGET_CC TARGET_CC = None cargo:rerun-if-env-changed=CC CC = Some(~/wasi-sdk-24.0-arm64-macos/bin/clang --sysroot=~/wasi-sdk-24.0-arm64-macos/share/wasi-sysroot) cargo:rerun-if-env-changed=CC_KNOWN_WRAPPER_CUSTOM CC_KNOWN_WRAPPER_CUSTOM = None RUSTC_WRAPPER = None cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS CRATE_CC_NO_DEFAULTS = None cargo:rerun-if-env-changed=WASI_SYSROOT WASI_SYSROOT = Some(/opt/wasi-sdk/WASI-SDK-12.0/share/wasi-sysroot) DEBUG = Some(true) cargo:rerun-if-env-changed=CFLAGS_wasm32-wasip1 CFLAGS_wasm32-wasip1 = None cargo:rerun-if-env-changed=CFLAGS_wasm32_wasip1 CFLAGS_wasm32_wasip1 = None cargo:rerun-if-env-changed=TARGET_CFLAGS TARGET_CFLAGS = None cargo:rerun-if-env-changed=CFLAGS CFLAGS = None cargo:warning=In file included from ~/projects/pg-query-wasm/target/wasm32-wasip1/debug/build/pg_query-3bb5cd9751e243b8/out/src/pg_query.c:1: cargo:warning=~/projects/pg-query-wasm/target/wasm32-wasip1/debug/build/pg_query-3bb5cd9751e243b8/out/./pg_query.h:5:10: fatal error: 'sys/types.h' file not found cargo:warning= 5 | #include cargo:warning= | ^~~~~~~~~~~~~ cargo:warning=1 error generated. --- stderr error occurred: Command "~/wasi-sdk-24.0-arm64-macos/bin/clang" "--sysroot=~/wasi-sdk-24.0-arm64-macos/share/wasi-sysroot" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-fno-exceptions" "--sysroot=/opt/wasi-sdk/WASI-SDK-12.0/share/wasi-sysroot" "-g" "-fno-omit-frame-pointer" "--target=wasm32-wasip1" "-I" "~/projects/pg-query-wasm/target/wasm32-wasip1/debug/build/pg_query-3bb5cd9751e243b8/out/." "-I" "~/projects/pg-query-wasm/target/wasm32-wasip1/debug/build/pg_query-3bb5cd9751e243b8/out/./vendor" "-I" "~/projects/pg-query-wasm/target/wasm32-wasip1/debug/build/pg_query-3bb5cd9751e243b8/out/./src/postgres/include" "-I" "~/projects/pg-query-wasm/target/wasm32-wasip1/debug/build/pg_query-3bb5cd9751e243b8/out/./src/include" "-DUSE_ASSERT_CHECKING" "-o" "~/projects/pg-query-wasm/target/wasm32-wasip1/debug/build/pg_query-3bb5cd9751e243b8/out/9908e27992d197a4-pg_query.o" "-c" "~/projects/pg-query-wasm/target/wasm32-wasip1/debug/build/pg_query-3bb5cd9751e243b8/out/src/pg_query.c" with args clang did not execute successfully (status code exit status: 1) ```