Skip to content

Remove xcodeproj [ci full] #6715

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ testing/sync-test/Cargo.lock
# XCFramework artifact
megazords/ios-rust/MozillaRustComponents.xcframework*
megazords/ios-rust/focus/FocusRustComponents.xcframework*
megazords/ios-rust/include*
megazords/ios-rust/.build*
megazords/ios-rust/sources/MozillaRustComponentsWrapper/generated*


# Glean generated artifacts
Expand All @@ -52,7 +55,6 @@ MozillaAppServices.framework.zip
# Xcode generated logs
raw_xcodebuild.log
raw_xcodetest.log

# Generated debug symbols
crashreporter-symbols*
automation/symbols-generation/bin/
Expand Down
19 changes: 10 additions & 9 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
included: # paths to include during linting. `--path` is ignored if present.
- megazords
- components/places/ios
- components/support/ios
- components/logins/ios
- components/fxa-client/ios
- components/nimbus/ios
- "megazords/ios-rust/Sources"

excluded:
# We no longer use carthage. However, some developers might still
# have the Carthage directory in their local environment. It will
# create linting noise if we don't exclude it.
- Carthage
- "**/*/ios/Generated"
- "megazords/ios/MozillaAppServicesTests"
- "megazords/ios-rust/MozillaTestServices/MozillaTestServicesTests"
- "megazords/ios-rust/MozillaTestServices/MozillaTestServices/Generated"
- "megazords/ios-rust/tests"
- "megazords/ios-rust/Sources/MozillaRustComponentsWrapper/Generated"
# Sync manager wasn't added to the swiftlint checks before and didn't want to
# break APIs during the xcodeproj migration, so ignoring for now but we should
# eventually fix
- "megazords/ios-rust/Sources/MozillaRustComponentsWrapper/SyncManager"

disabled_rules:
- file_length
Expand All @@ -38,3 +37,5 @@ identifier_name:
min_length:
warning: 0
error: 0
# Turn off complaining about having _ in variable names
allowed_symbols: "_"
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 65 additions & 8 deletions automation/run_ios_tests.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,71 @@
#!/usr/bin/env bash

set -euvx
set -eu

./megazords/ios-rust/build-xcframework.sh --build-profile release
set -o pipefail && \
# XCFramework is a slow process rebuilding all the binaries and zipping it
# so we add an option to skip that if we're just trying to change tests
SKIP_BUILDING=false

# Parse command-line arguments
for arg in "$@"; do
case $arg in
--test-only)
SKIP_BUILDING=true
shift
;;
*)
echo "Unknown option: $arg" >&2
exit 1
;;
esac
done


SOURCE_ROOT=$(pwd)
export SOURCE_ROOT
export PROJECT=MozillaRustComponentsWrapper

# Conditionally generate the UniFFi bindings with rust binaries and bundle it into an XCFramework
if [ "$SKIP_BUILDING" != true ]; then

# Glean deletes everything in the folder it outputs, so we keep them in their own dir
./components/external/glean/glean-core/ios/sdk_generator.sh \
-g Glean \
-o ./megazords/ios-rust/Sources/MozillaRustComponentsWrapper/Generated/Glean \
"${SOURCE_ROOT}"/components/nimbus/metrics.yaml \
"${SOURCE_ROOT}"/components/sync_manager/metrics.yaml \
"${SOURCE_ROOT}"/components/sync_manager/pings.yaml

# Build the XCFramework
./megazords/ios-rust/build-xcframework.sh --build-profile release
else
echo "Skipping xcframework & glean metrics generation as --test-only was passed."
fi

# xcodebuild needs to run in the directory we have it since
# we are using SPM instead of an Xcode project
pushd megazords/ios-rust > /dev/null

# Temporarily disable "exit immediately" so we can capture the exit code from the pipeline
set +e
set -o pipefail
xcodebuild \
-workspace megazords/ios-rust/MozillaTestServices/MozillaTestServices.xcodeproj/project.xcworkspace \
-scheme MozillaTestServices \
-scheme MozillaRustComponents \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 15' \
test | \
tee raw_xcodetest.log | \
xcpretty && exit "${PIPESTATUS[0]}"
test | tee raw_xcodetest.log | xcpretty
result=${PIPESTATUS[0]}
set -e

# Return to the original directory
popd > /dev/null

# Provide clear messaging based on test results
if [ "$result" -eq 0 ]; then
echo "✅ Swift tests pass!"
else
echo "❌ Swift tests failed!"
fi


exit "${result}"
3 changes: 1 addition & 2 deletions automation/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,10 @@ def cargo_fmt(package=None, fix_issues=False):
def swift_format():
swift_format_args = [
"megazords",
"components/*/ios",
"--exclude",
"**/Generated",
"--exclude",
"components/nimbus/ios/Nimbus/Utils",
"megazords/ios-rust/Sources/MozillaRustComponentsWrapper/Nimbus/Utils",
"--lint",
"--swiftversion",
"5",
Expand Down
110 changes: 0 additions & 110 deletions components/as-ohttp-client/ios/ASOhttpClient/OhttpManager.swift

This file was deleted.

5 changes: 1 addition & 4 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ Configure maven to use the native windows maven repository - then, when doing `.
1. Run `./libs/verify-ios-environment.sh` to check your setup and environment
variables.
1. Make any corrections recommended by the script and re-run.
2. Next, run `./megazords/ios-rust/build-xcframework.sh` to build all the binaries needed to consume a-s in iOS

Once the script passes, you should be able to run the Xcode project.
> Note: The built Xcode project is located at `megazords/ios-rust/MozillaTestServices.xcodeproj`.
Next, run `./automation/run_ios_tests.sh` to build all the binaries and run tests using the local SPM setup.

> Note: This is mainly for testing the rust components, the artifact generated in the above steps should be all you need for building application with application-services

Expand Down
70 changes: 29 additions & 41 deletions docs/howtos/adding-a-new-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,68 +99,56 @@ You will end up with a directory structure something like this:
* `uniffi.toml`
* `src/`
* Rust code here.
* `ios/`
* `Generated/`
* Generated Swift code will be written into this directory.

### Adding your component to the Swift Package Manager Megazord

> *For more information on our how we ship components using the Swift Package Manager, check the [ADR that introduced the Swift Package Manager](../adr/0003-swift-packaging.md)*

Add your component into the iOS ["megazord"](../design/megazords.md) through the Xcode project, which can only really by done using the Xcode application, which can only really be done if you're on a Mac.
Add your component into the iOS ["megazord"](../design/megazords.md) through the local Swift Package Manager (SPM) package `MozillaRustComponentsWrapper`. Note this SPM is for easy of local testing of APIs locally. The official SPM that is consumed by firefox-ios is [rust-components-swift](https://github.com/mozilla/rust-components-swift?tab=readme-ov-file).

1. Open `megazords/ios-rust/MozillaTestServices/MozillaTestServices.xcodeproj` in Xcode.
1. Place any hand-written Swift wrapper code for your component in:
```
megazords/ios-rust/sources/MozillaRustComponentsWrapper/<your_crate_name>/
```

1. In the Project navigator, add a new Group for your new component, pointing to
the `./ios/` directory you created above. Add the following entries to the Group:
* Any hand-written `.swift `files for your component
2. Place your Swift test code in:
```
megazords/ios-rust/tests/MozillaRustComponentsWrapper/
```

> Make sure that the "Copy items if needed" option is **unchecked**, and that
nothing is checked in the "Add to targets" list.
That's it! At this point, if you don't intend on writing tests _(are you sure?)_ you can skip this next section.

The result should look something like this:
### Writing and Running Tests

![Screenshot of Xcode Project Navigator](./img/xcode_add_component_1.png)
The current system combines all rust crates into one binary (megazord). To use your rust APIs simply
import the local SPM into your tests:

Click on the top-level "MozillaTestServices" project in the navigator, then go to "Build Phases".

Finally, in the Project navigator, add a sub-group named "Generated", pointing to the `./Generated/` subdirectory, and
containing entries for the files generated by UniFFI:
* `<your_crate_name>.swift`
* `<your_crate_name>FFI.h`
Make sure that "Copy items if needed" is unchecked, and that nothing is checked in "Add to targets".

> Double-check that `<your_crate_name>.swift` does **not** appear in the "Compile Sources" section.

The result should look something like this:

![Screenshot of Xcode Compile Sources list](./img/xcode_add_component_2.png)
```swift
@testable import MozillaRustComponentsWrapper
```

Build the project in Xcode to check whether that all worked correctly.
To test your component:

To add Swift tests for your component API, create them in a file under
`megazords/ios-rust/MozillaTestServicesTests/`. Use this syntax to import
your component's bindings from the compiled megazord:
- Run the script:

```
@testable import MozillaTestServices
./automation/run_ios_tests.sh
```

In Xcode, navigate to the `MozillaTestServicesTests` Group and add your
new test file as an entry. Select the corresponding target, click on
"Build Phases", and add your test file to the list of "Compile Sources".
The result should look something like this:
The script will:
1. Build the XCFramework (combines all rust binaries for SPM)
2. Generate UniFFi bindings (artifacts can be found in `megazords/ios-rust/sources/MozillaRustComponentsWrapper/Generated/`)
3. Generate Glean metrics
4. Run any tests found in the test dir mentioned above

![Screenshot of Xcode Test Setup](./img/xcode_add_component_4.png)
TODO: Update this section??

Use the Xcode Test Navigator to run your tests and check whether
they're passing.
To ensure distribution of this code, edit `taskcluster/scripts/build-and-test-swift.py`:

- Add your component's directory path to `SOURCE_TO_COPY`
- Optionally, add the path to `FOCUS_SOURCE_TO_COPY` if your component targets Firefox Focus.

### Hand-written code

You can include hand-written Swift code alongside the automatically
generated bindings, by placing `.swift` files in a directory named:
`./ios/<your_crate_name>/`.

Make sure that this code gets distributed. Edit `taskcluster/scripts/build-and-test-swift.py` and:

Expand Down
12 changes: 5 additions & 7 deletions libs/verify-ios-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ fi
"$(pwd)/libs/verify-ios-ci-environment.sh"

echo ""
echo "Looks good! Next steps:"
echo "- Build the XCFramework:"
echo " ./megazords/ios-rust/build-xcframework.sh"
echo ""
echo " Then you'll be able do one of the following: "
echo "- Run the tests via the XCode project:"
echo " open megazords/ios-rust/MozillaTestServices.xcodeproj"
echo "Looks good! You can either:"
echo ""
echo "- Run the iOS tests via command line:"
echo " ./automation/run_ios_tests.sh"
echo ""
echo " If you want to just generate the rust binaries"
echo "- Build the XCFramework:"
echo " ./megazords/ios-rust/build-xcframework.sh"
Loading
Loading