rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

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

Open LoganDark opened this issue 4 years ago • 11 comments

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 avatar Jul 22 '20 06:07 LoganDark

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

LoganDark avatar Jul 22 '20 06:07 LoganDark

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.

kulp avatar Jul 22 '20 11:07 kulp

Yesss, thank you!

LoganDark avatar Jul 22 '20 15:07 LoganDark

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

LoganDark avatar Jul 25 '20 10:07 LoganDark

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.

kulp avatar Jul 26 '20 22:07 kulp

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 avatar Jul 26 '20 23:07 LoganDark

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.

LoganDark avatar Jul 27 '20 05:07 LoganDark

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
  '';

milahu avatar Dec 05 '21 21:12 milahu

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.

levkk avatar May 01 '23 17:05 levkk