You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This includes:
* Correctly calling a custom `uniffi-bindgen` through cargo.
* Ditching lipo for individual static libraries per target, that way it
easily works on all Mac hardware (x86_64 or arm64) as well as for iOS
hardware targets.
* Build a `staticlib` using cargo's new `--crate-type` option
Copy file name to clipboardExpand all lines: examples/app/ios/IOSApp.xcodeproj/project.pbxproj
+9-5Lines changed: 9 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@
34
34
"$(SRCROOT)/Generated/$(INPUT_FILE_BASE)FFI.h",
35
35
"$(SRCROOT)/Generated/$(INPUT_FILE_BASE).swift",
36
36
);
37
-
script = "# Generate swift bindings for the todolist rust library.\necho \"Generating files for $INPUT_FILE_PATH\"\n\"$SRCROOT/../../../target/debug/uniffi-bindgen\" generate \"$INPUT_FILE_PATH\" --language swift --out-dir \"$SRCROOT/Generated\"\necho \"Generated files for $INPUT_FILE_BASE in $SRCROOT/Generated\"\n";
37
+
script = "# Generate swift bindings for the todolist rust library.\necho \"Generating files for $INPUT_FILE_PATH\"\n$HOME/.cargo/bin/cargo run -p uniffi-bindgen-cli -- \\\n generate \"$INPUT_FILE_PATH\" \\\n --language swift \\\n --out-dir \"$SRCROOT/Generated\"\necho \"Generated files for $INPUT_FILE_BASE in $SRCROOT/Generated\"\n";
The header file is a descriptor of the C API to a library that hasn't been built yet. The Swift file is a Swift facade that calls that C API.
@@ -49,91 +56,89 @@ The header file is a descriptor of the C API to a library that hasn't been built
49
56
#ifndef IOSApp_Bridging_Header_h
50
57
#define IOSApp_Bridging_Header_h
51
58
52
-
#import "todolist-Bridging-Header.h"
59
+
#import "todolistFFI.h"
53
60
54
61
#endif/* IOSApp_Bridging_Header_h */
55
62
```
56
63
57
-
The `#import` directive points to the header file generated by `uniffi-bindgen generate` above— `$(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE)-Bridging-Header.h`
64
+
The `#import` directive points to the header file generated by `uniffi-bindgen generate` above— `$(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE)FFI.h`
58
65
59
66
```h
60
-
#import"todolist-Bridging-Header.h"
67
+
#import"todolistFFI.h"
61
68
```
62
69
63
70
This `IOSApp-Bridging-Header.h` tells Xcode to look for the header file; because it's in `DERIVED_FILE_DIR`, Xcode should know where to look.
64
71
65
72
## Configure `cargo` to build the crate as a static library
66
73
67
-
1.In the `Cargo.toml` file of the Rust project, add `staticlib` to the `crate-type` list.
74
+
1.The build script automatically builds a static library (note: this requires rustc 1.64 or newer)
68
75
69
76
```toml
70
77
[lib]
71
-
crate-type = ["staticlib", "cdylib"]
72
78
name = "uniffi_todolist"
73
79
```
74
80
75
81
The `package``name` and the `lib``name` will be used below. In this case, the package name is `uniffi-example-todolist` and the lib name is `uniffi_todolist`.
76
82
77
83
## Tell Xcode how to build the Rust project.
78
84
79
-
#### TODO use a better explanation of what is going on here
80
-
81
85
1. In Xcode, click on the project in the Project Navigator.
82
86
2. In the main window, select the app's main target, and then select "Build Phases".
83
87
3. Add a new `Run Script` build phase and move it to the top.
84
88
4. Add the script that will build a universal binary for the Rust project.
85
89
86
-
For this project, we've used a script adapted from the #mozilla/application-services project to build a universal binary with `lipo`.
90
+
`uniffi` comes with a script suitable to build a static library for all iOS targets:
*`STATIC_LIB_NAME` from the `lib``name` above: `uniffi_todolist` -->`libuniffi_todolist.a`
101
104
*`FFI_TARGET` from the `package``name` above: `uniffi-example-todolist`.
102
105
103
106
The workspace path is where the `Cargo.toml` will resolve the Rust project, and also determine the target directory that `cargo build` and `lipo` will put its artifacts.
104
107
105
-
This script performs a few steps:
106
-
107
-
1. Runs `cargo build` to compile the Rust project for the `x86_64-apple-ios` and `aarch64-apple-ios` targets.
108
-
* This includes using `uniffi-bindgen` to generate the Rust scaffolding so we can go from C to Rust.
109
-
2. Runs `lipo` to combine these libs in to a universal binary.
110
-
3. Puts the universal binary in to the `$WORKSPACE_PATH/target/universal` directory.
108
+
This script runs `cargo build` to compile the Rust project for the `x86_64-apple-ios`, `aarch64-apple-ios` and `aarch64-apple-ios-sim` targets.
109
+
This includes using `uniffi-bindgen` to generate the Rust scaffolding so we can go from C to Rust.
111
110
112
111
## Tell Xcode where the universal library is
113
112
114
-
Finally, we need to tell Xcode to look for the universal binary `libuniffi_todolist.a` is, so it can tie it together with the header file `todolist-Bridging-Header.h`.
113
+
Finally, we need to tell Xcode to look for the libraries based on the target, so it can tie it together with the header file `todolistFFI.h`.
115
114
116
115
1. In Xcode, click on the project in the Project Navigator.
117
116
2. In the main window, selectthe app's main target, and then select "Build Settings".
118
117
3. Search for `Library Search Paths`.
119
-
4. Add paths to where lipo constructed the universal binaries for each of `Debug` and `Release`.
118
+
4. Add paths per OS and architecture.
119
+
The OS specific part can be configured in the Xcode project editor,
120
+
but the architecture specific part has to be added by manually editing the `project.pbxproj` file.
121
+
Open `project.pbxproj` in your project direcotry and add the following in the `Debug` section:
0 commit comments