Skip to content

Commit

Permalink
fix: remove ios builds
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberb committed Sep 19, 2024
1 parent 9e3b0db commit a085e47
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 53 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/build-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
- name: Build Dependencies
env:
NSS_DIR: ${{ github.workspace }}/libs/ios/arm64/nss
NSS_DIR: ${{ github.workspace }}/libs/desktop/darwin-aarch64/nss
NSS_STATIC: 1
run: |
# Install virtual environment and setuptools + six
Expand All @@ -94,18 +94,14 @@ jobs:
# Install the required dependencies on macOS (replace tcl with tcl-tk)
brew install ninja zlib tcl-tk python
# Ensure the environment for iOS is correctly set up
# NSS for iOS hast be setup for building app-services
./libs/verify-ios-environment.sh
# Ensure the environment for desktop is correctly set up
# NSS for desktop has to be setup to build megazord
./libs/verify-desktop-environment.sh
- name: Build Swift docs
env:
NSS_DIR: ${{ github.workspace }}/libs/ios/arm64/nss
NSS_DIR: ${{ github.workspace }}/libs/desktop/darwin-aarch64/nss
NSS_STATIC: 1
run: |
cd ./automation/swift-components-docs
Expand Down
82 changes: 35 additions & 47 deletions automation/swift-components-docs/generate-swift-project.sh
Original file line number Diff line number Diff line change
@@ -1,66 +1,54 @@
#!/usr/bin/env bash
#
# This script builds the Rust crate in its directory and generates Swift bindings, headers, and a module map using UniFFI in library mode.
# This script builds the Rust crate in its directory and generates Swift bindings,
# headers, and a module map using UniFFI in library mode.

FRAMEWORK_NAME="SwiftComponents"
set -euo pipefail # Ensure script exits on errors or unset variables

FRAMEWORK_NAME="SwiftComponents"
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
REPO_ROOT="$( dirname "$( dirname "$THIS_DIR" )" )"
WORKING_DIR=$THIS_DIR

MANIFEST_PATH="$WORKING_DIR/Cargo.toml"

if [[ ! -f "$MANIFEST_PATH" ]]; then
echo "Could not locate Cargo.toml in $MANIFEST_PATH"
exit 1
fi

CRATE_NAME=$(grep --max-count=1 '^name =' "$MANIFEST_PATH" | cut -d '"' -f 2)
if [[ -z "$CRATE_NAME" ]]; then
echo "Could not determine crate name from $MANIFEST_PATH"
exit 1
fi

# Helper to run the cargo build command in a controlled environment.
# It's important that we don't let environment variables from the user's default
# desktop build environment leak into the iOS build, otherwise it might e.g.
# link against the desktop build of NSS.

WORKING_DIR="$THIS_DIR"
CARGO="$HOME/.cargo/bin/cargo"
LIBS_DIR="$REPO_ROOT/libs"

setup_env () {
LIBS_DIR="$REPO_ROOT/libs/ios/arm64"

env -i \
NSS_STATIC=1 \
NSS_DIR="$LIBS_DIR/nss" \
PATH="${PATH}"
}

set -euvx

setup_env

# Create directories for Swift files, headers, and module map
INCLUDE_DIR="$WORKING_DIR/Sources/$FRAMEWORK_NAME/include"
SWIFT_DIR="$WORKING_DIR/Sources/$FRAMEWORK_NAME"

mkdir -p "$INCLUDE_DIR"

# Generate Swift bindings, headers, and module map using uniffi-bindgen in library mode
cargo build -p megazord --release
# Build the Rust crate using Cargo
echo "Building the Rust crate..."
$CARGO build -p megazord --release

# Define the path to the generated Rust library
LIBRARY_FILE="$REPO_ROOT/target/release/libmegazord.dylib"
$CARGO uniffi-bindgen generate --library "$LIBRARY_FILE" --language swift --out-dir "$SWIFT_DIR"
if [[ ! -f "$LIBRARY_FILE" ]]; then
echo "Error: Rust library not found at $LIBRARY_FILE"
exit 1
fi

# Generate Swift bindings, headers, and module map using uniffi-bindgen
echo "Generating Swift bindings with uniffi-bindgen..."
$CARGO uniffi-bindgen generate --library "$LIBRARY_FILE" --language swift --out-dir "$SWIFT_DIR"

# Move header files to the include directory
mv "$SWIFT_DIR"/*.h "$INCLUDE_DIR"
# Move generated header files to the include directory
echo "Moving header files to include directory..."
mv "$SWIFT_DIR"/*.h "$INCLUDE_DIR" || {
echo "Error: Failed to move header files."
exit 1
}

## Remove any component modulemaps
rm -rf "$WORKING_DIR"/Sources/"$FRAMEWORK_NAME"/*.modulemap
# Remove any old modulemaps
echo "Cleaning up old module maps..."
rm -f "$SWIFT_DIR"/*.modulemap

echo "Generate the modulemap"
./generate-modulemap.sh
# Generate a new module map
echo "Generating module map..."
if [[ ! -f "$WORKING_DIR/generate-modulemap.sh" ]]; then
echo "Error: generate-modulemap.sh script not found."
exit 1
fi
"$WORKING_DIR/generate-modulemap.sh"

echo "Successfully generated Swift bindings, headers, and module map."
# Success message
echo "Successfully generated Swift bindings, headers, and module map."

0 comments on commit a085e47

Please sign in to comment.