eclipse-iceoryx / iceoryx2

Eclipse iceoryx2™ - true zero-copy inter-process-communication in pure Rust
https://iceoryx.io
Apache License 2.0
1.03k stars 40 forks source link

cargo build failed at iceoryx2/iceoryx2-pal/posix because missing stddef.h #443

Closed xieyuschen closed 1 month ago

xieyuschen commented 1 month ago

I have tried to read iceoryx2 in my weekend at my linux:

➜  iceoryx2 git:(main) ✗ uname -a
Linux xieyuschen 5.15.0-48-generic #54~20.04.1-Ubuntu SMP Thu Sep 1 16:17:26 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

However, I encountered error when i tried to buld iceoryx2/iceoryx2-pal/posix. However, it's fine to build a .c file with stddef.h import. Hence, I tried to check more about it. I found the bindgen respects the /usr/include/x86_64-linux-gnu/ only, but the stddef.h actually locates in /usr/lib/gcc/x86_64-linux-gnu/9/include(I found it by calling echo | gcc -E -x c - -v). Note that I haven't installed clang due to the system issue.

➜  posix git:(main) cargo build
   Compiling iceoryx2-pal-posix v0.4.1 (/home/xieyuschen/codespace/iceoryx2/iceoryx2-pal/posix)
error: failed to run custom build command for `iceoryx2-pal-posix v0.4.1 (/home/xieyuschen/codespace/iceoryx2/iceoryx2-pal/posix)`

Caused by:
  process didn't exit successfully: `/home/xieyuschen/codespace/iceoryx2/target/debug/build/iceoryx2-pal-posix-fe2665ecc42216ae/build-script-build` (exit status: 101)
  --- stdout
  cargo:rustc-link-lib=pthread
  cargo:rerun-if-changed=src/c/posix.h
  cargo:rerun-if-env-changed=TARGET
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
  cargo:rerun-if-changed=src/c/posix.h

  --- stderr
  /usr/include/x86_64-linux-gnu/sys/types.h:144:10: fatal error: 'stddef.h' file not found
  thread 'main' panicked at iceoryx2-pal/posix/build.rs:46:18:
  Unable to generate bindings: ClangDiagnostic("/usr/include/x86_64-linux-gnu/sys/types.h:144:10: fatal error: 'stddef.h' file not found\n")
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
     1: core::panicking::panic_fmt
               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:74:14
     2: core::result::unwrap_failed
               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/result.rs:1679:5
     3: core::result::Result<T,E>::expect
     4: build_script_build::main
     5: core::ops::function::FnOnce::call_once
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I proposed to add a check in iceoryx2-pal/posix/build.rs to check whether the clang is installed, if not, let the build.rs suggests users to install it. Or at least it reports some warnings so I can aware that I need to find the stddef.h by myself and set up it the bindgen builder:

            bindgen::Builder::default()
                .header("src/c/posix.h")
+               .clang_arg("-I/usr/lib/gcc/x86_64-linux-gnu/9/include")
                .blocklist_type("max_align_t")
                .parse_callbacks(Box::new(CargoCallbacks::new()))
                .use_core()
                .generate()
                .expect("Unable to generate bindings")

How do you think about it? This should be an document issue for us to improve.

elfenpiff commented 1 month ago

@xieyuschen

I like your proposal to let the build.rs suggest that the user shall install clang. Also, this would be a nice entry for our getting started documentation to install clang. Maybe also an FAQ entry: What shall I do when stddef.h cannot be found?

xieyuschen commented 1 month ago

@xieyuschen

I like your proposal to let the build.rs suggest that the user shall install clang. Also, this would be a nice entry for our getting started documentation to install clang. Maybe also an FAQ entry: What shall I do when stddef.h cannot be found?

Sure, i think this is a good idea and let me help to create a PR for it. Besides, I cannot install clang in my ubuntu as the dependencies are messy now and i don't want to tackle them at all.

For me, adding a clang_arg call is enough, but it's of course rediculous to merge the path which only makes sense in my own desktop. Hence, I proposed we support an env var ICEORYX2_CLANG_ARG in build.rs to do so.

xieyuschen commented 1 month ago

close as it could be solved by export BINDGEN_EXTRA_CLANG_ARGS, see https://github.com/rust-lang/rust-bindgen?tab=readme-ov-file#environment-variables.

sorry for missing the bindgen documentation.