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

fix: use library mode for kotlin docs #6391

Merged
merged 1 commit into from
Sep 23, 2024
Merged
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
27 changes: 27 additions & 0 deletions .github/workflows/build-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,34 @@ jobs:
toolchain: stable
override: true

- name: Build Dependencies
env:
NSS_DIR: ${{ github.workspace }}/libs/desktop/linux-x86-64/nss
NSS_STATIC: 1
run: |
sudo apt-get update
sudo apt-get install -y libclang-dev tcl ninja-build

python3 -m venv venv
source venv/bin/activate
python3 -m pip install --upgrade pip setuptools six

# Clone the gyp repository
git clone https://chromium.googlesource.com/external/gyp.git tools/gyp

# Navigate to gyp directory and install it
cd tools/gyp
python3 setup.py install
cd ../..

# 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 Kotlin docs
env:
NSS_DIR: ${{ github.workspace }}/libs/desktop/linux-x86-64/nss
NSS_STATIC: 1
run: |
cd ./automation/kotlin-components-docs
chmod +x ./generate_docs.sh
Expand Down
42 changes: 21 additions & 21 deletions automation/kotlin-components-docs/generate_docs.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#!/usr/bin/env bash

# This script builds the Rust crate in its directory and generates Kotlin bindings,
# using UniFFI in library mode.

# Ensure script exits on errors or unset variables
set -euo pipefail

THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
REPO_ROOT="$( dirname "$( dirname "$THIS_DIR" )" )"
WORKING_DIR=$THIS_DIR
echo "Project root directory: $REPO_ROOT"
CARGO="$HOME/.cargo/bin/cargo"

# Set the documentation directory
KOTLIN_DIR="$WORKING_DIR/src/main/kotlin"

# Generate Kotlin bindings using uniffi-bindgen
CARGO=${CARGO:-cargo} # Use the provided CARGO or fallback to cargo

$CARGO uniffi-bindgen generate "$REPO_ROOT/components/remote_settings/src/remote_settings.udl" -l kotlin -o "$KOTLIN_DIR"
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/nimbus/src/nimbus.udl" -l kotlin -o "$KOTLIN_DIR"
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/support/error/src/errorsupport.udl" -l kotlin -o "$KOTLIN_DIR"
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/support/rust-log-forwarder/src/rust_log_forwarder.udl" -l kotlin -o "$KOTLIN_DIR"

# Repeat for other components
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/crashtest/src/crashtest.udl" -l kotlin -o "$KOTLIN_DIR"
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/fxa-client/src/fxa_client.udl" -l kotlin -o "$KOTLIN_DIR"
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/logins/src/logins.udl" -l kotlin -o "$KOTLIN_DIR"
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/autofill/src/autofill.udl" -l kotlin -o "$KOTLIN_DIR"
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/push/src/push.udl" -l kotlin -o "$KOTLIN_DIR"
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/tabs/src/tabs.udl" -l kotlin -o "$KOTLIN_DIR"
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/places/src/places.udl" -l kotlin -o "$KOTLIN_DIR"
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/suggest/src/suggest.udl" -l kotlin -o "$KOTLIN_DIR"
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/sync_manager/src/syncmanager.udl" -l kotlin -o "$KOTLIN_DIR"
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/sync15/src/sync15.udl" -l kotlin -o "$KOTLIN_DIR"
$CARGO uniffi-bindgen generate "$REPO_ROOT/components/as-ohttp-client/src/as_ohttp_client.udl" -l kotlin -o "$KOTLIN_DIR"
# 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.so"
if [[ ! -f "$LIBRARY_FILE" ]]; then
echo "Error: Rust library not found at $LIBRARY_FILE"
exit 1
fi

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

# Generate documentation with increased memory
(cd "$WORKING_DIR" && "$REPO_ROOT/gradlew" --max-workers=2 dokkaHtml -Dorg.gradle.vfs.watch=false)
Expand Down
9 changes: 5 additions & 4 deletions automation/swift-components-docs/generate-swift-project.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/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.

set -euo pipefail # Ensure script exits on errors or unset variables
# Ensure script exits on errors or unset variables
set -euo pipefail

gruberb marked this conversation as resolved.
Show resolved Hide resolved
FRAMEWORK_NAME="SwiftComponents"
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
Expand All @@ -18,10 +19,10 @@ mkdir -p "$INCLUDE_DIR"

# Build the Rust crate using Cargo
echo "Building the Rust crate..."
$CARGO build -p megazord --release
$CARGO build -p megazord_ios --release

# Define the path to the generated Rust library
LIBRARY_FILE="$REPO_ROOT/target/release/libmegazord.dylib"
LIBRARY_FILE="$REPO_ROOT/target/release/libmegazord_ios.a"
if [[ ! -f "$LIBRARY_FILE" ]]; then
echo "Error: Rust library not found at $LIBRARY_FILE"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
- [Releases](howtos/releases.md)
- [CI Publishing tools and flow](build-and-publish-pipeline.md)
- [How to upgrade NSS](howtos/upgrading-nss-guide.md)
- Rustdocs for components
- [Rustdocs for components](rust-docs/index.html)
- [as_ohttp_client](rust-docs/as_ohttp_client/index.html)
- [autofill](rust-docs/autofill/index.html)
- [crashtest](rust-docs/crashtest/index.html)
Expand Down