Skip to content
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

Allow the iOS toolchain to be built on Linux #88072

Merged
merged 1 commit into from
Aug 22, 2021
Merged

Allow the iOS toolchain to be built on Linux #88072

merged 1 commit into from
Aug 22, 2021

Conversation

kit-981
Copy link
Contributor

@kit-981 kit-981 commented Aug 16, 2021

The iOS toolchain can be built on Linux with minor changes. The compilation will invoke xcrun to find the path to the iPhone SDK but a fake xcrun executable can be used.

#!/bin/sh
echo "/path/to/sdk"

The iOS toolchain can then be built and linked with rustup.

$ ./x.py build --stage 2 --host x86_64-unknown-linux-gnu \
  	 --target aarch64-apple-ios
$ rustup toolchain link stage1 build/x86_64-unknown-linux-gnu/stage1

It's possible to take this toolchain and compile an iOS executable with it. This requires the ld64 linker and an iOS SDK. The ld64 linker can be taken from cctools. A project's .cargo/config can then be edited to use the linker for this target.

[target.aarch64-apple-ios]
linker = "/path/to/cctools/bin/arm-apple-darwin-ld"
rustflags = [
    "-C",
    """
link-args=
    -F/path/to/sdk/System/Library/Frameworks
    -L/path/to/sdk/usr/lib
    -L/path/to/sdk/usr/lib/system/
    -adhoc_codesign
    """,
]

The iOS toolchain can be built on Linux with minor changes. The
compilation will invoke `xcrun` to find the path to the iPhone SDK but
a fake `xcrun` executable can be used.

```
#!/bin/sh
echo "/path/to/sdk"
```

The iOS toolchain can then be built and linked with rustup.

```
$ ./x.py build --stage 2 --host x86_64-unknown-linux-gnu \
  	 --target aarch64-apple-ios
$ rustup toolchain link stage1 build/x86_64-unknown-linux-gnu/stage1
```

It's possible to take this toolchain and compile an iOS executable
with it. This requires the ld64 linker and an iOS SDK. The ld64 linker
can be taken from
[cctools](https://github.com/tpoechtrager/cctools-port). A project's
.cargo/config can then be edited to use the linker for this target.

```
[target.aarch64-apple-ios]
linker = "/path/to/cctools/bin/arm-apple-darwin-ld"
rustflags = [
    "-C",
    """
link-args=
    -F/path/to/sdk/System/Library/Frameworks
    -L/path/to/sdk/usr/lib
    -L/path/to/sdk/usr/lib/system/
    -adhoc_codesign
    """,
]
```
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 16, 2021
@jyn514
Copy link
Member

jyn514 commented Aug 16, 2021

Hmm, could you change this to check if xcrun is installed instead? That way it still fails quickly if you don't have the MacOS SDK installed.

@kit-981
Copy link
Contributor Author

kit-981 commented Aug 16, 2021

Hmm, could you change this to check if xcrun is installed instead? That way it still fails quickly if you don't have the MacOS SDK installed.

This case is already handled and, from what I can tell, is handled before the check against the host operating system:

patches/rust % ./x.py build --stage 2 --host x86_64-unknown-linux-gnu --target aarch64-apple-ios
Updating only changed submodules
Submodules updated in 0.01 seconds
    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
running: "xcrun" "--show-sdk-path" "--sdk" "iphoneos"


error occurred: Failed to find tool. Is `xcrun` installed?


Build completed unsuccessfully in 0:00:00
running: "xcrun" "--show-sdk-path" "--sdk" "iphoneos"
exit status: 0
running: "xcrun" "--show-sdk-path" "--sdk" "iphoneos"
exit status: 0
thread 'main' panicked at 'the iOS target is only supported on macOS', src/bootstrap/sanity.rs:171:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Build completed unsuccessfully in 0:01:13

@Mark-Simulacrum
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 19, 2021

📌 Commit 79e402e has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 19, 2021
camsteffen added a commit to camsteffen/rust that referenced this pull request Aug 19, 2021
…-on-linux, r=Mark-Simulacrum

Allow the iOS toolchain to be built on Linux

The iOS toolchain can be built on Linux with minor changes. The compilation will invoke `xcrun` to find the path to the iPhone SDK but a fake `xcrun` executable can be used.

```
#!/bin/sh
echo "/path/to/sdk"
```

The iOS toolchain can then be built and linked with rustup.

```
$ ./x.py build --stage 2 --host x86_64-unknown-linux-gnu \
  	 --target aarch64-apple-ios
$ rustup toolchain link stage1 build/x86_64-unknown-linux-gnu/stage1
```

It's possible to take this toolchain and compile an iOS executable with it. This requires the ld64 linker and an iOS SDK. The ld64 linker can be taken from [cctools](https://github.com/tpoechtrager/cctools-port). A project's .cargo/config can then be edited to use the linker for this target.

```
[target.aarch64-apple-ios]
linker = "/path/to/cctools/bin/arm-apple-darwin-ld"
rustflags = [
    "-C",
    """
link-args=
    -F/path/to/sdk/System/Library/Frameworks
    -L/path/to/sdk/usr/lib
    -L/path/to/sdk/usr/lib/system/
    -adhoc_codesign
    """,
]
```
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 22, 2021
Rollup of 13 pull requests

Successful merges:

 - rust-lang#87604 (CI: Verify commits in beta & stable are in upstream branches.)
 - rust-lang#88057 (Update RELEASES to clarify attribute macro values.)
 - rust-lang#88072 (Allow the iOS toolchain to be built on Linux)
 - rust-lang#88170 (Update release note for 1.55.0.)
 - rust-lang#88172 (Test that type alias impl trait happens in a submodule)
 - rust-lang#88179 (Mailmap entry for myself)
 - rust-lang#88182 (We meant to use a trait instead of lifetime here)
 - rust-lang#88183 (test TAIT in different positions)
 - rust-lang#88189 (Add TAIT struct test)
 - rust-lang#88192 (Use of impl trait in an impl as the value for an associated type in a dyn)
 - rust-lang#88194 (Test use of impl Trait in an impl as the value for an associated type in an impl trait)
 - rust-lang#88197 (Test tait use in a fn type)
 - rust-lang#88201 (Test that incomplete inference for TAITs fail)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5ffff5c into rust-lang:master Aug 22, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 22, 2021
@kit-981 kit-981 deleted the feature/build-ios-toolchain-on-linux branch November 9, 2021 07:50
@kit-981 kit-981 mentioned this pull request Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants