Skip to content

Commit 9ff08a6

Browse files
committed
Updated Documentation
1 parent fe1fd56 commit 9ff08a6

File tree

1 file changed

+40
-55
lines changed

1 file changed

+40
-55
lines changed

Readme.md

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,69 @@
11
# Rust Catalyst Example
22

3-
This is an example that shows how to build a static library supporting Catalyst from Rust.
3+
This is an example that shows how to build a static library supporting Mac Catalyst (X86_64 and ARM64) from Rust.
44

5-
## Requirements
6-
7-
1. [Xargo](https://github.com/japaric/xargo)
8-
2. Rust Nightly
9-
3. Rust Source (after switching to nightly)
10-
4. Xcode 11+
115

12-
## Not Required
13-
- the `XARGO_RUST_SRC` env variable
14-
15-
## Full Local Installation
16-
17-
``` bash
18-
cargo install xargo
19-
rustup toolchain install nightly
20-
rustup toolchain default nightly
6+
# Usage
217

22-
# Or use a directory override
23-
rustup override set nightly
24-
```
8+
Until [this PR that adds Catalyst ARM64 support to Rust](https://github.com/rust-lang/rust/pull/77484) is merged, you need to build the Rust compiler. Hence, jump to the end to see how to build and use a custom Rust toolchain based on 77484.
259

26-
## Using It
10+
This repo contains an Xcode project that sets up everything to include a library written in Rust and call functions in it. The repo is set up to use ARM64 and X86_64 Catalyst. It should compile fine if you select the `My Mac` target. If you select the `Any Mac` target, it requires the above mentioned PR / a custom toolchain.
2711

28-
Just do a release build with the correct target
12+
The Xcode project also contains all the required binaries to try this out immediately. You can just open `XcodeIntegration.xcodeproj` and build.
2913

30-
``` bash
31-
xargo build --target x86_64-apple-ios-macabi --release
32-
```
14+
# Usage with normal nightly Rust
3315

34-
## Caveats
3516

36-
- Building for other archs (such as the host arch) also requires setting the target.
37-
- Non-Release builds fail on some targets
38-
- Lipo can be used to make a fat binary (see below)
17+
## Requirements
3918

40-
## Fat Binary
19+
1. Rustup / Rust Nightly
20+
2. Xcode 12
4121

42-
This requires that the correct targets are installed for non-macabi:
22+
## Full Local Installation
4323

4424
``` bash
25+
rustup toolchain install nightly
26+
rustup toolchain default nightly
4527
rustup target add aarch64-apple-ios
46-
```
28+
rustup target add x86_64-apple-ios
4729

48-
Then the following will generate a fat binary. You can also just call the `make_fat.sh` included in the example project.
30+
# Or use a directory override
31+
rustup override set nightly
4932

50-
``` bash
51-
# lipo together the different architectures into a universal 'fat' file
52-
xargo build --target x86_64-apple-ios-macabi --release
53-
xargo build --target aarch64-apple-ios --release
54-
lipo -create -output target/libtest1.a target/{x86_64-apple-darwin,aarch64-apple-ios,x86_64-apple-darwin}/release/libtest1.a
33+
./make_fat.sh
5534
```
5635

57-
Note that we're not including `x86_64-apple-darwin` because a fat binary cannot contain darwing x86_64 and iOS x86_64 together.
36+
It will automatically generate the binaries and write them to `XcodeIntegration/Rust`
5837

59-
# How it works
38+
Open Xcode, hit compile.
6039

61-
Tx86_64-he `x86_64-apple-ios-macabi.json` file contains the information that `Xargo` needs to build a custom sysroot to compile your project with.
62-
A sysroot is the `libstd`, `libcore` and so on.
40+
### build-std
6341

64-
## Cargo.toml
42+
Catalyst is not a tier 1 Rust platform, so there is no pre-build standard library. This repository uses `cargo build-std` to automatically build the standard library for the given platform. This takes a bit longer but works reliably (at least for me).
6543

66-
The panic line:
44+
## Custom Rust Toolchain
6745

68-
``` toml
69-
[profile.release]
70-
panic = "abort"
46+
```
47+
git clone https://github.com/rust-lang/rust.git
48+
cd rust
49+
cp config.toml.sample config.toml
7150
```
7251

73-
Seems to be required as `panic_unwind` leads to a failing build.
74-
75-
## Xargo.toml
52+
Edit config.toml and change `build-stage = 1` to `build-stage = 2` (line 149)
53+
54+
```
55+
./x.py build
56+
```
57+
58+
Install with
59+
```
60+
rustup toolchain link myrust ~/rust/build/x86_64-apple-darwin/stage2/
61+
```
7662

77-
Just copy the contents verbatim. Otherwise it fails to build `libstd`.
63+
Go back to this directory
64+
```
65+
rustup default myrust
66+
```
7867

79-
``` toml
80-
std = {features = ["jemalloc"]}
68+
Now you can continue with (Full Local Installation) above.
8169

82-
[dependencies]
83-
std = {}
84-
```

0 commit comments

Comments
 (0)