Skip to content

crosscompiling macos -> ios + xcodebuild + build-script problem #530

@Dushistov

Description

@Dushistov

I call cargo build from my XCode project and build project for iOS.
One of my crates depend on bindgen, which depend on clang-sys,
which depend on libloading.

And build failed, with such error:

cargo:warning=In file included from src/os/unix/global_static.c:1:
cargo:warning=In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/pthread.h:60:
cargo:warning=In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/time.h:69:
cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types/_clock_t.h:31:9: error: unknown type name '__darwin_clock_t'
cargo:warning=typedef __darwin_clock_t clock_t;

libloading is part of build-script, so it should not be compiled for iOS,
it should be compiled for macOS, but for some reason it compiled for iOS instead of macOS.

Interesting thing that if I run cargo build --target=aarch64-apple-ios manually all works fine.

After analysing what environment variable set xcodebuild I thing culprit is

SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk

because of with it

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-o" "/tmp/global_static.o" "-c" /Users/evgeniy/.cargo/registry/src/github.spider-man.dpdns.org-1ecc6299db9ec823/libloading-0.5.2/src/os/unix/global_static.c

report the same problem, and if I change it into

export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

all works fine if I call cc manually.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions