docs.rs icon indicating copy to clipboard operation
docs.rs copied to clipboard

Cannot cross-compile to windows if using C compiler in build script

Open Srinivasa314 opened this issue 5 years ago • 9 comments

After a day documentation is still not built for version 0.1.4. In version 0.1.3, there is no documentation for windows and the example in the crate level documentation does not contain the code I added in version 0.1.3.

Srinivasa314 avatar Jun 01 '20 06:06 Srinivasa314

Going backwards through the issues:

The 0.1.3 crate level docs appear to match the source from crates.io. (Checked with cargo download -x alcro==0.1.3).


The windows documentation build failed because tinyfiledialog builds a native library, which I don't think is possible for Windows on docs.rs yet. (@jyn514 do we actually have any issue tracking problems with targetting x86_64-pc-windows-msvc?).


The 0.1.4 build failed because it believes the Cargo.lock needs to be updated

error: the lock file /opt/docsrs/rustwide/builds/alcro-0.1.4/source/Cargo.lock needs to be updated but --locked was passed to prevent this

There's a bug that docs.rs does not record build status if it fails this early (#797). And the actual failure seems to be a cargo bug, docs.rs regenerates the lockfile if it fails to fetch the sources, but it seems even the regenerated lockfile doesn't work (https://github.com/rust-lang/cargo/issues/8302).

Nemo157 avatar Jun 01 '20 11:06 Nemo157

The windows documentation build failed because tinyfiledialog builds a native library, which I don't think is possible for Windows on docs.rs yet. (@jyn514 do we actually have any issue tracking problems with targetting x86_64-pc-windows-msvc?)

From my understanding, the build failed because we cross-compiled from Linux to Windows? I think we should make an issues for failures due to cross-compilation, not for windows specifically.

jyn514 avatar Jun 01 '20 13:06 jyn514

Sure, a general issue about cross compilation would be useful, but the reasons for different targets are going to be different enough that it might be useful to have sub-issues for them (e.g. cross-compiling to x86_64-pc-windows-gnu is easy, it just requires adding in more tools to the build-env, for -msvc I’m not sure if there’s a solution to the lack of link.exe).

Nemo157 avatar Jun 01 '20 14:06 Nemo157

cross-compiling to x86_64-pc-windows-gnu is easy, it just requires adding in more tools to the build-env

This is not usually the case. Most build failures are because pkg-config disables cross-compilation by default:

Cross compilation detected. Use PKG_CONFIG_ALLOW_CROSS=1 to override

That will be an issue regardless of the target. Can you paste the error that alcro has for windows so I can see what failed?

jyn514 avatar Jun 01 '20 15:06 jyn514

For x86_64-pc-windows-msvc (ignoring the failure because of tinyfiledialog writing temporary files to the source folder):

running: "lib.exe" "-out:/alcro-0.1.3/target/x86_64-pc-windows-msvc/debug/build/tinyfiledialogs-843c895d48dd6318/out/libtinyfiledialogs.a" "-nologo" "/alcro-0.1.3/target/x86_64-pc-windows-msvc/debug/build/tinyfiledialogs-843c895d48dd6318/out/libtinyfiledialogs/tinyfiledialogs.o"

--- stderr
error occurred: Failed to find tool. Is `lib.exe` installed?

For x86_64-pc-windows-gnu:

running: "x86_64-w64-mingw32-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-v" "-o" "/alcro-0.1.3/target/x86_64-pc-windows-gnu/debug/build/tinyfiledialogs-a43b97fc6b9fcef9/out/libtinyfiledialogs/tinyfiledialogs.o" "-c" "libtinyfiledialogs/tinyfiledialogs.c"

--- stderr
error occurred: Failed to find tool. Is `x86_64-w64-mingw32-gcc` installed?

then after an apt install gcc-mingw-w64 it successfully built the documentation.

Nemo157 avatar Jun 01 '20 15:06 Nemo157

UPDATE: I fixed a bug in version 0.1.4 so I yanked it. Also I changed the version of winapi from ^0 to ^0.3. Documentation for 0.1.5 appears only for linux and macos in docs.rs

edit : For the tinyfiledialogs crate also documentation only appears for linux and macos in docs.rs

Srinivasa314 avatar Jun 05 '20 07:06 Srinivasa314

The relevant code is https://docs.rs/crate/tinyfiledialogs/3.3.9/source/build.rs, which calls cc libtinyfiledialogs/tinyfiledialogs.c. I'm not sure this is actually a docs.rs bug, it seems to me that it should be trying to use the host compiler toolchain and cross-compiling itself (currently it tries to compile using the target toolchain which obviously fails).

jyn514 avatar Jun 27 '20 22:06 jyn514

Yeah, this is a bug in the cc crate. I opened https://github.com/alexcrichton/cc-rs/issues/523.

jyn514 avatar Jun 27 '20 22:06 jyn514

@Nemo157 from what I see in the comments this build failure was not a docs.rs issue? So we can close this?

Or did this issue grow into "we need to natively build on windows"?

syphar avatar Oct 24 '23 08:10 syphar