rust-lang / rust-bindgen

Automatically generates Rust FFI bindings to C (and some C++) libraries.
https://rust-lang.github.io/rust-bindgen/
BSD 3-Clause "New" or "Revised" License
4.51k stars 702 forks source link

"fatal error: 'string' file not found" on macOS #1834

Open LoganDark opened 4 years ago

LoganDark commented 4 years ago

Input C/C++ Header

#include <string>

Bindgen Invocation

bindgen::Builder::default()
    .header("wrapper.hpp")
    .detect_include_paths(false)
    .clang_arg("-std=c++14")
    .generate()
    .expect("Couldn't make bindings!");

Actual Results

The following warnings were emitted during compilation:

warning: couldn't execute `llvm-config --prefix` (error: No such file or directory (os error 2))
warning: set the LLVM_CONFIG_PATH environment variable to the full path to a valid `llvm-config` executable (including the executable itself)

error: failed to run custom build command for `bindgen-hates-macos v0.1.0 (/Users/LoganDark/CLionProjects/bindgen-hates-macos)`

Caused by:
  process didn't exit successfully: `/Users/LoganDark/CLionProjects/bindgen-hates-macos/target/debug/build/bindgen-hates-macos-e6fb019ae718a79e/build-script-build` (exit code: 101)
--- stdout
cargo:rerun-if-changed=wrapper.hpp
cargo:warning=couldn't execute `llvm-config --prefix` (error: No such file or directory (os error 2))
cargo:warning=set the LLVM_CONFIG_PATH environment variable to the full path to a valid `llvm-config` executable (including the executable itself)

--- stderr
[2020-07-22T05:47:08Z DEBUG bindgen] Generating bindings, libclang at /usr/local/opt/llvm@10/lib/libclang.dylib
[2020-07-22T05:47:08Z DEBUG bindgen] Fixed-up options: BindgenOptions { blacklisted_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, blacklisted_functions: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, blacklisted_items: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, opaque_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, rustfmt_path: None, whitelisted_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, whitelisted_functions: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, whitelisted_vars: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, default_enum_style: Consts, bitfield_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, newtype_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, rustified_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, rustified_non_exhaustive_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, constified_enum_modules: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, constified_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, default_alias_style: TypeAlias, type_alias: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, new_type_alias: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, new_type_alias_deref: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, builtins: false, emit_ast: false, emit_ir: false, emit_ir_graphviz: None, enable_cxx_namespaces: false, enable_function_attribute_detection: false, disable_name_namespacing: false, disable_nested_struct_naming: false, disable_header_comment: false, layout_tests: true, impl_debug: false, impl_partialeq: false, derive_copy: true, derive_debug: true, derive_default: false, derive_hash: false, derive_partialord: false, derive_ord: false, derive_partialeq: false, derive_eq: false, use_core: false, ctypes_prefix: None, time_phases: false, namespaced_constants: true, msvc_mangling: false, convert_floats: true, raw_lines: [], module_lines: {}, clang_args: ["-std=c++14", "wrapper.hpp"], input_header: Some("wrapper.hpp"), input_unsaved_files: [], parse_callbacks: Some(CargoCallbacks), codegen_config: FUNCTIONS | TYPES | VARS | METHODS | CONSTRUCTORS | DESTRUCTORS, conservative_inline_namespaces: false, generate_comments: true, generate_inline_functions: false, whitelist_recursively: true, objc_extern_crate: false, generate_block: false, block_extern_crate: false, enable_mangling: true, detect_include_paths: false, prepend_enum_name: true, rust_target: Stable_1_40, rust_features: RustFeatures { untagged_union: true, associated_const: true, builtin_clone_impls: true, repr_align: true, i128_and_u128: true, must_use_function: true, repr_transparent: true, min_const_fn: true, core_ffi_c_void: true, repr_packed_n: true, maybe_uninit: true, non_exhaustive: true, thiscall_abi: false }, record_matches: true, size_t_is_usize: false, rustfmt_bindings: true, rustfmt_configuration_file: None, no_partialeq_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, no_copy_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, no_hash_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, array_pointers_in_arguments: false, wasm_import_module_name: None }
wrapper.hpp:1:10: fatal error: 'string' file not found
wrapper.hpp:1:10: fatal error: 'string' file not found, err: true
thread 'main' panicked at 'Couldn't make bindings!: ()', build.rs:9:20
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::result::unwrap_failed
   9: core::result::Result<T,E>::expect
  10: build_script_build::main
  11: std::rt::lang_start::{{closure}}
  12: std::rt::lang_start_internal
  13: std::rt::lang_start
  14: main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Expected Results

I expected no fatal error.


This has happened on every single clang on my macOS 10.14.6 system, even if I try to specify include paths and stuff. Also it's really weird. Look here:

0 LoganDark ~/CLionProjects/bindgen-hates-macos
env LLVM_CONFIG_PATH=/usr/local/Cellar/llvm/10.0.0_3/bin/llvm-config LIBCLANG_PATH=/usr/local/Cellar/llvm/10.0.0_3/lib/ CLANG_PATH=/usr/local/Cellar/llvm/10.0.0_3/bin/clang++ BINDGEN_EXTRA_CLANG_ARGS=(wx-config --cxxflags)' -I/usr/local/Cellar/llvm/10.0.0_3/lib/clang/10.0.0/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include -F/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks' RUST_LOG=bindgen RUST_BACKTRACE=1 bindgen --no-include-path-detection wrapper.hpp
[2020-07-22T05:53:18Z INFO  bindgen] Clang Version: clang version 10.0.0 , parsed: Some((10, 0))
[2020-07-22T05:53:18Z DEBUG bindgen] Generating bindings, libclang at /usr/local/Cellar/llvm/10.0.0_3/lib/libclang.dylib
[2020-07-22T05:53:18Z DEBUG bindgen] Fixed-up options: BindgenOptions { blacklisted_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, blacklisted_functions: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, blacklisted_items: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, opaque_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, rustfmt_path: None, whitelisted_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, whitelisted_functions: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, whitelisted_vars: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, default_enum_style: Consts, bitfield_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, newtype_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, rustified_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, rustified_non_exhaustive_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, constified_enum_modules: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, constified_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, default_alias_style: TypeAlias, type_alias: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, new_type_alias: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, new_type_alias_deref: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, builtins: false, emit_ast: false, emit_ir: false, emit_ir_graphviz: None, enable_cxx_namespaces: false, enable_function_attribute_detection: false, disable_name_namespacing: false, disable_nested_struct_naming: false, disable_header_comment: false, layout_tests: true, impl_debug: false, impl_partialeq: false, derive_copy: true, derive_debug: true, derive_default: false, derive_hash: false, derive_partialord: false, derive_ord: false, derive_partialeq: false, derive_eq: false, use_core: false, ctypes_prefix: None, time_phases: false, namespaced_constants: true, msvc_mangling: false, convert_floats: true, raw_lines: [], module_lines: {}, clang_args: ["-I/usr/local/lib/wx/include/osx_cocoa-unicode-3.1", "-I/usr/local/include/wx-3.1", "-DWXUSINGDLL", "-D__WXOSX_COCOA__", "-D__WXMAC__", "-D__WXOSX__", "-pthread", "-I/usr/local/Cellar/llvm/10.0.0_3/lib/clang/10.0.0/include", "-I/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include", "-F/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks", "wrapper.hpp"], input_header: Some("wrapper.hpp"), input_unsaved_files: [], parse_callbacks: None, codegen_config: FUNCTIONS | TYPES | VARS | METHODS | CONSTRUCTORS | DESTRUCTORS, conservative_inline_namespaces: false, generate_comments: true, generate_inline_functions: false, whitelist_recursively: true, objc_extern_crate: false, generate_block: false, block_extern_crate: false, enable_mangling: true, detect_include_paths: false, prepend_enum_name: true, rust_target: Stable_1_40, rust_features: RustFeatures { untagged_union: true, associated_const: true, builtin_clone_impls: true, repr_align: true, i128_and_u128: true, must_use_function: true, repr_transparent: true, min_const_fn: true, core_ffi_c_void: true, repr_packed_n: true, maybe_uninit: true, non_exhaustive: true, thiscall_abi: false }, record_matches: true, size_t_is_usize: false, rustfmt_bindings: true, rustfmt_configuration_file: None, no_partialeq_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, no_copy_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, no_hash_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, array_pointers_in_arguments: false, wasm_import_module_name: None }
wrapper.hpp:1:10: fatal error: 'string' file not found
wrapper.hpp:1:10: fatal error: 'string' file not found, err: true
thread 'main' panicked at 'Unable to generate bindings: ()', /Users/LoganDark/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.54.1/src/main.rs:56:17
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::option::expect_none_failed
   9: bindgen::main
  10: std::rt::lang_start::{{closure}}
  11: std::rt::lang_start_internal
  12: main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Maybe the compiler's wrong? Nope.

1 LoganDark ~/CLionProjects/bindgen-hates-macos
/usr/local/Cellar/llvm/10.0.0_3/bin/clang -I/usr/local/Cellar/llvm/10.0.0_3/lib/clang/10.0.0/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include -F/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks wrapper.hpp
0 LoganDark ~/CLionProjects/bindgen-hates-macos ls
Cargo.lock      Cargo.toml      build.rs        src             target          wrapper.hpp     wrapper.hpp.gch

Let's try letting bindgen find the default Apple compiler:

1 LoganDark ~/CLionProjects/bindgen-hates-macos env RUST_LOG=bindgen RUST_BACKTRACE=1 bindgen wrapper.hpp
cargo:warning=couldn't execute `llvm-config --prefix` (error: No such file or directory (os error 2))
cargo:warning=set the LLVM_CONFIG_PATH environment variable to the full path to a valid `llvm-config` executable (including the executable itself)
[2020-07-22T05:55:07Z INFO  bindgen] Clang Version: clang version 10.0.0 , parsed: Some((10, 0))
[2020-07-22T05:55:07Z DEBUG bindgen] Generating bindings, libclang at /usr/local/opt/llvm@10/lib/libclang.dylib
[2020-07-22T05:55:07Z DEBUG bindgen] Trying to find clang with flags: []
[2020-07-22T05:55:07Z DEBUG bindgen] Found clang: Clang { path: "/usr/bin/clang", version: Some(CXVersion { Major: 10, Minor: 0, Subminor: 1 }), c_search_paths: Some(["/usr/local/include", "/Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include", "/Library/Developer/CommandLineTools/usr/include", "/usr/include", "/System/Library/Frameworks", "/Library/Frameworks"]), cpp_search_paths: Some(["/Library/Developer/CommandLineTools/usr/include/c++/v1", "/usr/local/include", "/Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include", "/Library/Developer/CommandLineTools/usr/include", "/usr/include", "/System/Library/Frameworks", "/Library/Frameworks"]) }
[2020-07-22T05:55:07Z DEBUG bindgen] Fixed-up options: BindgenOptions { blacklisted_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, blacklisted_functions: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, blacklisted_items: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, opaque_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, rustfmt_path: None, whitelisted_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, whitelisted_functions: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, whitelisted_vars: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, default_enum_style: Consts, bitfield_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, newtype_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, rustified_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, rustified_non_exhaustive_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, constified_enum_modules: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, constified_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, default_alias_style: TypeAlias, type_alias: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, new_type_alias: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, new_type_alias_deref: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, builtins: false, emit_ast: false, emit_ir: false, emit_ir_graphviz: None, enable_cxx_namespaces: false, enable_function_attribute_detection: false, disable_name_namespacing: false, disable_nested_struct_naming: false, disable_header_comment: false, layout_tests: true, impl_debug: false, impl_partialeq: false, derive_copy: true, derive_debug: true, derive_default: false, derive_hash: false, derive_partialord: false, derive_ord: false, derive_partialeq: false, derive_eq: false, use_core: false, ctypes_prefix: None, time_phases: false, namespaced_constants: true, msvc_mangling: false, convert_floats: true, raw_lines: [], module_lines: {}, clang_args: ["-isystem", "/usr/local/include", "-isystem", "/Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include", "-isystem", "/Library/Developer/CommandLineTools/usr/include", "-isystem", "/usr/include", "-isystem", "/System/Library/Frameworks", "-isystem", "/Library/Frameworks", "wrapper.hpp"], input_header: Some("wrapper.hpp"), input_unsaved_files: [], parse_callbacks: None, codegen_config: FUNCTIONS | TYPES | VARS | METHODS | CONSTRUCTORS | DESTRUCTORS, conservative_inline_namespaces: false, generate_comments: true, generate_inline_functions: false, whitelist_recursively: true, objc_extern_crate: false, generate_block: false, block_extern_crate: false, enable_mangling: true, detect_include_paths: true, prepend_enum_name: true, rust_target: Stable_1_40, rust_features: RustFeatures { untagged_union: true, associated_const: true, builtin_clone_impls: true, repr_align: true, i128_and_u128: true, must_use_function: true, repr_transparent: true, min_const_fn: true, core_ffi_c_void: true, repr_packed_n: true, maybe_uninit: true, non_exhaustive: true, thiscall_abi: false }, record_matches: true, size_t_is_usize: false, rustfmt_bindings: true, rustfmt_configuration_file: None, no_partialeq_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, no_copy_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, no_hash_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, array_pointers_in_arguments: false, wasm_import_module_name: None }
wrapper.hpp:1:10: fatal error: 'string' file not found
wrapper.hpp:1:10: fatal error: 'string' file not found, err: true
thread 'main' panicked at 'Unable to generate bindings: ()', /Users/LoganDark/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.54.1/src/main.rs:56:17
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::option::expect_none_failed
   9: bindgen::main
  10: std::rt::lang_start::{{closure}}
  11: std::rt::lang_start_internal
  12: main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Nope. Surely it must not work right?

