Closed snakevil closed 3 years ago
Because of the requirements of Windows when it comes to C runtime selection, you need to do one of the following
RUSTFLAGS=-Ctarget-feature=+crt-static
to make Rust use the fullly static runtimeVCPKGRS_DYNAMIC=1
to link to DLLs.There is a little more info here.
The NotMSVC error message is wrong - sorry about that.
Thanks so much for your advice!
I changed x86_64-pc-windows-msvc = { triplet = "x64-windows-static-md", install = ["tesseract"] }
in the Cargo.toml
, and ran cargo vcpkg build
once more. However the same error message occurred on cargo run
, even with $RUSTFLAGS="-Ctarget-feature=+crt-static"
.
Did I understand something wrong?
Once again, thanks for your immediate reply!
Hmm, maybe the NotMSVC is not spurious after all! Are you actually using the MSVC Rust toolchain, or do you have the -gnu version selected? (rustup show
)
At this point I have not tried vcpkg with mingw - in principle it is possible since a vcpkg triplet community triplet exists. Vcpkg itself was, last time I checked, not yet able to build itself with mingw so an msvc install would be required anyway.
It was so hard to setup a development environment in Windows!
I installed rust and rustup through scoop, for it is more like brew which I'm used to. And I also installed Visual Studio 2017 Build Tools, to use the MSVC ABI without Visual Studio 2015 (or higher) installed.
scoop info rustup
Name: rustup Description: Manage multiple rust installations with ease Version: 1.22.1 Website: https://rustup.rs License: MIT|Apache-2.0 (https://spdx.org/licenses/MIT.html, https://spdx.org/licenses/Apache-2.0.html) Manifest: C:\Users\Snakevil\scoop\buckets\main\bucket\rustup.json Installed: C:\Users\Snakevil\scoop\apps\rustup\1.22.1 Environment: CARGO_HOME=C:\Users\Snakevil\scoop\persist\rustup\.cargo RUSTUP_HOME=C:\Users\Snakevil\scoop\persist\rustup\.rustup PATH=%PATH%;C:\Users\Snakevil\scoop\apps\rustup\1.22.1\.cargo\bin Notes ----- To use the MSVC ABI without Visual Studio 2015 (or higher) installed, you will need the Visual Studio 2017 Build Tools: https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017
scoop info rust
Name: rust Description: A language empowering everyone to build reliable and efficient software. (GNU toolchain) Version: 1.46.0 Website: https://www.rust-lang.org License: MIT|Apache-2.0 (https://spdx.org/licenses/MIT.html, https://spdx.org/licenses/Apache-2.0.html) Manifest: C:\Users\Snakevil\scoop\buckets\main\bucket\rust.json Installed: C:\Users\Snakevil\scoop\apps\rust\1.46.0 Binaries: bin\rustc.exe bin\rustdoc.exe bin\cargo.exe
rustup show
Default host: x86_64-pc-windows-msvc rustup home: C:\Users\Snakevil\scoop\persist\rustup\.rustup stable-x86_64-pc-windows-msvc (default) rustc 1.46.0 (04488afe3 2020-08-24)
That all looks good.
Looking again, I see that you are running find_package
from main.rs
. You need to put vcpkg = "0.2.10"
under [build-dependencies]
and run it from build.rs
.
Thanks for the great detail in the issue. I should have spotted that the first time round.
OK. I appended this new section to Cargo.toml
as:
[dependencies]
vcpkg = "0.2.10"
[build-dependencies]
vcpkg = "0.2.10"
[package.metadata.vcpkg]
git = "https://github.com/microsoft/vcpkg"
rev = "56fffbe"
[package.metadata.vcpkg.target]
x86_64-pc-windows-msvc = { triplet = "x64-windows-static-md", install = ["tesseract"] }
But the error still occurs on cargo run
. Hope the following backtrace could expose something useful.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NotMSVC', src\main.rs:2:38 stack backtrace: 0: backtrace::backtrace::trace_unsynchronized at C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.46\src\backtrace\mod.rs:66 1: std::sys_common::backtrace::_print_fmt at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\sys_common\backtrace.rs:78 2: std::sys_common::backtrace::_print::{{impl}}::fmt at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\sys_common\backtrace.rs:59 3: core::fmt::write at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libcore\fmt\mod.rs:1076 4: std::io::Write::write_fmt<std::sys::windows::stdio::Stderr> at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\io\mod.rs:1537 5: std::sys_common::backtrace::_print at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\sys_common\backtrace.rs:62 6: std::sys_common::backtrace::print at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\sys_common\backtrace.rs:49 7: std::panicking::default_hook::{{closure}} at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\panicking.rs:198 8: std::panicking::default_hook at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\panicking.rs:217 9: std::panicking::rust_panic_with_hook at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\panicking.rs:526 10: std::panicking::begin_panic_handler at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\panicking.rs:437 11: core::panicking::panic_fmt at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libcore\panicking.rs:85 12: core::option::expect_none_failed at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libcore\option.rs:1269 13: core::result::Result<vcpkg::Library, vcpkg::Error>::unwrap<vcpkg::Library,vcpkg::Error> at C:\Users\Snakevil\scoop\persist\rustup\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libcore\result.rs:1005 14: x::main at .\src\main.rs:2 15: std::rt::lang_start::{{closure}}<tuple<>> at C:\Users\Snakevil\scoop\persist\rustup\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\rt.rs:67 16: std::rt::lang_start_internal::{{closure}} at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\rt.rs:52 17: std::panicking::try::do_call at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\panicking.rs:348 18: std::panicking::try at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\panicking.rs:325 19: std::panic::catch_unwind at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\panic.rs:394 20: std::rt::lang_start_internal at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9\/src\libstd\rt.rs:51 21: std::rt::lang_start<tuple<>> at C:\Users\Snakevil\scoop\persist\rustup\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\rt.rs:67 22: main 23: invoke_main at D:\agent\_work\9\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78 24: __scrt_common_main_seh at D:\agent\_work\9\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288 25: BaseThreadInitThunk 26: RtlUserThreadStart
Looks like you need to delete it from main.rs?
Sorry, I don't get your point here. Moved this code snippet into another file, did not change anything.
You need to add a build script.
The build script is an optional program that will be run before the main code in the crate is compiled. It goes in a file called build.rs at the root of the package - the same level as Cargo.toml. The build script gets called by cargo with some extra enviroment variables set that relate to the main code in your package.
The vcpkg build script helper crate that you are calling find_package from requires the extra (build step) environment variables in order to work. It cannot not work without them, so it cannot work from application code in src/main.rs
, only build script code in build.rs
.
Take a look at the build script in the tesseract-sys crate which is used by the tesseract crate for a working example.
OK. I'll read the handbook carefully once again. Thank you very much for your patience and guidance!
Hi, I ran into some unexplained trouble although following the readmes step by step. The steps below are what I exactly did. How could I solve it?
Cargo.toml
cargo vcpkg build
vcpkg_cli probe -l static tesseract
main.rs
cargo run