Skip to content

Docs not built on target platform, causing failures #1957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
CamJN opened this issue Dec 15, 2022 · 13 comments
Open

Docs not built on target platform, causing failures #1957

CamJN opened this issue Dec 15, 2022 · 13 comments
Labels
A-builds Area: Building the documentation for a crate E-hard Effort: This will require a lot of work

Comments

@CamJN
Copy link

CamJN commented Dec 15, 2022

Crate name

getargv

Build failure link

https://docs.rs/crate/getargv/0.1.1/builds/701636

Additional details

This crate has a dep getargv-sys which requires an apple OS to build, I specify:

[package.metadata.docs.rs]
targets = ["x86_64-apple-darwin", "aarch64-apple-darwin"]

In both crates' Cargo.toml; but when docs.rs builds the getargv crate, the getargv-sys crate is built with an incompatible system/command.

@CamJN
Copy link
Author

CamJN commented Dec 16, 2022

Actually I just checked and it fails to build getargv-sys directly too... I see in the log that the build command has the "--target" "x86_64-apple-darwin" flag, but does it actually do anything? the build script still seems to know it's not an apple OS.

@CamJN
Copy link
Author

CamJN commented Dec 16, 2022

I can detect building in docs.rs and bypass the OS check, but the sys/types.h header will be wrong on a non-apple OS so the generated docs will probably be wrong.

@CamJN
Copy link
Author

CamJN commented Dec 16, 2022

not mine but i noticed https://docs.rs/crate/mac-notification-sys/0.5.6 is broken too since docs.rs doesn't build macOS sys crates on macOS, and i imagine there are others too.

@CamJN CamJN changed the title Target is not applied to deps when building docs Docs not built on target platform, causing failures and potential mis-compilation of docs Dec 16, 2022
@syphar
Copy link
Member

syphar commented Dec 16, 2022

Thank you for the report!

Docs.rs currently only builds x86_64-unknown-linux-gnu natively and uses cross-compilation for all other targets (see here).

I see you fixed this (e.g. worked around the limitation) for getargv and getargv-sys already, does this mean this issue is solved for you?

Building on native targets is a bigger topic and not easily solveable right now.

@syphar syphar added A-builds Area: Building the documentation for a crate E-hard Effort: This will require a lot of work labels Dec 16, 2022
@CamJN
Copy link
Author

CamJN commented Dec 16, 2022

Yeah I made it build, but I had to shim in a header, and I was wondering what the current advice is for bindgen based crates on non-linux platforms?

I'm also still a bit confused why cfg!(not(target_vendor = "apple")) does not reflect the target triple set with the --target flag in the build command.

@Nemo157
Copy link
Member

Nemo157 commented Dec 16, 2022

I'm also still a bit confused why cfg!(not(target_vendor = "apple")) does not reflect the target triple set with the --target flag in the build command.

The build script is always built for the host, which is what cfg! checks; if you want to know what target it is being run for you need to inspect the environment variable CARGO_CFG_TARGET_VENDOR while it is running.

@jyn514
Copy link
Member

jyn514 commented Dec 21, 2022

potential mis-compilation of docs

I think this bit is not true, the cfg was set correctly, the build script was just interpreting it wrong.

@jyn514 jyn514 changed the title Docs not built on target platform, causing failures and potential mis-compilation of docs Docs not built on target platform, causing failures Dec 21, 2022
@CamJN
Copy link
Author

CamJN commented Dec 21, 2022

@jyn514 it can very much cause miscompilation. If you run bindgen on the wrong platform it might pick up a header with a type defined for say x86 linux instead of aarch64 macOS, which would result in mistakes in the generated docs.

@jyn514
Copy link
Member

jyn514 commented Dec 21, 2022

@CamJN that sounds like a bug in bindgen, that would break when cross-compiling as well.

@CamJN
Copy link
Author

CamJN commented Dec 21, 2022

Cross compiling anything that links to C requires you to have all of the C headers of the target installed. Bindgen supports this fine by allowing you to specify where to look for C stdlib headers, your environment does not provide these things, so cross compiling does not work properly.

@CamJN
Copy link
Author

CamJN commented Dec 26, 2022

If you'd like some docs on how to get the headers this does a decent job of explaining what's required: https://github.com/tpoechtrager/osxcross#packaging-the-sdk

@Nemo157
Copy link
Member

Nemo157 commented Dec 27, 2022

Xcode's license terms do not allow using it for cross-compiling from non-Apple hardware. I don't believe AWS offers Linux-on-Apple-hardware, so there's really no way we can support cross-compilation that requires the Xcode SDK, the only solution would be setting up native macOS build instances (something I think will eventually be needed to properly support macOS-only libraries, but is not going to happen soon as there's a lot of architectural questions that would have to be resolved first).

@CamJN
Copy link
Author

CamJN commented Dec 27, 2022

Fair enough, in looking at the headers that I use specifically the license seems fine (it's pretty much bsd-4-clause + don't pirate macOS), but the license for the whole sdk is probably not compatible.

You may want to put something in your docs or elsewhere that generated docs for crates that link to C and are cross-compiled will likely have incorrect types atm, since I don't believe the headers are present for any non-linux OS, and I don't know if the arch is set at the docker image level (ie building arm docs will see arm C-headers) or just at the cargo level.

This is probably an even bigger problem for crates used for embedded development, since those machines are more likely to have unusual C-type sizes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-builds Area: Building the documentation for a crate E-hard Effort: This will require a lot of work
Projects
None yet
Development

No branches or pull requests

4 participants