0 LoganDark ~/CLionProjects/bindgen-hates-macos rm wrapper.hpp.gch
0 LoganDark ~/CLionProjects/bindgen-hates-macos ls
Cargo.lock  Cargo.toml  build.rs    src         target      wrapper.hpp
0 LoganDark ~/CLionProjects/bindgen-hates-macos clang wrapper.hpp
0 LoganDark ~/CLionProjects/bindgen-hates-macos ls
Cargo.lock      Cargo.toml      build.rs        src             target          wrapper.hpp     wrapper.hpp.gch

It does. However, with all the extra flags added by bindgen it doesn't:

1 LoganDark ~/CLionProjects/bindgen-hates-macos
clang -isystem /usr/local/include -isystem /Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include -isystem /Library/Developer/CommandLineTools/usr/include -isystem /usr/include -isystem /System/Library/Frameworks -isystem /Library/Frameworks wrapper.hpp
In file included from wrapper.hpp:1:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string:500:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string_view:176:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__string:56:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/algorithm:640:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/initializer_list:47:
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstddef:44:15: fatal error: 'stddef.h' file not found
#include_next <stddef.h>
              ^~~~~~~~~~
1 error generated.

So telling bindgen not to add those flags should work then, right?

0 LoganDark ~/CLionProjects/bindgen-hates-macos
env RUST_LOG=bindgen RUST_BACKTRACE=1 bindgen --no-include-path-detection wrapper.hpp
cargo:warning=couldn't execute `llvm-config --prefix` (error: No such file or directory (os error 2))
cargo:warning=set the LLVM_CONFIG_PATH environment variable to the full path to a valid `llvm-config` executable (including the executable itself)
[2020-07-22T05:58:27Z INFO  bindgen] Clang Version: clang version 10.0.0 , parsed: Some((10, 0))
[2020-07-22T05:58:27Z DEBUG bindgen] Generating bindings, libclang at /usr/local/opt/llvm@10/lib/libclang.dylib
[2020-07-22T05:58:27Z DEBUG bindgen] Fixed-up options: BindgenOptions { blacklisted_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, blacklisted_functions: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, blacklisted_items: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, opaque_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, rustfmt_path: None, whitelisted_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, whitelisted_functions: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, whitelisted_vars: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, default_enum_style: Consts, bitfield_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, newtype_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, rustified_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, rustified_non_exhaustive_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, constified_enum_modules: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, constified_enums: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, default_alias_style: TypeAlias, type_alias: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, new_type_alias: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, new_type_alias_deref: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, builtins: false, emit_ast: false, emit_ir: false, emit_ir_graphviz: None, enable_cxx_namespaces: false, enable_function_attribute_detection: false, disable_name_namespacing: false, disable_nested_struct_naming: false, disable_header_comment: false, layout_tests: true, impl_debug: false, impl_partialeq: false, derive_copy: true, derive_debug: true, derive_default: false, derive_hash: false, derive_partialord: false, derive_ord: false, derive_partialeq: false, derive_eq: false, use_core: false, ctypes_prefix: None, time_phases: false, namespaced_constants: true, msvc_mangling: false, convert_floats: true, raw_lines: [], module_lines: {}, clang_args: ["wrapper.hpp"], input_header: Some("wrapper.hpp"), input_unsaved_files: [], parse_callbacks: None, codegen_config: FUNCTIONS | TYPES | VARS | METHODS | CONSTRUCTORS | DESTRUCTORS, conservative_inline_namespaces: false, generate_comments: true, generate_inline_functions: false, whitelist_recursively: true, objc_extern_crate: false, generate_block: false, block_extern_crate: false, enable_mangling: true, detect_include_paths: false, prepend_enum_name: true, rust_target: Stable_1_40, rust_features: RustFeatures { untagged_union: true, associated_const: true, builtin_clone_impls: true, repr_align: true, i128_and_u128: true, must_use_function: true, repr_transparent: true, min_const_fn: true, core_ffi_c_void: true, repr_packed_n: true, maybe_uninit: true, non_exhaustive: true, thiscall_abi: false }, record_matches: true, size_t_is_usize: false, rustfmt_bindings: true, rustfmt_configuration_file: None, no_partialeq_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, no_copy_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, no_hash_types: RegexSet { items: [], matched: [], set: Some(RegexSet([])), record_matches: true }, array_pointers_in_arguments: false, wasm_import_module_name: None }
wrapper.hpp:1:10: fatal error: 'string' file not found
wrapper.hpp:1:10: fatal error: 'string' file not found, err: true
thread 'main' panicked at 'Unable to generate bindings: ()', /Users/LoganDark/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.54.1/src/main.rs:56:17
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::option::expect_none_failed
   9: bindgen::main
  10: std::rt::lang_start::{{closure}}
  11: std::rt::lang_start_internal
  12: main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Nope...

