diff --git a/.github/patches/apply_flutter_3.44_source_patches.sh b/.github/patches/apply_flutter_3.44_source_patches.sh index 27d91912a..4e6d69771 100644 --- a/.github/patches/apply_flutter_3.44_source_patches.sh +++ b/.github/patches/apply_flutter_3.44_source_patches.sh @@ -14,9 +14,9 @@ # (https://github.com/rustdesk/rustdesk/issues/17143). DialogTextField keeps 3.24's desktop # behavior; 3.24 has no selectAllOnFocus parameter, hence the patch. # -# Used by BOTH arm64 builds (flutter-build.yml) and their shared bridge artifact (bridge.yml) so -# they share an identical 3.44 source state -- the generated *.freezed.dart must compile against -# the same Flutter/freezed version the arm64 builds resolve. +# Used by the arm64 builds and the Linux riscv64 build (flutter-build.yml) and their shared bridge +# artifact (bridge.yml) so they share an identical 3.44 source state -- the generated +# *.freezed.dart must compile against the same Flutter/freezed version those builds resolve. # # Remove this script (and commit the changes) once upstream bumps Flutter across the board. # @@ -29,10 +29,10 @@ # resolve differently under Flutter 3.44 with the bumps below: mostly packages the Flutter SDK # pins, plus the bumped ones. Every other package keeps following the committed lock, and a # change there that the diff no longer fits fails here or at `flutter pub get --enforce-lockfile` -# instead of resolving live. Moving FLUTTER_WINDOWS_ARM_VERSION, FLUTTER_MACOS_ARM_VERSION or the -# 3.44 bridge to a release whose SDK pins differ needs a new diff. To regenerate it, with that -# Flutter on PATH: make the two pubspec.yaml bumps below by hand, run `flutter pub get` in -# flutter/, and save `git diff flutter/pubspec.lock` to that file. +# instead of resolving live. Moving FLUTTER_WINDOWS_ARM_VERSION, FLUTTER_MACOS_ARM_VERSION, +# FLUTTER_RISCV64_VERSION or the 3.44 bridge to a release whose SDK pins differ needs a new diff. +# To regenerate it, with that Flutter on PATH: make the two pubspec.yaml bumps below by hand, run +# `flutter pub get` in flutter/, and save `git diff flutter/pubspec.lock` to that file. set -euo pipefail readonly NO_MATCHES=0 diff --git a/.github/workflows/bridge.yml b/.github/workflows/bridge.yml index d642328f5..546b247b7 100644 --- a/.github/workflows/bridge.yml +++ b/.github/workflows/bridge.yml @@ -32,7 +32,7 @@ jobs: flutter-version: "3.22.3", artifact-name: "bridge-artifact", } - # Dedicated bridge for the Windows and macOS arm64 builds (Flutter 3.44); runs in parallel. + # Dedicated bridge for the Flutter 3.44 builds (Windows/macOS arm64, Linux riscv64); runs in parallel. # Its lock comes from .github/patches/flutter_3.44_pubspec.lock.diff (see the header of # apply_flutter_3.44_source_patches.sh before changing flutter-version). - { @@ -110,7 +110,7 @@ jobs: # in flutter/, then save `git diff flutter/pubspec.lock` to it. git apply .github/patches/flutter_3.22_bridge_pubspec.lock.diff else - # Flutter 3.44 bridge for Windows/macOS arm64: match those builds' source/pubspec state so + # Flutter 3.44 bridge (Windows/macOS arm64, Linux riscv64): match those builds' source/pubspec state so # the generated *.freezed.dart compiles against the same Flutter/freezed they resolve. bash .github/patches/apply_flutter_3.44_source_patches.sh fi diff --git a/.github/workflows/flutter-build.yml b/.github/workflows/flutter-build.yml index 57605983b..8287ca9e1 100644 --- a/.github/workflows/flutter-build.yml +++ b/.github/workflows/flutter-build.yml @@ -43,6 +43,16 @@ env: # (https://github.com/rustdesk/rustdesk/issues/16817, https://github.com/flutter/flutter/issues/153157). # x86_64 stays on FLUTTER_VERSION: 3.44's FlutterMacOS needs macOS 10.15 there, and it targets 10.14. FLUTTER_MACOS_ARM_VERSION: "3.44.9" + # linux riscv64: the same 3.44 release as the arm64 builds and the 3.44 bridge. Flutter publishes + # no riscv64 engine; rustdesk-org/flutter-engine builds one per engine version (meta-flutter's + # riscv64 build, on a GitHub-hosted runner, with provenance attestation). A new + # FLUTTER_RISCV64_VERSION needs a run of its rustdesk-engine-riscv64 workflow first. + FLUTTER_RISCV64_VERSION: "3.44.9" + # From flutter_infra_release/releases/releases_linux.json; a new FLUTTER_RISCV64_VERSION needs it. + FLUTTER_RISCV64_SHA256: "a9120fa4a01048bdef438ddc3a2d4b7389662ea98a95db86eeaf10382bc4efcb" + # bin/internal/engine.version of FLUTTER_RISCV64_VERSION. + FLUTTER_RISCV64_ENGINE: "5a2a6a42cce67f965cf540fcecf616faca624aa1" + FLUTTER_RISCV64_ENGINE_SHA256: "a305a700a3edc91511beae6d8e7f48b7bde43ae36dcfc43aadf302ea8b1b7b18" # for arm64 linux because official Dart SDK does not work FLUTTER_ELINUX_VERSION: "3.16.9" TAG_NAME: "${{ inputs.upload-tag }}" @@ -2486,6 +2496,294 @@ jobs: files: | res/rustdesk-${{ env.VERSION }}*.zst + # Cross-built on x86_64 against Ubuntu 24.04's riscv64 ports archive, with Flutter 3.44 (the + # Windows/macOS arm64 source patches, lock diff and bridge) and rustdesk-org's riscv64 engine. + # vcpkg has no riscv64 support here, so libvpx and libaom are built from the sources and versions + # of the res/vcpkg overlay ports and linked statically, as vcpkg links them on x86_64 and aarch64: + # their sonames change between distribution releases. opus, libyuv and libsodium, whose sonames + # are stable, come from the distribution (linux-pkg-config). Like the other Linux debs it carries + # the drm backend and libdrmtap, off until allow-drm-capture is on. + # Built only when uploading (nightly, tags), as build-rustdesk-linux builds aarch64. + build-rustdesk-linux-riscv64: + if: ${{ inputs.upload-artifact }} + needs: [generate-bridge] + name: build rustdesk linux riscv64 + runs-on: ubuntu-24.04 + env: + BUILD_ARGS: "--flutter --unix-file-copy-paste" + TARGET: riscv64gc-unknown-linux-gnu + FLUTTER_ROOT: /opt/flutter + # Static libvpx and libaom; keep in step with res/vcpkg/libvpx and res/vcpkg/aom. + CODECS_PREFIX: /opt/riscv64-codecs + LIBVPX_VERSION: "1.15.2" + LIBVPX_SHA512: "824fe8719e4115ec359ae0642f5e1cea051d458f09eb8c24d60858cf082f66e411215e23228173ab154044bafbdfbb2d93b589bb726f55b233939b91f928aae0" + AOM_COMMIT: "03087864cf4bea6abb0d28f95cf7843511413d8f" # 3.14.1 + steps: + - name: Maximize build space + run: sudo rm -rf /opt/ghc /usr/local/lib/android /usr/share/dotnet + + - name: Checkout source code + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + with: + submodules: recursive + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1 + with: + toolchain: ${{ env.RUST_VERSION }} + targets: riscv64gc-unknown-linux-gnu + + - name: Restore bridge files + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: bridge-artifact-flutter-3.44 + path: ./ + + - name: Install cross toolchain and riscv64 libraries + shell: bash + run: | + set -euo pipefail + sudo sed -i 's/^Types: deb$/Types: deb\nArchitectures: amd64/' /etc/apt/sources.list.d/ubuntu.sources + sudo tee /etc/apt/sources.list.d/ports-riscv64.sources > /dev/null <<'EOF' + Types: deb + URIs: http://ports.ubuntu.com/ubuntu-ports + Suites: noble noble-updates noble-security + Components: main restricted universe multiverse + Architectures: riscv64 + EOF + sudo dpkg --add-architecture riscv64 + sudo apt-get update -y + # qemu-user-static satisfies libglib2.0-dev:riscv64's `python3 | qemu-user-static`, + # which would otherwise replace the host's python3 with the riscv64 one. + sudo apt-get install -y --no-install-recommends gcc-riscv64-linux-gnu \ + g++-riscv64-linux-gnu clang libclang-dev lld cmake ninja-build meson pkg-config \ + make libssl-dev libsodium-dev qemu-user-static + sudo apt-get install -y --no-install-recommends \ + libc6-dev:riscv64 libgtk-3-dev:riscv64 libxcb-randr0-dev:riscv64 \ + libxcb-shape0-dev:riscv64 libxcb-xfixes0-dev:riscv64 libxdo-dev:riscv64 \ + libxfixes-dev:riscv64 libasound2-dev:riscv64 libpulse-dev:riscv64 libva-dev:riscv64 \ + libgstreamer1.0-dev:riscv64 libgstreamer-plugins-base1.0-dev:riscv64 \ + libayatana-appindicator3-dev:riscv64 libpam0g-dev:riscv64 libssl-dev:riscv64 \ + libopus-dev:riscv64 libyuv-dev:riscv64 \ + libsodium-dev:riscv64 libdrm-dev:riscv64 libegl-dev:riscv64 libgles-dev:riscv64 \ + libseccomp-dev:riscv64 libcap-dev:riscv64 + # libyuv-dev ships no pkg-config file. + sudo tee /usr/lib/riscv64-linux-gnu/pkgconfig/libyuv.pc > /dev/null <<'EOF' + prefix=/usr + libdir=${prefix}/lib/riscv64-linux-gnu + includedir=${prefix}/include + Name: libyuv + Description: YUV conversion and scaling + Version: 0.0 + Libs: -L${libdir} -lyuv + Cflags: -I${includedir} + EOF + + # Neither has riscv64 assembly at these versions, so both are the portable C build. + - name: Build static libvpx and libaom + shell: bash + run: | + set -euo pipefail + sudo mkdir -p "$CODECS_PREFIX" && sudo chown "$(id -u):$(id -g)" "$CODECS_PREFIX" + mkdir -p /tmp/codecs && cd /tmp/codecs + # The archive vcpkg_from_github fetches for the libvpx port, with the port's SHA-512. + curl -fsSL -o libvpx.tar.gz "https://github.com/webmproject/libvpx/archive/v${LIBVPX_VERSION}.tar.gz" + echo "$LIBVPX_SHA512 libvpx.tar.gz" | sha512sum -c - + mkdir libvpx && tar -xzf libvpx.tar.gz -C libvpx --strip-components=1 + mkdir vpx-build && pushd vpx-build + CROSS=riscv64-linux-gnu- ../libvpx/configure --target=generic-gnu --prefix="$CODECS_PREFIX" \ + --enable-static --disable-shared --enable-pic --disable-examples --disable-tools \ + --disable-docs --disable-unit-tests + make -j"$(nproc)" && make install + popd + # The aom port takes this commit from aomedia.googlesource.com; fetch it by sha. + mkdir aom && pushd aom + git init -q && git remote add origin https://aomedia.googlesource.com/aom + git fetch -q --depth 1 origin "$AOM_COMMIT" && git checkout -q FETCH_HEAD + test "$(git rev-parse HEAD)" = "$AOM_COMMIT" + popd + cmake -S aom -B aom-build -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=riscv64 \ + -DCMAKE_C_COMPILER=riscv64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=riscv64-linux-gnu-g++ \ + -DCMAKE_INSTALL_PREFIX="$CODECS_PREFIX" -DCMAKE_INSTALL_LIBDIR=lib \ + -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DAOM_TARGET_CPU=generic \ + -DENABLE_DOCS=OFF -DENABLE_EXAMPLES=OFF -DENABLE_TESTDATA=OFF -DENABLE_TESTS=OFF \ + -DENABLE_TOOLS=OFF + cmake --build aom-build && cmake --install aom-build + ls -l "$CODECS_PREFIX/lib" "$CODECS_PREFIX/lib/pkgconfig" + rm -rf /tmp/codecs + + # Cross-built here rather than by build.py, which builds for the host. build.py takes it + # through DRMTAP_PREBUILT_DIR without the unpinned opt-in, since it is the pinned checkout. + - name: Build libdrmtap + shell: bash + run: | + set -euo pipefail + read -r repo sha < <(python3 - <<'PY' + import importlib.util, sys + spec = importlib.util.spec_from_file_location("b", "build.py") + b = importlib.util.module_from_spec(spec) + sys.argv = ["build.py"] + spec.loader.exec_module(b) + print(b.LIBDRMTAP_REPO_PINNED, b.LIBDRMTAP_SHA_PINNED) + PY + ) + mkdir -p third_party/libdrmtap && cd third_party/libdrmtap + git init -q && git remote add origin "$repo" + git fetch -q --depth 1 origin "$sha" && git checkout -q FETCH_HEAD + cat > riscv64.cross <<'EOF' + [binaries] + c = 'riscv64-linux-gnu-gcc' + cpp = 'riscv64-linux-gnu-g++' + ar = 'riscv64-linux-gnu-ar' + strip = 'riscv64-linux-gnu-strip' + pkg-config = 'pkg-config' + [properties] + pkg_config_libdir = '/usr/lib/riscv64-linux-gnu/pkgconfig:/usr/share/pkgconfig' + [host_machine] + system = 'linux' + cpu_family = 'riscv64' + cpu = 'riscv64' + endian = 'little' + EOF + meson setup build-pkg --buildtype=release -Dhelper=disabled --cross-file riscv64.cross + meson compile -C build-pkg drmtap:shared_library + + - name: Install Flutter and the riscv64 engine + shell: bash + run: | + set -euo pipefail + sudo mkdir -p "$FLUTTER_ROOT" && sudo chown "$(id -u):$(id -g)" "$FLUTTER_ROOT" + curl -fsSL -o /tmp/flutter.tar.xz "https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_${FLUTTER_RISCV64_VERSION}-stable.tar.xz" + echo "$FLUTTER_RISCV64_SHA256 /tmp/flutter.tar.xz" | sha256sum -c - + tar -xJf /tmp/flutter.tar.xz -C "$FLUTTER_ROOT" --strip-components=1 + rm /tmp/flutter.tar.xz + git config --global --add safe.directory '*' + test "$(cat "$FLUTTER_ROOT/bin/internal/engine.version")" = "$FLUTTER_RISCV64_ENGINE" + export PATH="$FLUTTER_ROOT/bin:$PATH" + flutter config --no-analytics --enable-riscv64 + flutter precache --linux + tag="linux-engine-sdk-release-riscv64-$FLUTTER_RISCV64_ENGINE" + curl -fsSL -o /tmp/engine.tar.gz "https://github.com/rustdesk-org/flutter-engine/releases/download/$tag/$tag.tar.gz" + echo "$FLUTTER_RISCV64_ENGINE_SHA256 /tmp/engine.tar.gz" | sha256sum -c - + mkdir /tmp/engine && tar -xzf /tmp/engine.tar.gz -C /tmp/engine --wildcards \ + '*/engine-sdk/lib/libflutter_linux_gtk.so' '*/engine-sdk/clang_x64/bin/gen_snapshot' + sdk=$(dirname "$(find /tmp/engine -type d -name clang_x64)") + # The tool only downloads the host's linux-x64 artifacts; these directories are ours. + cache="$FLUTTER_ROOT/bin/cache/artifacts/engine" + for d in linux-riscv64 linux-riscv64-release; do + mkdir -p "$cache/$d" + cp "$sdk/lib/libflutter_linux_gtk.so" "$cache/$d/" + cp "$sdk/clang_x64/bin/gen_snapshot" "$cache/$d/gen_snapshot" + cp "$sdk/clang_x64/bin/gen_snapshot" "$cache/$d/gen_snapshot_riscv64" + cp -r "$cache/linux-x64-release/flutter_linux" "$cache/$d/" + cp "$cache/linux-x64/icudtl.dat" "$cache/$d/" + done + rm -rf /tmp/engine /tmp/engine.tar.gz + + - name: Build rustdesk library + shell: bash + run: | + set -euo pipefail + sed -i "s/\[\"cdylib\", \"staticlib\", \"rlib\"\]/\[\"cdylib\"\]/g" Cargo.toml + export CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-linux-gnu-gcc + export CC_riscv64gc_unknown_linux_gnu=riscv64-linux-gnu-gcc + export CXX_riscv64gc_unknown_linux_gnu=riscv64-linux-gnu-g++ + export AR_riscv64gc_unknown_linux_gnu=riscv64-linux-gnu-ar + export PKG_CONFIG_ALLOW_CROSS=1 + export PKG_CONFIG_LIBDIR_riscv64gc_unknown_linux_gnu=$CODECS_PREFIX/lib/pkgconfig:/usr/lib/riscv64-linux-gnu/pkgconfig:/usr/share/pkgconfig + # Link the static libvpx and libaom from CODECS_PREFIX (pkg-config's --static). + export VPX_STATIC=1 AOM_STATIC=1 + export BINDGEN_EXTRA_CLANG_ARGS_riscv64gc_unknown_linux_gnu="--target=riscv64-linux-gnu -I/usr/include/riscv64-linux-gnu" + # libsodium-sys's configure does not know the riscv64gc triple; pkg-config is target-scoped. + export SODIUM_USE_PKG_CONFIG=1 + # mozjpeg-sys enables SIMD on riscv64 without having any riscv64 SIMD code, and then + # leaves out jsimd_none.c; compile that fallback and link it in. + cargo build --locked --release --target "$TARGET" -p mozjpeg-sys + mzv=$(grep -A1 '^name = "mozjpeg-sys"$' Cargo.lock | sed -n 's/^version = "\(.*\)"$/\1/p') + mzsrc=$(ls -d ~/.cargo/registry/src/*/mozjpeg-sys-"$mzv" | head -1) + mzout=$(ls -d target/"$TARGET"/release/build/mozjpeg-sys-*/out | head -1) + riscv64-linux-gnu-gcc -O2 -fPIC -c "$mzsrc/vendor/jsimd_none.c" \ + -I"$mzout/include" -I"$mzsrc/vendor" -o "$PWD/target/jsimd_none.o" + export CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUSTFLAGS="-C link-arg=$PWD/target/jsimd_none.o" + FEATURES=$(python3 ./build.py $BUILD_ARGS --print-features),linux-pkg-config + cargo build --locked --lib --release --target "$TARGET" --features "$FEATURES" + mkdir -p target/release + cp "target/$TARGET/release/liblibrustdesk.so" target/release/ + + - name: Build flutter and package + shell: bash + run: | + set -euo pipefail + bash .github/patches/apply_flutter_3.44_source_patches.sh + (cd flutter && "$FLUTTER_ROOT/bin/flutter" pub get --enforce-lockfile) + sed -i "s|flutter build linux --release|flutter build linux --release --target-platform linux-riscv64 --target-sysroot /|" build.py + sed -i "s|x64/release|riscv64/release|g" build.py + export PATH="$FLUTTER_ROOT/bin:$PATH" + export PKG_CONFIG_LIBDIR=/usr/lib/riscv64-linux-gnu/pkgconfig:/usr/share/pkgconfig + export DEB_ARCH=riscv64 + export DRMTAP_PREBUILT_DIR="$PWD/third_party/libdrmtap/build-pkg" + python3 ./build.py $BUILD_ARGS --skip-cargo + for name in rustdesk*??.deb; do + mv "$name" "${name%%.deb}-riscv64.deb" + done + + - name: Check the deb + shell: bash + run: | + set -euo pipefail + shopt -s nullglob + debs=(rustdesk-*-riscv64.deb) + [ "${#debs[@]}" -eq 1 ] || { echo "::error::expected one riscv64 deb, found: ${debs[*]-none}"; exit 1; } + deb="${debs[0]}" + echo "DEB=$deb" >> "$GITHUB_ENV" + [ "$(dpkg-deb -f "$deb" Architecture)" = riscv64 ] + rm -rf /tmp/deb && dpkg-deb -R "$deb" /tmp/deb + for f in rustdesk lib/librustdesk.so lib/libflutter_linux_gtk.so lib/libapp.so; do + [ -f "/tmp/deb/usr/share/rustdesk/$f" ] || { echo "::error::$deb has no $f"; exit 1; } + done + # Every ELF in the package, Flutter engine and plugins included, must be riscv64. + # Tab-separated so the test sees file's description, never the path. + elfs=$(find /tmp/deb/usr -type f -exec file -F $'\t' {} + | awk -F '\t' '$2 ~ /^ *ELF/') + echo "$elfs" + bad=$(awk -F '\t' '$2 !~ /RISC-V/' <<< "$elfs") + if [ -n "$bad" ]; then + echo "::error::$deb carries non-riscv64 ELF files:" + echo "$bad" + exit 1 + fi + # The deb must carry libdrmtap and a binary that dlopens it, as build-rustdesk-linux checks. + contents=$(dpkg -c "$deb") + grep -qE 'usr/lib/rustdesk/libdrmtap\.so\.0\.[0-9]+\.[0-9]+' <<< "$contents" || + { echo "::error::$deb has no versioned libdrmtap.so.0.x.y"; exit 1; } + grep -qF 'usr/lib/rustdesk/libdrmtap.so.0 ->' <<< "$contents" || + { echo "::error::$deb has no libdrmtap.so.0 soname symlink"; exit 1; } + grep -qF /usr/lib/rustdesk/libdrmtap.so.0 /tmp/deb/usr/share/rustdesk/lib/librustdesk.so || + { echo "::error::$deb was not built with the drm feature"; exit 1; } + # libvpx and libaom are linked in, so nothing may need their distribution sonames. + needed=$(riscv64-linux-gnu-readelf -d /tmp/deb/usr/share/rustdesk/lib/librustdesk.so | grep NEEDED) + echo "$needed" + if grep -E 'lib(vpx|aom)\.so' <<< "$needed"; then + echo "::error::$deb links libvpx or libaom dynamically" + exit 1 + fi + + - name: Publish debian package + if: env.UPLOAD_ARTIFACT == 'true' + uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v1 + with: + prerelease: true + tag_name: ${{ env.TAG_NAME }} + files: | + ${{ env.DEB }} + + - name: Upload deb + if: always() && env.DEB != '' + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: ${{ env.DEB }} + path: ${{ env.DEB }} + build-rustdesk-linux-sciter: if: ${{ inputs.upload-artifact }} needs: [validate-update-metadata-keys] diff --git a/build.py b/build.py index 59ac5c712..961323452 100755 --- a/build.py +++ b/build.py @@ -46,6 +46,9 @@ def get_deb_extra_depends() -> str: custom_arch = os.environ.get("DEB_ARCH") if custom_arch == "armhf": # for arm32v7 libsciter-gtk.so return ", libatomic1" + if custom_arch == "riscv64": # libvpx/libaom are static; these come from the distribution + # Cross-built on Ubuntu 24.04 (glibc 2.39, g++ 13): keep apt from installing it on older releases. + return ", libc6 (>= 2.39), libstdc++6 (>= 13), libopus0, libyuv0, libsodium23" return "" def system2(cmd):