diff --git a/dist-ui/Cargo.toml b/dist-ui/Cargo.toml index 821da38..8f1b8f1 100644 --- a/dist-ui/Cargo.toml +++ b/dist-ui/Cargo.toml @@ -5,6 +5,14 @@ edition = "2021" description = "Thin Rust foreign node (egui) driven by Gleam over Erlang distribution (ETF)" license = "MIT" +# Desktop `cargo run` / `cargo build` enable default features (includes the bin). +# Android `cargo apk … --no-default-features` builds only the cdylib; shipping both +# as artifacts makes cargo-apk panic ("Bin is not compatible with Cdylib") *after* +# a successful APK package. +[features] +default = ["desktop"] +desktop = [] + [lib] name = "global_dist_ui" path = "src/lib.rs" @@ -13,6 +21,7 @@ crate-type = ["cdylib", "rlib"] [[bin]] name = "global-dist-ui" path = "src/main.rs" +required-features = ["desktop"] [dependencies] erl_dist = "0.8" diff --git a/scripts/ci-build-apk.sh b/scripts/ci-build-apk.sh index bbdc4ea..8d5ca0d 100755 --- a/scripts/ci-build-apk.sh +++ b/scripts/ci-build-apk.sh @@ -299,21 +299,23 @@ NIX } run_cargo_apk() { - local cmd=(cargo apk build --target x86_64-linux-android --no-default-features) + # --lib: package only the cdylib (android_main). Including the desktop [[bin]] + # makes cargo-apk panic: "Bin is not compatible with Cdylib" after a good APK. + local cmd=(cargo apk build --lib --target x86_64-linux-android --no-default-features) ( cd "$ROOT/dist-ui" export RUST_BACKTRACE="${RUST_BACKTRACE:-1}" export ANDROID_HOME ANDROID_NDK_HOME ANDROID_NDK_ROOT unset ANDROID_SDK_ROOT || true if [[ ${#FHS_RUN[@]} -eq 0 ]]; then - "${cmd[@]}" || true + "${cmd[@]}" elif [[ "${FHS_RUN[1]:-}" == "-c" ]]; then # buildFHSEnv wrapper: fhs -c 'shell command' local quoted quoted=$(printf '%q ' "${cmd[@]}") - "${FHS_RUN[@]}" "export PATH=$(printf %q "$PATH"); export HOME=$(printf %q "$HOME"); export CARGO_HOME=$(printf %q "${CARGO_HOME:-$HOME/.cargo}"); export RUSTUP_HOME=$(printf %q "${RUSTUP_HOME:-$HOME/.rustup}"); export ANDROID_HOME=$(printf %q "$ANDROID_HOME"); export ANDROID_NDK_HOME=$(printf %q "$ANDROID_NDK_HOME"); export ANDROID_NDK_ROOT=$(printf %q "$ANDROID_NDK_ROOT"); unset ANDROID_SDK_ROOT; ${quoted}" || true + "${FHS_RUN[@]}" "export PATH=$(printf %q "$PATH"); export HOME=$(printf %q "$HOME"); export CARGO_HOME=$(printf %q "${CARGO_HOME:-$HOME/.cargo}"); export RUSTUP_HOME=$(printf %q "${RUSTUP_HOME:-$HOME/.rustup}"); export ANDROID_HOME=$(printf %q "$ANDROID_HOME"); export ANDROID_NDK_HOME=$(printf %q "$ANDROID_NDK_HOME"); export ANDROID_NDK_ROOT=$(printf %q "$ANDROID_NDK_ROOT"); unset ANDROID_SDK_ROOT; ${quoted}" else - "${FHS_RUN[@]}" "${cmd[@]}" || true + "${FHS_RUN[@]}" "${cmd[@]}" fi ) } @@ -325,7 +327,7 @@ build() { setup_rust_android preflight_cargo_apk_env ensure_fhs_runner - log "cargo apk build --target x86_64-linux-android --no-default-features" + log "cargo apk build --lib --target x86_64-linux-android --no-default-features" run_cargo_apk [[ -f "$APK" ]] || { log "APK missing: $APK"; exit 1; } local size diff --git a/scripts/global-run.sh b/scripts/global-run.sh index 1e8f4ce..652f9b7 100755 --- a/scripts/global-run.sh +++ b/scripts/global-run.sh @@ -178,16 +178,16 @@ build_apk() { echo "[global] cargo-apk not found; installing…" >&2 cargo install cargo-apk --locked fi - echo "[global] cargo apk build --target x86_64-linux-android --no-default-features" >&2 + echo "[global] cargo apk build --lib --target x86_64-linux-android --no-default-features" >&2 local before after apk apk="$ROOT/$APK_REL" before=0 [[ -f "$apk" ]] && before=$(stat -c %Y "$apk" 2>/dev/null || echo 0) ( cd "$ROOT/dist-ui" - # cargo-apk may panic after packaging (bin+cdylib); APK is often still written. + # --lib: only the cdylib (avoids cargo-apk "Bin is not compatible with Cdylib"). # All cargo/apk chatter → stderr; stdout is only the APK path. - cargo apk build --target x86_64-linux-android --no-default-features >&2 || true + cargo apk build --lib --target x86_64-linux-android --no-default-features >&2 ) [[ -f "$apk" ]] || { echo "[global] APK missing after build: $apk" >&2 diff --git a/scripts/waydroid-dist-ui.sh b/scripts/waydroid-dist-ui.sh index 8d5075b..1c638b1 100755 --- a/scripts/waydroid-dist-ui.sh +++ b/scripts/waydroid-dist-ui.sh @@ -71,8 +71,8 @@ build_apk() { exit 1 } cd "$DIST_UI" - # cargo-apk may panic after packaging (bin+cdylib); APK is still written. - cargo apk build --target x86_64-linux-android --no-default-features || true + # --lib: only the cdylib (avoids cargo-apk "Bin is not compatible with Cdylib"). + cargo apk build --lib --target x86_64-linux-android --no-default-features APK="$DIST_UI/target/debug/apk/global-dist-ui.apk" [[ -f "$APK" ]] || { echo "APK missing at $APK" >&2; exit 1; } echo "$APK" diff --git a/test/ci_apk_workflow_test.sh b/test/ci_apk_workflow_test.sh index b7440ca..6010e7c 100755 --- a/test/ci_apk_workflow_test.sh +++ b/test/ci_apk_workflow_test.sh @@ -36,7 +36,7 @@ check "workflow enables FHS wrap" grep -q 'GLOBAL_CI_USE_FHS' "$WF" check "script has buildFHSEnv path" grep -q 'buildFHSEnv' "$SCRIPT" check "script emits APK_REL path" grep -q 'dist-ui/target/debug/apk/global-dist-ui.apk' "$SCRIPT" check "script checks ZIP magic" grep -q '504b' "$SCRIPT" -check "script tolerates cargo-apk panic" grep -q 'cargo apk build' "$SCRIPT" +check "script builds APK with --lib" grep -q 'cargo apk build --lib' "$SCRIPT" # Spindle nixery may omit findutils; NDK extract must not require bare find(1). check "script NDK extract avoids find(1)" bash -c "! grep -E '(^|[^[:alnum:]_])find ' '$SCRIPT'" check "workflow includes findutils (belt)" grep -q 'findutils' "$WF"