LoganDark commented 4 years ago

Repro here https://github.com/LoganDark/bindgen-hates-macos if anyone has a macOS 10.14 machine.

kulp commented 4 years ago

I easily reproduced this on my macOS 10.14.6 machine.

cd $(mktemp -d)
git clone https://github.com/LoganDark/bindgen-hates-macos.git
cargo test

I do not know anything further at this time. I might be able to look at this on Friday.

LoganDark commented 4 years ago

Yesss, thank you!

LoganDark commented 4 years ago

Hey, any progress on this? Still impacted by this issue.

kulp commented 4 years ago

I looked at this a little while longer.

I agree that this particular problem should not arise (#1597 implies that #include <string> works on non-macOS platforms).

I was able to work around the issue for your particular testcase by adding these two lines before .generate():

.clang_arg("-I/Library/Developer/CommandLineTools/usr/include/c++/v1")
.clang_arg("-I/Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include")

(the first arg for <string> and the second for <stdarg.h>).

I understand that this is not really a solution, but I have no experience using bindgen with C++, so I am not likely to be much more help myself. Perhaps @emilio has seen something like this before.

LoganDark commented 4 years ago

Well, bindgen already tries to detect include paths so I suppose it should know this already.

It is too a solution, but one I shouldn't have to apply myself. bindgen should understand that these options are necessary (in that order too) and automatically apply them. Either that, or it should invoke the compiler in such a way that these options are not necessary to explicitly provide (maybe not possible with libclang, I'm not sure).

