Skip to content

aarch64-apple-ios cannot be cross-compiled from Linux and causes cargo doc failures #76584

Closed

Description

@bbqsrc

All up there seems to two issues:

  • Docs cannot be generated for iOS from non-macOS hosts because of a dependency on a binary for generating linker flags that only exists on macOS
  • Errors are not being propagated from this part of the build process to rustbuild, leaving for a headscratcher

I added an aarch64-apple-ios requirement to the docs.rs metadata in one of my crates, which caused a build failure on docs.rs. rust-lang/docs.rs#1040

Upon trying to reproduce this issue and find a fix, I hit the issue while trying to build rustc with the target aarch64-apple-ios from an x86_64 Linux host.

$ ./x.py build --target aarch64-apple-ios
Updating only changed submodules
Submodules updated in 0.02 seconds
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s


error occurred: No such file or directory (os error 2)


failed to run: /.../rust/build/bootstrap/debug/bootstrap build --target aarch64-apple-ios
Build completed unsuccessfully in 0:00:00

Not ideal output. 😛

The reason this happens is quite straightforward: ios and tvos targets use the apple_sdk_base module to resolve the pre_link_args field, and it is fallable.

The logic in the get_sdk_root function seems a little faulty, as it does a simple check for existence of a directory from the environment variable SDKROOT, then if that fails, it tries to run the xcrun binary which only exists on macOS hosts. That xcrun failure is a hard failure.

As stated in rust-lang/docs.rs#1040, a workaround for at least generating documentation is to provide SDKROOT with a path to an empty directory to iPhoneOS.platform.

No such issue occurs on *-apple-darwin because an entirely different codepath is taken.

I am not sure of the right course of action to fix this:

  1. Change ios and tvos targets to not require pre_link_flags to be set, like macOS, and let build failures occur after printing a warning so the user can at least fix the issue
  2. Add a hack for doc so that at least docs.rs can generate documentation for ios
  3. Don't change this behaviour at all, but fix the error message so that cross-compiling devs won't just stare blindly at their screen asking "why me"

My preference is for the first option, and I'm quite happy to contribute a fix for it, though I would need assistance in successfully cross-compiling rustc for macOS from Linux. 😄


It is probable that this is the same issue: #42084.

Activity

  1. added
    A-crossArea: Cross compilation
    O-iosOperating system: iOS
    on Sep 10, 2020
  2. jyn514 commented on Sep 10, 2020

    @jyn514
    Member

    My preference is for the first option, and I'm quite happy to contribute a fix for it, though I would need assistance in successfully cross-compiling rustc for macOS from Linux. 😄

    You shouldn't need to cross-compile rustc, if you can build stage1 on linux and then try using stage1 to cross-compile to iOS that should be enough to make sure it's fixed. Note that cross-compiling rustc itself is different from cross-compiling using the rustc you've built for the host target.

  3. bbqsrc commented on Sep 10, 2020

    @bbqsrc
    Author

    and then try using stage1 to cross-compile to iOS

    How do I go about doing that? I've read the rustc dev guide a couple of times and I'm still not certain.

  4. jyn514 commented on Sep 10, 2020

    @jyn514
    Member

    Follow the instructions in https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html?highlight=toolchain#creating-a-rustup-toolchain, then run cargo +stage1 doc --target aarch64-apple-ios like you normally would.

  5. jyn514 commented on Sep 20, 2020

    @jyn514
    Member

    @bbqsrc let me know if you need help working on this :)

  6. bbqsrc commented on Sep 20, 2020

    @bbqsrc
    Author

    Ah, been side tracked by life. I intend to look into this next weekend at this stage. Will definitely ping if I need anything, most likely on Zulip. 😄 thanks

  7. added a commit that references this issue on Oct 1, 2020
    37df40b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-crossArea: Cross compilationC-bugCategory: This is a bug.O-iosOperating system: iOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions