Rust-bindgen глючит даже на проекте из туторила

Если toolchain

nightly-x86_64-pc-windows-msvc-

то мой проект компилируется как и ожидается, но мне нужна отладка - при переключении на

nightly-x86_64-pc-windows-gnu

компилироваться перестаёт , стабильные версии ведут себя также

ну, ладно, думаю… наверно в моём коде что то накосячил…

иду в туториал и пытаюсь собрать каноничный проект bzip2 скачиваю проект добавляю в него сишные исходники

получаю точно такое же поведение при компиляции под nightly-x86_64-pc-windows-gnu высыпается ошибка

Compiling bindgen-tutorial-bzip2-sys v0.1.0 (D:\bindgen-tutorial-bzip2-sys-master)
error: failed to run custom build command for bindgen-tutorial-bzip2-sys v0.1.0 (D:\bindgen-tutorial-bzip2-sys-master)
process didn’t exit successfully: D:\bindgen-tutorial-bzip2-sys-master\target\debug\build\bindgen-tutorial-bzip2-sys-6642fcf83988627d\build-script-build (exit code: 101)
— stdout
cargo:rustc-link-lib=bz2

— stderr
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vadefs.h:28:33: error: expected ‘;’ after top level declarator
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:83:1: error: expected identifier
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:83:20: error: expected ‘;’ after top level declarator
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:180:29: error: expected ‘;’ after top level declarator
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:283:51: error: unknown type name ‘uintptr_t’
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:284:67: error: unknown type name ‘uintptr_t’
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:288:8: error: unknown type name ‘uintptr_t’
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:296:1: error: a parameter list without types is only allowed in a function definition
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:12:1: error: expected function body after function declarator
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:287:16: error: unknown type name ‘uintptr_t’
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:561:13: error: unknown type name ‘size_t’
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:2010:1: error: a parameter list without types is only allowed in a function definition
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_stdio_config.h:12:1: error: expected function body after function declarator
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_stdio_config.h:31:10: error: Unsupported architecture
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:31:14: error: unknown type name ‘FILE’
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:49:17: error: unknown type name ‘FILE’
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:58:17: error: unknown type name ‘FILE’
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:67:17: error: unknown type name ‘FILE’
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:79:38: error: unknown type name ‘FILE’
fatal error: too many errors emitted, stopping now [-ferror-limit=]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vadefs.h:28:33: error: expected ‘;’ after top level declarator, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:83:1: error: expected identifier, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:83:20: error: expected ‘;’ after top level declarator, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:180:29: error: expected ‘;’ after top level declarator, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:283:51: error: unknown type name ‘uintptr_t’, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:284:67: error: unknown type name ‘uintptr_t’, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:288:8: error: unknown type name ‘uintptr_t’, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:296:1: error: a parameter list without types is only allowed in a function definition, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:12:1: error: expected function body after function declarator, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:287:16: error: unknown type name ‘uintptr_t’, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:561:13: error: unknown type name ‘size_t’, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:2010:1: error: a parameter list without types is only allowed in a function definition, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_stdio_config.h:12:1: error: expected function body after function declarator, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_stdio_config.h:31:10: error: Unsupported architecture, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:31:14: error: unknown type name ‘FILE’, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:49:17: error: unknown type name ‘FILE’, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:58:17: error: unknown type name ‘FILE’, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:67:17: error: unknown type name ‘FILE’, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:79:38: error: unknown type name ‘FILE’, err: true
fatal error: too many errors emitted, stopping now [-ferror-limit=], err: true
thread ‘main’ panicked at ‘Unable to generate bindings: ()’, src\libcore\result.rs:997:5
stack backtrace:
0: std::sys_common::backtrace::_print
at src\libstd\sys\windows\backtrace/mod.rs:95
at src\libstd\sys\windows\backtrace/mod.rs:82
at src\libstd\sys_common/backtrace.rs:71
1: std::panicking::default_hook::{{closure}}
at src\libstd\sys_common/backtrace.rs:59
at src\libstd/panicking.rs:200
2: std::panicking::default_hook
at src\libstd/panicking.rs:215
3: std::panicking::rust_panic_with_hook
at src\libstd/panicking.rs:478
4: std::panicking::continue_panic_fmt
at src\libstd/panicking.rs:385
5: rust_begin_unwind
at src\libstd/panicking.rs:312
6: core::panicking::panic_fmt
at src\libcore/panicking.rs:85
7: core::result::unwrap_failed
at /rustc/350674b7180a41c8e508d93c6ab8e203b69d3df7\src\libcore/macros.rs:17
8: <core::result::Result<T, E>>::expect
at /rustc/350674b7180a41c8e508d93c6ab8e203b69d3df7\src\libcore/result.rs:825
9: build_script_build::main
at .\build.rs:9
10: std::rt::lang_start::{{closure}}
at /rustc/350674b7180a41c8e508d93c6ab8e203b69d3df7\src\libstd/rt.rs:64
11: std::panicking::try::do_call
at src\libstd/rt.rs:49
at src\libstd/panicking.rs:297
12: _rust_maybe_catch_panic
at src\libpanic_unwind/lib.rs:87
13: std::rt::lang_start_internal
at src\libstd/panicking.rs:276
at src\libstd/panic.rs:388
at src\libstd/rt.rs:48
14: std::rt::lang_start
at /rustc/350674b7180a41c8e508d93c6ab8e203b69d3df7\src\libstd/rt.rs:64
15: main
16: _tmainCRTStartup
17: mainCRTStartup
18: unit_addrs_search
19: unit_addrs_search

