diff --git a/.gitea/workflows/build-linux.yml b/.gitea/workflows/build-linux.yml index 7d7a84438..1d52267b3 100644 --- a/.gitea/workflows/build-linux.yml +++ b/.gitea/workflows/build-linux.yml @@ -106,13 +106,31 @@ jobs: [[ -x "$tools/bin/flutter_rust_bridge_codegen" ]] || { echo "missing fr_bridge_codegen"; exit 1; } echo "$tools/bin" >> "$GITHUB_PATH" - - name: Generate Rust <-> Dart bridge + - name: Generate Rust <-> Dart bridge (with Flutter 3.22.3) shell: bash run: | set -e - export PATH="/opt/cargo-tools/bin:$PATH" + # flutter_rust_bridge_codegen 1.80.1 + freezed produces broken Dart + # output (wrong FFI types, unprefixed Int/Pointer in part files) when + # run under Flutter 3.24.5 on Linux. Upstream's bridge.yml works around + # this by running the bridge generation under Flutter 3.22.3 -- the + # produced .dart/.freezed.dart files are then compatible with the + # 3.24.5 build that follows. + # + # provision.sh installs Flutter 3.22.3 at /opt/flutter-bridge alongside + # /opt/flutter (3.24.5). Use the bridge SDK ONLY for pub get + codegen, + # then unset PATH overrides so subsequent steps use the build SDK. + export PATH="/opt/cargo-tools/bin:/opt/flutter-bridge/bin:$PATH" + flutter --version command -v flutter_rust_bridge_codegen - (cd flutter && flutter pub get) + + # extended_text 14.0.0 requires Flutter 3.24+. Downgrade to 13.0.0 for + # the bridge-gen pub get under 3.22.3. Mirrors upstream bridge.yml. + (cd flutter && \ + sed -i -e 's/extended_text: 14.0.0/extended_text: 13.0.0/g' pubspec.yaml && \ + flutter pub get && \ + git checkout -- pubspec.yaml) + flutter_rust_bridge_codegen \ --llvm-path "$LLVM_HOME" \ --rust-input ./src/flutter_ffi.rs \ @@ -120,30 +138,11 @@ jobs: --c-output ./flutter/macos/Runner/bridge_generated.h cp ./flutter/macos/Runner/bridge_generated.h ./flutter/ios/Runner/bridge_generated.h - # Explicitly regenerate .freezed.dart files. - (cd flutter && dart run build_runner build --delete-conflicting-outputs) - - # Workaround for a flutter_rust_bridge 1.80.1 + freezed interaction: - # the generated `lib/generated_bridge.freezed.dart` references FFI - # types like `Int` and `Pointer` *without* the `ffi.` prefix that the - # parent file's `import 'dart:ffi' as ffi;` requires. Result is - # "Type 'Int' not found" / "Type 'Pointer' not found" at build time. - # Add the prefix where it's missing -- only when the identifier is - # NOT already prefixed (no preceding `.`) and is NOT part of a longer - # token (no preceding alnum/underscore). - freezed=./flutter/lib/generated_bridge.freezed.dart - if [ -f "$freezed" ]; then - echo "Patching FFI type prefixes in $(basename "$freezed")" - sed -i -E ' - s/([^A-Za-z0-9_.])Pointer ,)])/\1ffi.Int\2/g - ' "$freezed" - # Sanity: there should be no remaining unprefixed Int/Pointer in FFI position. - if grep -nE '[<,( ]Int[ >,)]|[<,( ]Pointer<' "$freezed" >/dev/null; then - echo "WARNING: still found unprefixed FFI types after patch:" - grep -nE '[<,( ]Int[ >,)]|[<,( ]Pointer<' "$freezed" | head - fi - fi + # Re-resolve packages with the build SDK (3.24.5) so pubspec.lock has + # the correct entries for the final build. The generated_bridge files + # produced under 3.22.3 above stay on disk -- they're plain Dart and + # remain compatible with 3.24.5's compiler. + (cd flutter && /opt/flutter/bin/flutter pub get) - name: vcpkg install dependencies (x64-linux) shell: bash diff --git a/ci/runners/linux/provision.sh b/ci/runners/linux/provision.sh index 903e5505c..47e565449 100755 --- a/ci/runners/linux/provision.sh +++ b/ci/runners/linux/provision.sh @@ -23,7 +23,8 @@ set -euo pipefail # ---- pinned versions (mirror .gitea/workflows/build-linux.yml env block) ---- RUST_VERSION="1.75.0" -FLUTTER_VERSION="3.24.5" +FLUTTER_VERSION="3.24.5" # used for `flutter build linux` +FLUTTER_BRIDGE_VERSION="3.22.3" # used for `flutter pub get` + flutter_rust_bridge_codegen LLVM_VERSION="15.0.6" VCPKG_COMMIT="120deac3062162151622ca4860575a33844ba10b" RUNNER_VERSION="0.2.11" @@ -135,18 +136,31 @@ fi "$CARGO_HOME/bin/rustup" target add --toolchain "$RUST_VERSION" x86_64-unknown-linux-gnu "$CARGO_HOME/bin/rustup" default "$RUST_VERSION" -# ---- 5. Flutter ---- +# ---- 5. Flutter (two SDKs: 3.24.5 for build, 3.22.3 for bridge gen) ---- +# Why two: the bridge codegen (flutter_rust_bridge_codegen 1.80.1 + freezed) +# produces broken Dart output when run under newer Flutter SDKs on Linux. +# Upstream's bridge.yml uses 3.22.3 specifically; we mirror that. The .deb +# build itself uses 3.24.5. +install_flutter() { + local ver="$1" dir="$2" + if [[ ! -x "$dir/bin/flutter" ]]; then + log "Installing Flutter $ver -> $dir" + local tmp; tmp="$(mktemp -d)" + local parent; parent="$(dirname "$dir")" + curl -fsSL -o "$tmp/flutter.tar.xz" \ + "https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_${ver}-stable.tar.xz" + # Tarball extracts into a top-level `flutter/` dir; rename to target. + tar -xJf "$tmp/flutter.tar.xz" -C "$tmp" + mkdir -p "$parent" + mv "$tmp/flutter" "$dir" + rm -rf "$tmp" + fi + "$dir/bin/flutter" config --no-analytics >/dev/null + "$dir/bin/flutter" precache --linux >/dev/null +} +install_flutter "$FLUTTER_VERSION" /opt/flutter +install_flutter "$FLUTTER_BRIDGE_VERSION" /opt/flutter-bridge FLUTTER_DIR=/opt/flutter -if [[ ! -x "$FLUTTER_DIR/bin/flutter" ]]; then - log "Installing Flutter $FLUTTER_VERSION" - tmp="$(mktemp -d)" - curl -fsSL -o "$tmp/flutter.tar.xz" \ - "https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_${FLUTTER_VERSION}-stable.tar.xz" - tar -xJf "$tmp/flutter.tar.xz" -C /opt - rm -rf "$tmp" -fi -"$FLUTTER_DIR/bin/flutter" config --no-analytics >/dev/null -"$FLUTTER_DIR/bin/flutter" precache --linux >/dev/null # ---- 6. vcpkg ---- VCPKG_DIR=/opt/vcpkg @@ -170,6 +184,7 @@ chown -R "$SERVICE_USER:$SERVICE_USER" "$RUSTUP_HOME" # Flutter SDK: r/x is enough for builds, but `flutter pub get` writes to its # own cache subdir so we make it writable as well. chown -R "$SERVICE_USER:$SERVICE_USER" "$FLUTTER_DIR" +chown -R "$SERVICE_USER:$SERVICE_USER" /opt/flutter-bridge # vcpkg: builds write under installed/, buildtrees/, etc. chown -R "$SERVICE_USER:$SERVICE_USER" "$VCPKG_DIR" # LLVM: read+execute is enough; we never write here at build time.