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

Draft
wants to merge 5 commits into
base: dev
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
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()
}
34 changes: 32 additions & 2 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ jobs:
args: '--verbose'
- platform: 'windows-latest'
args: '--verbose'
- platform: 'macos-latest'
args: '--verbose --debug'
mobile: true

runs-on: ${{ matrix.platform }}
steps:
Expand Down Expand Up @@ -141,7 +144,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,20 +160,47 @@ jobs:
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev

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

- name: Setup Android SDK
if: matrix.mobile
uses: android-actions/setup-android@v3

- name: Install NDK
if: matrix.mobile
run: sdkmanager "ndk;27.0.11902837"

- name: init mobile
if: matrix.mobile
env:
NDK_HOME: ${{ env.ANDROID_HOME }}/ndk/27.0.11902837
run: |
cd ./.github/fixtures/example-with-tauri-v2
pnpm tauri android init
pnpm tauri ios init

- name: Preconfigured Tauri Project
uses: ./
env:
NDK_HOME: ${{ env.ANDROID_HOME }}/ndk/27.0.11902837
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Updater signature is exposed here to make sure it works in PR's
TAURI_SIGNING_PRIVATE_KEY: dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5YTBGV3JiTy9lRDZVd3NkL0RoQ1htZmExNDd3RmJaNmRMT1ZGVjczWTBKZ0FBQkFBQUFBQUFBQUFBQUlBQUFBQWdMekUzVkE4K0tWQ1hjeGt1Vkx2QnRUR3pzQjVuV0ZpM2czWXNkRm9hVUxrVnB6TUN3K1NheHJMREhQbUVWVFZRK3NIL1VsMDBHNW5ET1EzQno0UStSb21nRW4vZlpTaXIwZFh5ZmRlL1lSN0dKcHdyOUVPclVvdzFhVkxDVnZrbHM2T1o4Tk1NWEU9Cg==
with:
projectPath: ./.github/fixtures/example-with-tauri-v2
includeDebug: true
includeDebug: ${{ !matrix.mobile }}
includeRelease: false
tagName: ${{ !github.event.pull_request.head.repo.fork && 'example-with-tauri-v__VERSION__' || '' }}
releaseName: 'Release example with preconfigured Tauri app v__VERSION__ for tauri-v2'
releaseBody: 'See the assets to download this version and install.'
releaseDraft: true
includeAndroid: ${{ matrix.mobile || false }}
includeIOS: ${{ matrix.mobile || false }}
args: ${{ matrix.args }}

- name: Frontend-only Project
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ inputs:
includeRelease:
description: 'whether to include a release build or not'
default: true
includeIOS:
description: 'whether to include an iOS build. Ignored on Linux/Windows runners.'
default: false
includeAndroid:
description: 'whether to include an Android build.'
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.
92 changes: 92 additions & 0 deletions src/build-mobile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
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,
buildOpts: BuildOptions,
): Promise<Artifact[]> {
const runner = await getRunner(root, buildOpts.tauriScript);

const tauriArgs = 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/arm64/');
// 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, `${info.cargoName}.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));
}
24 changes: 20 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import stringArgv from 'string-argv';
import { createRelease } from './create-release';
import { uploadAssets as uploadReleaseAssets } from './upload-release-assets';
import { uploadVersionJSON } from './upload-version-json';
import { buildProject } from './build';
import { buildProject as buildDesktop } from './build-desktop';
import { buildProject as buildMobile } from './build-mobile';
import { execCommand, getInfo, getTargetInfo } from './utils';

import type { Artifact, BuildOptions, InitOptions } from './types';
Expand All @@ -25,6 +26,8 @@ async function run(): Promise<void> {
const appVersion = core.getInput('appVersion');
const includeRelease = core.getBooleanInput('includeRelease');
const includeDebug = core.getBooleanInput('includeDebug');
const includeAndroid = core.getBooleanInput('includeAndroid');
const includeIOS = core.getBooleanInput('includeIOS');
const includeUpdaterJson = core.getBooleanInput('includeUpdaterJson');
const updaterJsonKeepUniversal = core.getBooleanInput(
'updaterJsonKeepUniversal',
Expand Down Expand Up @@ -84,17 +87,30 @@ async function run(): Promise<void> {

const releaseArtifacts: Artifact[] = [];
const debugArtifacts: Artifact[] = [];
const mobileArtifacts: Artifact[] = [];
if (includeRelease) {
releaseArtifacts.push(
...(await buildProject(projectPath, false, buildOptions, initOptions)),
...(await buildDesktop(projectPath, false, buildOptions, initOptions)),
);
}
if (includeDebug) {
debugArtifacts.push(
...(await buildProject(projectPath, true, buildOptions, initOptions)),
...(await buildDesktop(projectPath, true, buildOptions, initOptions)),
);
}
const artifacts = releaseArtifacts.concat(debugArtifacts);
if (includeAndroid) {
mobileArtifacts.push(
...(await buildMobile(projectPath, true, buildOptions)),
);
}
if (includeIOS) {
mobileArtifacts.push(
...(await buildMobile(projectPath, false, buildOptions)),
);
}
const artifacts = releaseArtifacts
.concat(debugArtifacts)
.concat(mobileArtifacts);

if (artifacts.length === 0) {
if (releaseId || tagName || releaseName) {
Expand Down
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface CargoManifest {

export interface Info {
tauriPath: string | null;
cargoName: string;
name: string;
version: string;
wixLanguage: string | string[] | { [language: string]: unknown };
Expand Down
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,9 @@ export function getInfo(
version = config?.version;
}

const cargoManifest = getCargoManifest(tauriDir);

if (!(name && version)) {
const cargoManifest = getCargoManifest(tauriDir);
name = name ?? cargoManifest.package.name;
version = version ?? cargoManifest.package.version;
}
Expand All @@ -335,6 +336,7 @@ export function getInfo(

return {
tauriPath: tauriDir,
cargoName: cargoManifest.package.name,
name,
version,
wixLanguage,
Expand Down
Loading