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

feat: initial mobile support #924

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions .github/fixtures/example-with-tauri-v2/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ license = ""
repository = ""
edition = "2021"

[lib]
name = "test_app_lib"
crate-type = ["lib", "cdylib", "staticlib"]

[dependencies]
serde_json = "1"
serde = { version = "1", features = ["derive"] }
tauri = { version = "2.0.0-beta", features = [] }
tauri = { version = "2.0.0-rc", features = [] }

[build-dependencies]
tauri-build = { version = "2.0.0-beta", features = [] }
tauri-build = { version = "2.0.0-rc", features = [] }

[features]
prod = ["tauri/custom-protocol"]
Expand Down
7 changes: 7 additions & 0 deletions .github/fixtures/example-with-tauri-v2/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
5 changes: 2 additions & 3 deletions .github/fixtures/example-with-tauri-v2/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

fn main() {
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("error while running tauri application");
test_app_lib::run()
}
57 changes: 56 additions & 1 deletion .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,21 @@ jobs:
fail-fast: false
matrix:
include:
# desktop
- platform: 'macos-latest'
args: '--verbose --target universal-apple-darwin'
- platform: 'ubuntu-22.04'
args: '--verbose'
- platform: 'windows-latest'
args: '--verbose'
# mobile
- platform: 'ubuntu-latest'
args: '--verbose'
android: true
# TODO: Test iOS builds
#- platform: 'macos-latest'
# args: '--verbose --debug'
# ios: true

runs-on: ${{ matrix.platform }}
steps:
Expand Down Expand Up @@ -141,7 +150,7 @@ jobs:
- name: install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-apple-darwin,x86_64-apple-darwin
targets: aarch64-apple-darwin,x86_64-apple-darwin,aarch64-linux-android,armv7-linux-androideabi,i686-linux-android,x86_64-linux-android,aarch64-apple-ios

- uses: Swatinem/rust-cache@v2
with:
Expand All @@ -157,9 +166,53 @@ jobs:
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev

- name: Setup Java
if: matrix.android
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'

- name: Setup Android SDK
if: matrix.android
uses: android-actions/setup-android@v3
- name: Setup Android NDK
if: matrix.android
uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r26d
link-to-sdk: true

- name: setup xcode
uses: maxim-lobanov/setup-xcode@v1
if: matrix.ios
with:
xcode-version: latest-stable

- name: init android
if: matrix.android
env:
NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
run: |
cd ./.github/fixtures/example-with-tauri-v2
pnpm add -D @tauri-apps/cli
pnpm tauri android init

- name: init ios
if: matrix.ios
env:
APPLE_DEVELOPMENT_TEAM: 12345
run: |
cd ./.github/fixtures/example-with-tauri-v2
pnpm add -D @tauri-apps/cli
pnpm tauri ios init

- name: Preconfigured Tauri Project
uses: ./
env:
NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
APPLE_DEVELOPMENT_TEAM: 12345
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Updater signature is exposed here to make sure it works in PR's
TAURI_SIGNING_PRIVATE_KEY: dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5YTBGV3JiTy9lRDZVd3NkL0RoQ1htZmExNDd3RmJaNmRMT1ZGVjczWTBKZ0FBQkFBQUFBQUFBQUFBQUlBQUFBQWdMekUzVkE4K0tWQ1hjeGt1Vkx2QnRUR3pzQjVuV0ZpM2czWXNkRm9hVUxrVnB6TUN3K1NheHJMREhQbUVWVFZRK3NIL1VsMDBHNW5ET1EzQno0UStSb21nRW4vZlpTaXIwZFh5ZmRlL1lSN0dKcHdyOUVPclVvdzFhVkxDVnZrbHM2T1o4Tk1NWEU9Cg==
Expand All @@ -171,11 +224,13 @@ jobs:
releaseName: 'Release example with preconfigured Tauri app v__VERSION__ for tauri-v2'
releaseBody: 'See the assets to download this version and install.'
releaseDraft: true
mobile: ${{ matrix.android || matrix.ios }}
args: ${{ matrix.args }}
updaterJsonKeepUniversal: true