LoganDark commented 4 years ago

So it seems like the solution is specifying /Library/Developer/CommandLineTools/usr/include/c++/v1 before the other include paths - since stuff uses #include_next, the included file has to exist after that file in the include chain, not before. That's hilarious, because bindgen seems to just throw flags around carelessly.

This could probably be fixed by bindgen automatically finding the STL and including it first in the include chain. That solution is cross-platform and could also be preventative towards other, unforeseen issues.

milahu commented 2 years ago

similar problem on nixos linux i must set include paths for bindgen::Builder::default() in c2rust-ast-exporter/build.rs

    let cppbindings = bindgen::Builder::default()
        .header("src/ExportResult.hpp")
        .whitelist_type("ExportResult")
        .generate_comments(true)
        .derive_default(true)
        // Tell bindgen we are processing c++
        .clang_arg("-xc++")
        .clang_arg("-std=c++11")

        // NixOS workaround to find header files
        // https://github.com/rust-lang/rust-bindgen/issues/1834
        // c2rust/c2rust-ast-exporter/src/ExportResult.hpp:11:10: fatal error: 'algorithm' file not found
        .clang_arg(format!("-I{}/c++/v1", env::var("LIBCXX_INCLUDE_DIR").unwrap()))
        // /nix/store/fpnnmg22plmha1qsq1fvsjsar3ziz2k1-libcxx-7.1.0-dev/include/c++/v1/__config:206:12: fatal error: 'features.h' file not found
        .clang_arg(format!("-I{}", env::var("GLIBC_INCLUDE_DIR").unwrap()))
        // /nix/store/fpnnmg22plmha1qsq1fvsjsar3ziz2k1-libcxx-7.1.0-dev/include/c++/v1/cstddef:44:15: fatal error: 'stddef.h' file not found
        .clang_arg(format!("-I{}", env::var("LIBC_INCLUDE_DIR").unwrap()))

        .generate()
        .or(Err("Unable to generate ExportResult bindings"))?;
# default.nix
{
  preBuild = ''
    export LIBCLANG_PATH=${pkgs.libclang.lib}/lib
    export LIBCXX_INCLUDE_DIR=${pkgs.libcxx.dev}/include
    export GLIBC_INCLUDE_DIR=${pkgs.glibc.dev}/include
    export LIBC_INCLUDE_DIR=${pkgs.libclang.lib}/lib/clang/7.1.0/include
  '';
levkk commented 1 year ago

I hit this on Linux (Ubuntu) as well. I ended up manually adding:

#[cfg(target_os = "linux")]
let bindings = bindings
    .clang_arg(format!("-I/usr/include/c++/11"))
    .clang_arg(format!("-I/usr/include/x86_64-linux-gnu/c++/11"));

to my build.rs.

spacejam commented 1 month ago

I hit this on macos after a system update seems to have broken my non-app-store-installed copy of xcode. I realized I could work around it by setting export CPPFLAGS="-I/Library/Developer/CommandLineTools/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/" (a directory that contains iostream and string etc... on my system), but then I seem to have fixed it without explicitly setting that env var by going into the xcode Settings GUI, going to the "Locations" tab, and even though Command Line Tools already listed Xcode 16, when I clicked its drop down (there was only one option for me) and I re-selected it, it asked me to authenticate, and then suddenly the system started working again. Before explicitly clicking this, xcode-select --print-path printed out /Library/Developer/CommandLineTools, but after this reconfiguration it printed out /Applications/Xcode.app/Contents/Developer, and then compilation started working as expected without the env var workaround. Hope this helps somebody!

ron-monday commented 1 month ago

@spacejam Thank you so much for sharing. Solved my issue.

alindima commented 3 days ago

Same issue as @spacejam, ran into similar errors after a macos system update. The brew-installed llvm was out of date. brew update && brew install llvm fixed it for me (the brew-installed clang was my default)