Process finished with exit code 101

bindgen = “0.47.3”

это у меня на машине просто такой бардак или …
прошу проверить, и подтвердить / опровергнуть.

С виду, у тебя для сишного кода, собираемого GCC, находятся заголовочные файлы от MSVC.

всё это очевидно…
gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

не понятно кто есть ху.
проверил несколько версий. обнаружил что объектные файлы создаются, исходя из этой схемы

выпадение происходит на этапе линковки.

Всё, разобрался. Если кратко - то проблема была из-за бардака на машине.

Два дня ада и израиля.
по крайней мере понял что мильён мух не могут ошибаться… в хорошем смысле.

сначала в виртуалке был Debian - это был худший случай. Rust поставился но в PATH никак не хотел быть видим. Всюду где надо нужные записи были, и машину перегружал - вот фиг и всё тут. Ну ладно, думаю потом разберусь… но глючное отображение Intellij IDEA (Java) через XRDP меня добило. мало того что оно глючит, так оно и ещё БЕЗБОЖНО тормозит. VNC - как был отстоем сто лет назад - так и остался.

потом в виртуалку поставил MACOS - там всё заработало без нареканий, попробовал поработать… но это опять VNC - ну тормозит же - работать невозможно.

поставил в виртуалку Windows решил разобраться ставя последовательно компоненты…
всё ссылки на mingw-w64 рекомендованные тут просто дико устарели.
всё заброшено и НЕ работает.
и тут я вспомнил, что из-за того что все это оказалось НЕ рабочим, я ставил из чёрти поми каких мест…поэтому вероятно и не работало.
вспомнил про пакетный менедженр под винду https://chocolatey.org оказалось там есть нужный пакет В итоге всё встало идеально.
Нужно только учитывать что оно все пакеты ставит в скрытую директорию C:/ProgramData/chocolatey/lib/mingw
и соответственно когда билд будет ругаться на отсутствие заголовков нужно будет явно указать директорию с заголовками.

bindgen::Builder::default()
        .clang_arg("-IC:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include")
        .rustfmt_bindings(true)......
....

виндовый RDP - это просто шедевр инженерной мысли… работаешь через него как на непосредственно машине.

Теперь всё билдится как надо! Спасибо всем за участие.

2 лайка

А адекватного способа подключения, отличного от “прошить в исходники путь на моей машине, всё остальное не поддерживается”, у них не предусмотрено случайно?

так а где заголовки то искать? по всей машине?

В мире Linux это решается требованием установки переменных среды. В винде можно поступать аналогично.

спасибо большое за участие, это мотивирует копать глубже…

вот что я обнаружил

##ENVIRONMENT

TMPDIR, TEMP, TMP

These environment variables are checked, in order, for the location to write temporary files used during the compilation process.

CPATH

If this environment variable is present, it is treated as a delimited list of paths to be added to the default system include path list. The delimiter is the platform dependent delimiter, as used in the PATH environment variable.

Empty components in the environment variable are ignored.

C_INCLUDE_PATH, OBJC_INCLUDE_PATH, CPLUS_INCLUDE_PATH, OBJCPLUS_INCLUDE_PATH

These environment variables specify additional paths, as for CPATH , which are only used when processing the appropriate language.

MACOSX_DEPLOYMENT_TARGET

If -mmacosx-version-min is unspecified, the default deployment target is read from this environment variable. This option only affects Darwin targets.