- name: Frontend-only Project
uses: ./
if: ${{ !(matrix.android || matrix.ios) }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Updater signature is exposed here to make sure it works in PR's
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,18 @@ These inputs are only used if your GitHub repository does not contain an existin

These inputs allow you to change how your Tauri project will be build.

| Name | Required | Description | Type | Default |
| -------------------------- | :------: | -------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------------------------------------------------------------------------------ |
| `projectPath` | false | The path to the root of the tauri project relative to the current working directory | string | . |
| `includeDebug` | false | whether to include a debug build or not | bool | false |
| `includeRelease` | false | whether to include a release build or not | bool | true |
| `includeUpdaterJson` | false | whether to upload a JSON file for the updater or not (only relevant if the updater is configured) | bool | true |
| `updaterJsonPreferNsis` | false | whether the action will use the NSIS (setup.exe) or WiX (.msi) bundles for the updater JSON if both types exist | bool | `false`. May be changed to `true` for projects using `tauri@v2` in the future. |
| `updaterJsonKeepUniversal` | false | whether the updater JSON file should include universal macOS builds as darwin-universal on top of using it in the aarch64 and x86_64 fields. | bool | false |
| `tauriScript` | false | the script to execute the Tauri CLI. It must not include any args or commands like `build` | string | `npm run\|pnpm\|yarn tauri` |
| `args` | false | Additional arguments to the current build command | string | |
| Name | Required | Description | Type | Default |
| -------------------------- | :------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ------------------------------------------------------------------------------ |
| `projectPath` | false | The path to the root of the tauri project relative to the current working directory | string | . |
| `includeDebug` | false | whether to include a debug build or not | bool | false |
| `includeRelease` | false | whether to include a release build or not | bool | true |
| `mobile` | false | Toggle between desktop and mobile builds, use includeDebug and includeRelease to switch between release and debug builds. Set it to `true` to enable iOS builds on macOS runners and Android builds on Ubuntu runners. Set it to `android` to enable Android builds on all runners. `ios` behaves the same as `true` and only works on macOS runners. Note that this setting, especially for iOS, is currently considered unstable! | bool / string | false |
| `includeIOS` | false | whether to include an iOS release build or not. macOS only (will be ignored on Linux/Windows). | bool | false |
| `includeUpdaterJson` | false | whether to upload a JSON file for the updater or not (only relevant if the updater is configured) | bool | true |
| `updaterJsonPreferNsis` | false | whether the action will use the NSIS (setup.exe) or WiX (.msi) bundles for the updater JSON if both types exist | bool | `false`. May be changed to `true` for projects using `tauri@v2` in the future. |
| `updaterJsonKeepUniversal` | false | whether the updater JSON file should include universal macOS builds as darwin-universal on top of using it in the aarch64 and x86_64 fields. | bool | false |
| `tauriScript` | false | the script to execute the Tauri CLI. It must not include any args or commands like `build` | string | `npm run\|pnpm\|yarn tauri` |
| `args` | false | Additional arguments to the current build command | string | |

### Release Configuration

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ inputs:
includeRelease:
description: 'whether to include a release build or not'
default: true
mobile:
description: 'Toggle between desktop and mobile builds, use includeDebug and includeRelease to switch between release and debug builds. Set it to `true` to enable iOS builds on macOS runners and Android builds on Ubuntu runners. Set it to `android` to enable Android builds on all runners. `ios` behaves the same as `true` and only works on macOS runners. Note that this setting, especially for iOS, is currently considered unstable!'
default: false
includeUpdaterJson:
description: 'whether to upload a static JSON file for the updater using GitHub Releases as the CDN'
default: true
Expand Down
20 changes: 10 additions & 10 deletions dist/index.js

Large diffs are not rendered by default.

File renamed without changes.
99 changes: 99 additions & 0 deletions src/build-mobile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { existsSync } from 'node:fs';
import { join } from 'node:path';

import { getRunner } from './runner';
import { getInfo } from './utils';

import type { Artifact, BuildOptions } from './types';

export async function buildProject(
root: string,
android: boolean,
debug: boolean,
buildOpts: BuildOptions,
): Promise<Artifact[]> {
const runner = await getRunner(root, buildOpts.tauriScript);

const tauriArgs = debug
? ['--debug', ...(buildOpts.args ?? [])]
: (buildOpts.args ?? []);

const configArgIdx = [...tauriArgs].findIndex(
(e) => e === '-c' || e === '--config',
);
const configArg =
configArgIdx >= 0 ? [...tauriArgs][configArgIdx + 1] : undefined;

const info = getInfo(
root,
{ arch: 'mobile', platform: android ? 'android' : 'ios' },
configArg,
);

if (!info.tauriPath) {
throw Error("Couldn't detect path of tauri app");
}

await runner.execTauriCommand(
[android ? 'android' : 'ios', 'build'],
[...tauriArgs],
root,
);

let artifacts: Artifact[] = [];

if (android) {
const artifactPaths = join(
info.tauriPath,
'gen/android/app/build/outputs/',
);
artifacts = [
// unsinged release apks
join(artifactPaths, 'apk/universal/release/app-universal-unsigned.apk'),
join(artifactPaths, 'apk/arm64/release/app-arm64-unsigned.apk'),
join(artifactPaths, 'apk/arm/release/app-arm-unsigned.apk'),
join(artifactPaths, 'apk/x86_64/release/app-x86_64-unsigned.apk'),
join(artifactPaths, 'apk/x86/release/app-x86-unsigned.apk'),
// signed release apks
join(artifactPaths, 'apk/universal/release/app-universal-release.apk'),
join(artifactPaths, 'apk/arm64/release/app-arm64-release.apk'),
join(artifactPaths, 'apk/arm/release/app-arm-release.apk'),
join(artifactPaths, 'apk/x86_64/release/app-x86_64-release.apk'),
join(artifactPaths, 'apk/x86/release/app-x86-release.apk'),
// release aabs
join(artifactPaths, 'bundle/universalRelease/app-universal-release.aab'),
join(artifactPaths, 'bundle/arm64Release/app-arm64-release.aab'),
join(artifactPaths, 'bundle/armRelease/app-arm-release.aab'),
join(artifactPaths, 'bundle/x86_64Release/app-x86_64-release.aab'),
join(artifactPaths, 'bundle/x86Release/app-x86-release.aab'),
// debug apks
join(artifactPaths, 'apk/universal/debug/app-universal-debug.apk'),
join(artifactPaths, 'apk/arm64/debug/app-arm64-debug.apk'),
join(artifactPaths, 'apk/arm/debug/app-arm-debug.apk'),
join(artifactPaths, 'apk/x86_64/debug/app-x86_64-debug.apk'),
join(artifactPaths, 'apk/x86/debug/app-x86-debug.apk'),
// debug aabs
join(artifactPaths, 'bundle/universalDebug/app-universal-debug.aab'),
join(artifactPaths, 'bundle/arm64Debug/app-arm64-debug.aab'),
join(artifactPaths, 'bundle/armDebug/app-arm-debug.aab'),
join(artifactPaths, 'bundle/x86_64Debug/app-x86_64-debug.aab'),
join(artifactPaths, 'bundle/x86Debug/app-x86-debug.aab'),
].map((path) => ({ path, arch: 'mobile' }));
} else {
const artifactPaths = join(info.tauriPath, 'gen/apple/app/build/');
// TODO: Confirm where the iOS project name actually comes from. it may be time for a glob pattern here to get the ipa without knowing the name.
artifacts = [
join(artifactPaths, `arm64/${info.name}.ipa`),
join(artifactPaths, `arm64-sim/${info.name}.ipa`),
join(artifactPaths, `/x86_64/${info.name}.ipa`),
].map((path) => ({
path,
arch: 'mobile',
}));
}

console.log(
`Looking for artifacts in:\n${artifacts.map((a) => a.path).join('\n')}`,
);
return artifacts.filter((p) => existsSync(p.path));
}
Loading