Skip to content

Build scripts fail on macOS if the target SDK is not the same as the host #7283

@ghost

Description

Problem

Invoking cargo build from an Xcode project targeting iOS or iOS Simulator fails to build any crate with a custom build script, because the wrong linker is invoked for the custom build script. This is because Xcode sets SDKROOT for the target platform (the build script must be built for the host platform instead)

Steps

  1. git clone [email protected]:rust-lang/libc.git && cd libc
  2. SDKROOT=`xcrun --sdk iphonesimulator --show-sdk-path` cargo +nightly build --target x86_64-apple-ios -vv
    or
    SDKROOT=`xcrun --sdk iphoneos --show-sdk-path` cargo +nightly build --target x86_64-apple-ios -vv
  3. The custom build script is built with the iPhoneSimulator SDK linker instead of the MacOSX SDK linker, which causes the build to fail with undefined symbols

Possible Solution(s)

Invoking rustc for the custom build script should always use the SDK for the host platform instead of the target platform (that is, ignore the SDKROOT environment variable set by the user or Xcode). This can be achieved, for example, by Cargo prepending the rustc invocation with SDKROOT=""

Notes

Output of cargo version: cargo 1.37.0 (9edd089 2019-08-02)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions