diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index cccdafa8..a3cbb55c 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -325,3 +325,178 @@ jobs: --data-binary @"$f" \ "${upload_url}?name=${f##*/}" done + + deb-loong64: + name: build and release deb loong64 + if: | + (github.event_name == 'workflow_dispatch' && inputs.release_tag != '') || + (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) + runs-on: ubuntu-24.04 + + env: + RELEASE_TAG: ${{ case(inputs.release_tag != '', inputs.release_tag, github.ref_name) }} + QCOW2_URL: https://github.com/xujiegb/debian-loong64-qcow2/releases/download/13.4/debian13-loong64.qcow2 + EFI_CODE_URL: https://github.com/xujiegb/debian-loong64-qcow2/releases/download/13.4/edk2-loongarch64-code.fd + EFI_VARS_URL: https://github.com/xujiegb/debian-loong64-qcow2/releases/download/13.4/edk2-loongarch64-vars.fd + QCOW2_IMAGE: debian13-loong64.qcow2 + EFI_CODE: edk2-loongarch64-code.fd + EFI_VARS: edk2-loongarch64-vars.fd + QEMU_VERSION: 10.2.2 + + steps: + - name: Prepare host tools + shell: bash + run: | + set -euo pipefail + + sudo apt-get update + sudo apt-get install -y rsync qemu-utils expect wget curl ca-certificates libfdt1 libglib2.0-0 libpixman-1-0 libslirp0 + + - name: Checkout repo + uses: actions/checkout@v6 + with: + submodules: recursive + fetch-depth: 0 + + - name: Download QEMU prebuild + run: | + set -euo pipefail + + wget -O qemu-linux-x64.tar.gz \ + "https://github.com/xujiegb/qemu-linux-prebuild/releases/download/${QEMU_VERSION}/qemu-linux-x64.tar.gz" + + tar -xzf qemu-linux-x64.tar.gz + + mkdir -p "$HOME/qemu-install" + + rsync -a qemu-linux-x64/ "$HOME/qemu-install/" + + "$HOME/qemu-install/bin/qemu-system-loongarch64" --version + + - name: Download loong64 qcow2 and EFI firmware + shell: bash + run: | + set -euo pipefail + + wget -O "$QCOW2_IMAGE" "$QCOW2_URL" + wget -O "$EFI_CODE" "$EFI_CODE_URL" + wget -O "$EFI_VARS" "$EFI_VARS_URL" + + qemu-img info "$QCOW2_IMAGE" + + - name: Build loong64 DEB in VM through serial console + shell: bash + timeout-minutes: 180 + env: + RELEASE_TAG: ${{ env.RELEASE_TAG }} + run: | + set -euo pipefail + + mkdir -p "$GITHUB_WORKSPACE/dist/deb-loong64" + + expect <<'EOF' + log_user 1 + set timeout -1 + + set release_tag $env(RELEASE_TAG) + set qemu_bin "$env(HOME)/qemu-install/bin/qemu-system-loongarch64" + set qemu_rom_dir "$env(HOME)/qemu-install/share/qemu" + + set workspace $env(GITHUB_WORKSPACE) + set repo $env(GITHUB_REPOSITORY) + set sha $env(GITHUB_SHA) + + set qcow2 $env(QCOW2_IMAGE) + set efi_code $env(EFI_CODE) + set efi_vars $env(EFI_VARS) + + proc wait_prompt {} { + expect { + -re "__CI_PROMPT__# " {} + timeout { exit 1 } + eof { exit 1 } + } + } + + proc run_cmd {cmd} { + send -- "$cmd\r" + wait_prompt + } + + spawn $qemu_bin \ + -L $qemu_rom_dir \ + -machine virt \ + -accel tcg,thread=multi,tb-size=2048 \ + -cpu la464 \ + -m 9216 \ + -smp 4 \ + -drive if=pflash,format=raw,unit=0,file=$efi_code,readonly=on \ + -drive if=pflash,format=raw,unit=1,file=$efi_vars \ + -device virtio-blk-pci,drive=hd0,bootindex=1 \ + -drive if=none,media=disk,id=hd0,file=$qcow2,format=qcow2 \ + -netdev user,id=net0 \ + -device virtio-net-pci,netdev=net0 \ + -virtfs local,path=$workspace,mount_tag=workspace,security_model=none,id=workspace \ + -display none \ + -serial stdio \ + -monitor none + + expect -re "login:|debian login:" + send -- "root\r" + + expect -re "Password:|密码:|密码:" + send -- "password\r" + + expect { + -re "# " {} + timeout { exit 1 } + eof { exit 1 } + } + + send -- "export TERM=dumb; export PS1='__CI_PROMPT__# '\r" + wait_prompt + + run_cmd "mkdir -p /workspace" + run_cmd "mount -t 9p -o trans=virtio,version=9p2000.L workspace /workspace || mount -t 9p -o trans=virtio workspace /workspace" + run_cmd "IFACE=\$(ip -o link show | awk -F': ' '\$2 != \"lo\" {print \$2; exit}') ; ip link set \$IFACE up || true" + run_cmd "dhclient \$IFACE || true" + run_cmd "printf 'nameserver 10.0.2.3\nnameserver 1.1.1.1\n' >/etc/resolv.conf" + run_cmd "apt-get update || apt-get update || apt-get update" + run_cmd "DEBIAN_FRONTEND=noninteractive apt-get install -y sudo git rsync findutils tar gzip unzip which curl jq wget file ca-certificates desktop-file-utils xdg-utils fakeroot dpkg-dev gcc make libc6-dev libgcc-s1 libstdc++6 zlib1g libatomic1" + run_cmd "rm -rf /root/v2rayN-src" + run_cmd "git clone --recursive https://github.com/$repo.git /root/v2rayN-src" + run_cmd "cd /root/v2rayN-src && git fetch --depth=1 origin $sha && git checkout FETCH_HEAD && git submodule update --init --recursive" + run_cmd "cd /root/v2rayN-src && chmod 755 package-debian-loong.sh" + + send -- "cd /root/v2rayN-src; cat >/tmp/run-loong-build.sh <<'SCRIPT'\nset +e\nset -o pipefail\nbash -x ./package-debian-loong.sh \"\$RELEASE_TAG\" 2>&1 | tee /tmp/build.log\nrc=\$?\nmkdir -p /workspace/dist/deb-loong64\ncp -av /root/debbuild/*.deb /workspace/dist/deb-loong64/ 2>/dev/null || true\necho __BUILD_DONE__\$rc\nSCRIPT\nRELEASE_TAG=\"$release_tag\" bash /tmp/run-loong-build.sh\r" + + expect { + -re "__BUILD_DONE__0" { + send -- "poweroff\r" + } + default { + exit 1 + } + } + EOF + + - name: Collect DEBs + shell: bash + run: | + set -euo pipefail + + mkdir -p "$GITHUB_WORKSPACE/dist/deb-loong64" + + find "$GITHUB_WORKSPACE/dist/deb-loong64" -name "*.deb" \ + -exec mv {} "$GITHUB_WORKSPACE/dist/deb-loong64/v2rayN-linux-loong64.deb" \; || true + + echo "==== Dist tree ====" + ls -R "$GITHUB_WORKSPACE/dist/deb-loong64" + + - name: Upload DEBs to release + uses: svenstaro/upload-release-action@v2 + with: + file: dist/deb-loong64/**/*.deb + tag: ${{ env.RELEASE_TAG }} + file_glob: true + prerelease: true diff --git a/.github/workflows/update-riscv-depand.yml b/.github/workflows/update-riscv-depand.yml deleted file mode 100644 index 9cb57d5e..00000000 --- a/.github/workflows/update-riscv-depand.yml +++ /dev/null @@ -1,256 +0,0 @@ -name: update riscv dependent versions - -on: - workflow_dispatch: - push: - branches: - - master - -permissions: - contents: write - -concurrency: - group: update-riscv-dependent - cancel-in-progress: false - -jobs: - update: - runs-on: ubuntu-24.04 - - steps: - - uses: actions/checkout@v6 - - - uses: actions/setup-dotnet@v5 - with: - dotnet-version: 10.0.1xx - - - run: sudo apt-get update && sudo apt-get install -y jq - - - name: resolve - id: resolve - shell: bash - run: | - set -euo pipefail - - TARGET_FILES=( - package-rhel-riscv.sh - package-debian-riscv.sh - ) - - echo "==> restore projects" - find . -name '*.csproj' | while read -r p; do - if grep -q '.*-windows' "$p"; then - echo "[skip] $p" - else - echo "[restore] $p" - dotnet restore "$p" -p:EnableWindowsTargeting=true || true - fi - done - - echo "==> collect assets" - mapfile -t ASSETS < <(find . -path '*/obj/project.assets.json') - printf ' %s\n' "${ASSETS[@]}" - - ALL_LIBS=() - for f in "${ASSETS[@]}"; do - mapfile -t libs < <(jq -r '.libraries | keys[]' "$f") - ALL_LIBS+=("${libs[@]}") - done - mapfile -t LIBS < <(printf '%s\n' "${ALL_LIBS[@]}" | sort -u) - - extract() { - local name="$1" - for i in "${LIBS[@]}"; do - [[ "$i" == "$name/"* ]] && echo "${i#*/}" - done | sort -u - } - - norm_version() { echo "${1#v}"; } - is_preview() { [[ "$(norm_version "$1")" == *-* ]]; } - base_version() { local v; v="$(norm_version "$1")"; echo "${v%%-*}"; } - - key() { - local v core pre a b c p1 p2 p3 - v="$(norm_version "$1")" - core="${v%%-*}" - [[ "$v" == *-* ]] && pre="${v#*-}" || pre="" - - IFS='.' read -r a b c <<< "$core" - a=${a//[^0-9]/}; a=${a:-0} - b=${b//[^0-9]/}; b=${b:-0} - c=${c//[^0-9]/}; c=${c:-0} - - if [[ -z "$pre" ]]; then - printf "%05d.%05d.%05d.1\n" "$a" "$b" "$c" - else - pre="${pre#preview.}" - IFS='.' read -ra p <<< "$pre" - p1=${p[0]:-0}; p1=${p1//[^0-9]/}; p1=${p1:-0} - p2=${p[1]:-0}; p2=${p2//[^0-9]/}; p2=${p2:-0} - p3=${p[2]:-0}; p3=${p3//[^0-9]/}; p3=${p3:-0} - printf "%05d.%05d.%05d.0.%05d.%05d.%05d\n" \ - "$a" "$b" "$c" "$p1" "$p2" "$p3" - fi - } - - latest() { - local best="" best_key="" cur cur_key - for cur in "$@"; do - [[ -n "$cur" ]] || continue - cur_key="$(key "$cur")" - echo " candidate: $cur -> $cur_key" >&2 - if [[ -z "$best_key" || "$cur_key" > "$best_key" ]]; then - best="$cur" - best_key="$cur_key" - fi - done - echo "$best" - } - - log_mixed_versions() { - local name="$1"; shift - local versions=("$@") bases=() v b - mapfile -t bases < <( - for v in "${versions[@]}"; do - [[ -n "$v" ]] && base_version "$v" - done | sort -u - ) - - for b in "${bases[@]}"; do - local has_stable=0 has_preview=0 matched=() - for v in "${versions[@]}"; do - [[ -n "$v" ]] || continue - [[ "$(base_version "$v")" == "$b" ]] || continue - matched+=("$v") - if is_preview "$v"; then - has_preview=1 - else - has_stable=1 - fi - done - - if [[ "$has_stable" -eq 1 && "$has_preview" -eq 1 ]]; then - echo "[warn] $name: stable and preview both exist for base $b, prefer stable for this base" >&2 - printf ' %s\n' "${matched[@]}" >&2 - fi - done - } - - filter_mixed_versions() { - local versions=("$@") stable_bases=() v b - mapfile -t stable_bases < <( - for v in "${versions[@]}"; do - if [[ -n "$v" ]] && ! is_preview "$v"; then - base_version "$v" - fi - done | sort -u - ) - - for v in "${versions[@]}"; do - [[ -n "$v" ]] || continue - b="$(base_version "$v")" - if is_preview "$v" && printf '%s\n' "${stable_bases[@]}" | grep -qxF "$b"; then - continue - fi - echo "$v" - done - } - - read_var() { - sed -nE "s/^$2=\"\\\$\\{$2:-([^\"]+)\\}\".*/\\1/p" "$1" | head -n1 - } - - choose_final_version() { - local old="$1" new="$2" - [[ -n "$new" ]] || { echo "$old"; return; } - [[ -n "$old" ]] || { echo "$new"; return; } - if [[ "$(key "$old")" > "$(key "$new")" ]]; then - echo "$old" - else - echo "$new" - fi - } - - update_file() { - local file="$1" - local old_skia old_harf final_skia final_harf changed=0 - - old_skia="$(read_var "$file" SKIA_VER)" - old_harf="$(read_var "$file" HARFBUZZ_VER)" - final_skia="$(choose_final_version "$old_skia" "$NEW_SKIA")" - final_harf="$(choose_final_version "$old_harf" "$NEW_HARF")" - - echo "==> check $file" - echo " SKIA_VER: ${old_skia} -> ${NEW_SKIA} (apply: ${final_skia})" - echo " HARFBUZZ_VER: ${old_harf} -> ${NEW_HARF} (apply: ${final_harf})" - - if [[ "$old_skia" != "$final_skia" ]]; then - sed -i -E "s|^SKIA_VER=.*|SKIA_VER=\"\\\${SKIA_VER:-$final_skia}\"|" "$file" - changed=1 - fi - if [[ "$old_harf" != "$final_harf" ]]; then - sed -i -E "s|^HARFBUZZ_VER=.*|HARFBUZZ_VER=\"\\\${HARFBUZZ_VER:-$final_harf}\"|" "$file" - changed=1 - fi - - grep -qF "SKIA_VER=\"\${SKIA_VER:-$final_skia}\"" "$file" - grep -qF "HARFBUZZ_VER=\"\${HARFBUZZ_VER:-$final_harf}\"" "$file" - bash -n "$file" - - [[ "$changed" -eq 1 ]] - } - - mapfile -t SKIA < <(extract SkiaSharp) - mapfile -t HARF < <(extract HarfBuzzSharp) - - echo "==> SkiaSharp" - printf ' %s\n' "${SKIA[@]}" - echo "==> HarfBuzzSharp" - printf ' %s\n' "${HARF[@]}" - - log_mixed_versions "SkiaSharp" "${SKIA[@]}" - log_mixed_versions "HarfBuzzSharp" "${HARF[@]}" - - mapfile -t SKIA < <(filter_mixed_versions "${SKIA[@]}") - mapfile -t HARF < <(filter_mixed_versions "${HARF[@]}") - - NEW_SKIA="$(latest "${SKIA[@]}")" - NEW_HARF="$(latest "${HARF[@]}")" - - echo "==> selected" - echo " SKIA_VER=$NEW_SKIA" - echo " HARFBUZZ_VER=$NEW_HARF" - - any_changed=0 - changed_files=() - - for file in "${TARGET_FILES[@]}"; do - if update_file "$file"; then - any_changed=1 - changed_files+=("$file") - fi - done - - if [[ "$any_changed" -eq 0 ]]; then - echo "changed=0" >> "$GITHUB_OUTPUT" - exit 0 - fi - - { - echo "changed=1" - echo "changed_files<> "$GITHUB_OUTPUT" - - - name: commit - if: steps.resolve.outputs.changed == '1' - run: | - git config user.name github-actions - git config user.email github-actions@github.com - git add package-rhel-riscv.sh package-debian-riscv.sh - if git diff --cached --quiet; then - exit 0 - fi - git commit -m "chore: update riscv native dependency versions" - git push diff --git a/package-debian-loong.sh b/package-debian-loong.sh new file mode 100644 index 00000000..e00b0cbf --- /dev/null +++ b/package-debian-loong.sh @@ -0,0 +1,742 @@ +#!/usr/bin/env bash +set -euo pipefail + +VERSION_ARG="" +WITH_CORE="both" +FORCE_NETCORE=0 +BUILD_FROM="" +XRAY_VER="${XRAY_VER:-}" +SING_VER="${SING_VER:-}" + +MIN_KERNEL="5.10" +PKGROOT="v2rayN-publish" +PROJECT_HINT="v2rayN.Desktop/v2rayN.Desktop.csproj" +OUTPUT_DIR="${HOME}/debbuild" +DOTNET_TFM="net10.0" +DOTNET_LOONGARCH_VERSION="10.0.108" +DOTNET_LOONGARCH_TAG="v10.0.108-loongarch64" +DOTNET_LOONGARCH_BASE="https://github.com/loongson/dotnet/releases/download" +DOTNET_LOONGARCH_FILE="dotnet-sdk-${DOTNET_LOONGARCH_VERSION}-linux-loongarch64.tar.gz" +DOTNET_SDK_URL="${DOTNET_LOONGARCH_BASE}/${DOTNET_LOONGARCH_TAG}/${DOTNET_LOONGARCH_FILE}" + +OS_ID="" +OS_NAME="" +OS_VERSION_ID="" +HOST_ARCH="" +SCRIPT_DIR="" +PROJECT="" +VERSION="" + +declare -a BUILT_DEBS=() + +die() { + echo "$*" >&2 + exit 1 +} + +parse_args() { + local first_arg="${1:-}" + + if [[ -n "$first_arg" && "$first_arg" != --* ]]; then + VERSION_ARG="$first_arg" + shift || true + fi + + while [[ $# -gt 0 ]]; do + case "$1" in + --with-core) WITH_CORE="${2:-both}"; shift 2 ;; + --xray-ver) XRAY_VER="${2:-}"; shift 2 ;; + --singbox-ver) SING_VER="${2:-}"; shift 2 ;; + --netcore) FORCE_NETCORE=1; shift ;; + --buildfrom) BUILD_FROM="${2:-}"; shift 2 ;; + *) + [[ -n "${VERSION_ARG:-}" ]] || VERSION_ARG="$1" + shift + ;; + esac + done + + if [[ -n "${VERSION_ARG:-}" && -n "${BUILD_FROM:-}" ]]; then + die "You cannot specify both an explicit version and --buildfrom at the same time. + Provide either a version (e.g. 7.14.0) OR --buildfrom 1|2|3." + fi +} + +detect_environment() { + local current_kernel="" + local lowest="" + + . /etc/os-release + + OS_ID="${ID:-}" + OS_NAME="${NAME:-$OS_ID}" + OS_VERSION_ID="${VERSION_ID:-}" + HOST_ARCH="$(uname -m)" + + case "$OS_ID" in + debian) + echo "Detected supported system: ${OS_NAME:-$OS_ID} ${OS_VERSION_ID:-}" + ;; + *) + die "Unsupported system: ${OS_NAME:-unknown} (${OS_ID:-unknown}). +This script only supports: Debian." + ;; + esac + + case "$HOST_ARCH" in + loongarch64) ;; + *) die "Only supports loongarch64" ;; + esac + + current_kernel="$(uname -r)" + lowest="$(printf '%s\n%s\n' "$MIN_KERNEL" "$current_kernel" | sort -V | head -n1)" + + [[ "$lowest" == "$MIN_KERNEL" ]] || die "Kernel $current_kernel is below $MIN_KERNEL" + echo "[OK] Kernel $current_kernel verified." +} + +install_dependencies() { + local install_ok=0 + local tmp_dotnet="" + + mkdir -p "$OUTPUT_DIR" + + if command -v apt-get >/dev/null 2>&1; then + sudo apt-get update + sudo apt-get -y install \ + curl unzip tar jq rsync ca-certificates git dpkg-dev fakeroot file \ + desktop-file-utils xdg-utils wget gcc make pkg-config \ + libicu-dev libssl-dev libfontconfig1 libfreetype6 zlib1g + + mkdir -p "$HOME/.dotnet" + tmp_dotnet="$(mktemp -d)" + curl -fL "$DOTNET_SDK_URL" -o "$tmp_dotnet/$DOTNET_LOONGARCH_FILE" + tar -C "$HOME/.dotnet" -xzf "$tmp_dotnet/$DOTNET_LOONGARCH_FILE" + rm -rf "$tmp_dotnet" + + export PATH="$HOME/.dotnet:$PATH" + export DOTNET_ROOT="$HOME/.dotnet" + + mkdir -p "$HOME/.nuget/NuGet" + + cat > "$HOME/.nuget/NuGet/NuGet.Config" < + + + + + + + +EOF + + dotnet --info >/dev/null 2>&1 && install_ok=1 + fi + + if [[ "$install_ok" -ne 1 ]]; then + echo "Could not auto-install dependencies for '$OS_ID'. Make sure these are available:" + echo "dotnet-loongarch SDK, curl, unzip, tar, rsync, git, gcc, make, dpkg-deb, fakeroot, libicu-dev, libssl-dev" + exit 1 + fi +} + +prepare_workspace() { + SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" + cd "$SCRIPT_DIR" + + if [[ -f .gitmodules ]]; then + git submodule sync --recursive || true + git submodule update --init --recursive || true + fi + + PROJECT="$PROJECT_HINT" + [[ -f "$PROJECT" ]] || PROJECT="$(find . -maxdepth 3 -name 'v2rayN.Desktop.csproj' | head -n1 || true)" + [[ -f "$PROJECT" ]] || die "v2rayN.Desktop.csproj not found" +} + +choose_channel() { + local ch="latest" + local sel="" + + if [[ -n "${BUILD_FROM:-}" ]]; then + case "$BUILD_FROM" in + 1) echo "latest"; return 0 ;; + 2) echo "prerelease"; return 0 ;; + 3) echo "keep"; return 0 ;; + *) die "[ERROR] Invalid --buildfrom value: ${BUILD_FROM}. Use 1|2|3." ;; + esac + fi + + if [[ -t 0 ]]; then + echo "[?] Choose v2rayN release channel:" >&2 + echo " 1) Latest (stable) [default]" >&2 + echo " 2) Pre-release (preview)" >&2 + echo " 3) Keep current (do nothing)" >&2 + printf "Enter 1, 2 or 3 [default 1]: " >&2 + + if read -r sel /dev/null 2>&1; then + git fetch --tags --force --prune --depth=1 || true + git rev-parse "refs/tags/${want}" >/dev/null 2>&1 && ref="$want" + + if [[ -n "$ref" ]]; then + echo "[OK] Found ref '${ref}', checking out..." + git checkout -f "$ref" + sync_submodules + return 0 + fi + fi + + return 1 +} + +apply_channel_or_keep() { + local ch="$1" + local tag="" + + if [[ "$ch" == "keep" ]]; then + echo "[*] Keep current repository state (no checkout)." + VERSION="$(git describe --tags --abbrev=0 2>/dev/null || echo '0.0.0+git')" + VERSION="${VERSION#v}" + return 0 + fi + + echo "[*] Resolving ${ch} tag from GitHub releases..." + + case "$ch" in + latest) tag="$(get_latest_tag_latest || true)" ;; + prerelease) tag="$(get_latest_tag_prerelease || true)" ;; + *) die "Failed to resolve latest tag for channel '${ch}'." ;; + esac + + [[ -n "$tag" ]] || die "Failed to resolve latest tag for channel '${ch}'." + + echo "[*] Latest tag for '${ch}': ${tag}" + git_try_checkout "$tag" || die "Failed to checkout '${tag}'." + VERSION="${tag#v}" +} + +resolve_version() { + if git rev-parse --git-dir >/dev/null 2>&1; then + if [[ -n "${VERSION_ARG:-}" ]]; then + local clean_ver="${VERSION_ARG#v}" + + if git_try_checkout "$clean_ver"; then + VERSION="$clean_ver" + else + echo "[WARN] Tag '${VERSION_ARG}' not found." + apply_channel_or_keep "$(choose_channel)" + fi + else + apply_channel_or_keep "$(choose_channel)" + fi + else + echo "Current directory is not a git repo; proceeding on current tree." + VERSION="${VERSION_ARG:-0.0.0}" + fi + + VERSION="${VERSION#v}" + echo "[*] GUI version resolved as: ${VERSION}" +} + +xray_url_for_rid() { + local rid="$1" + local ver="$2" + + case "$rid" in + linux-loongarch64) echo "https://github.com/XTLS/Xray-core/releases/download/v${ver}/Xray-linux-loong64.zip" ;; + *) return 1 ;; + esac +} + +singbox_url_for_rid() { + local rid="$1" + local ver="$2" + + case "$rid" in + linux-loongarch64) echo "https://github.com/SagerNet/sing-box/releases/download/v${ver}/sing-box-${ver}-linux-loong64.tar.gz" ;; + *) return 1 ;; + esac +} + +bundle_url_for_rid() { + local rid="$1" + + case "$rid" in + linux-loongarch64) echo "https://raw.githubusercontent.com/2dust/v2rayN-core-bin/refs/heads/master/v2rayN-linux-loong64.zip" ;; + *) return 1 ;; + esac +} + +download_xray() { + local outdir="$1" + local rid="$2" + local ver="${XRAY_VER:-}" + local url="" + local tmp="" + + mkdir -p "$outdir" + + if [[ -z "$ver" ]]; then + ver="$(curl -fsSL https://api.github.com/repos/XTLS/Xray-core/releases/latest \ + | grep -Eo '"tag_name":\s*"v[^"]+"' \ + | sed -E 's/.*"v([^"]+)".*/\1/' \ + | head -n1)" || true + fi + + [[ -n "$ver" ]] || { echo "[xray] Failed to get version"; return 1; } + url="$(xray_url_for_rid "$rid" "$ver")" || { echo "[xray] Unsupported RID: $rid"; return 1; } + + echo "[+] Download xray: $url" + + tmp="$(mktemp -d)" + curl -fL "$url" -o "$tmp/xray.zip" || { rm -rf "$tmp"; return 1; } + unzip -q "$tmp/xray.zip" -d "$tmp" || { rm -rf "$tmp"; return 1; } + install -m 755 "$tmp/xray" "$outdir/xray" || { rm -rf "$tmp"; return 1; } + rm -rf "$tmp" +} + +download_singbox() { + local outdir="$1" + local rid="$2" + local ver="${SING_VER:-}" + local url="" + local tmp="" + local bin="" + local cronet="" + + mkdir -p "$outdir" + + if [[ -z "$ver" ]]; then + ver="$(curl -fsSL https://api.github.com/repos/SagerNet/sing-box/releases/latest \ + | grep -Eo '"tag_name":\s*"v[^"]+"' \ + | sed -E 's/.*"v([^"]+)".*/\1/' \ + | head -n1)" || true + fi + + [[ -n "$ver" ]] || { echo "[sing-box] Failed to get version"; return 1; } + url="$(singbox_url_for_rid "$rid" "$ver")" || { echo "[sing-box] Unsupported RID: $rid"; return 1; } + + echo "[+] Download sing-box: $url" + + tmp="$(mktemp -d)" + curl -fL "$url" -o "$tmp/singbox.tar.gz" || { rm -rf "$tmp"; return 1; } + tar -C "$tmp" -xzf "$tmp/singbox.tar.gz" || { rm -rf "$tmp"; return 1; } + + bin="$(find "$tmp" -type f -name 'sing-box' | head -n1 || true)" + [[ -n "$bin" ]] || { echo "[!] sing-box unpack failed"; rm -rf "$tmp"; return 1; } + + install -m 755 "$bin" "$outdir/sing-box" || { rm -rf "$tmp"; return 1; } + + cronet="$(find "$tmp" -type f -name 'libcronet*.so*' | head -n1 || true)" + [[ -n "$cronet" ]] && install -m 644 "$cronet" "$outdir/libcronet.so" || true + + rm -rf "$tmp" +} + +unify_geo_layout() { + local outroot="$1" + local n + local names=( + geosite.dat + geoip.dat + geoip-only-cn-private.dat + Country.mmdb + geoip.metadb + ) + + mkdir -p "$outroot/bin" + + for n in "${names[@]}"; do + if [[ -f "$outroot/bin/xray/$n" ]]; then + mv -f "$outroot/bin/xray/$n" "$outroot/bin/$n" + fi + done +} + +download_geo_assets() { + local outroot="$1" + local bin_dir="$outroot/bin" + local srss_dir="$bin_dir/srss" + local f="" + + mkdir -p "$bin_dir" "$srss_dir" + + echo "[+] Download Xray Geo to ${bin_dir}" + curl -fsSL -o "$bin_dir/geosite.dat" "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geosite.dat" + curl -fsSL -o "$bin_dir/geoip.dat" "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geoip.dat" + curl -fsSL -o "$bin_dir/geoip-only-cn-private.dat" "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat" + curl -fsSL -o "$bin_dir/Country.mmdb" "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb" + + echo "[+] Download sing-box rule DB & rule-sets" + curl -fsSL -o "$bin_dir/geoip.metadb" "https://github.com/MetaCubeX/meta-rules-dat/releases/latest/download/geoip.metadb" + + for f in geoip-private.srs geoip-cn.srs geoip-facebook.srs geoip-fastly.srs geoip-google.srs geoip-netflix.srs geoip-telegram.srs geoip-twitter.srs; do + curl -fsSL -o "$srss_dir/$f" "https://raw.githubusercontent.com/2dust/sing-box-rules/refs/heads/rule-set-geoip/$f" + done + + for f in geosite-cn.srs geosite-gfw.srs geosite-google.srs geosite-greatfire.srs geosite-geolocation-cn.srs geosite-category-ads-all.srs geosite-private.srs; do + curl -fsSL -o "$srss_dir/$f" "https://raw.githubusercontent.com/2dust/sing-box-rules/refs/heads/rule-set-geosite/$f" + done + + unify_geo_layout "$outroot" +} + +populate_assets_zip_mode() { + local outroot="$1" + local rid="$2" + local url="" + local tmp="" + local nested_dir="" + + url="$(bundle_url_for_rid "$rid")" || { echo "[!] Bundle unsupported RID: $rid"; return 1; } + + echo "[+] Try v2rayN bundle archive: $url" + + tmp="$(mktemp -d)" + curl -fL "$url" -o "$tmp/v2rayn.zip" || { echo "[!] Bundle download failed"; rm -rf "$tmp"; return 1; } + unzip -q "$tmp/v2rayn.zip" -d "$tmp" || { echo "[!] Bundle unzip failed"; rm -rf "$tmp"; return 1; } + + if [[ -d "$tmp/bin" ]]; then + mkdir -p "$outroot/bin" + rsync -a "$tmp/bin/" "$outroot/bin/" + else + rsync -a "$tmp/" "$outroot/" + fi + + rm -f "$outroot/v2rayn.zip" 2>/dev/null || true + find "$outroot" -type d -name "mihomo" -prune -exec rm -rf {} + 2>/dev/null || true + + nested_dir="$(find "$outroot" -maxdepth 1 -type d -name 'v2rayN-linux-*' | head -n1 || true)" + if [[ -n "$nested_dir" && -d "$nested_dir/bin" ]]; then + mkdir -p "$outroot/bin" + rsync -a "$nested_dir/bin/" "$outroot/bin/" + rm -rf "$nested_dir" + fi + + unify_geo_layout "$outroot" + rm -rf "$tmp" + + echo "[+] Bundle extracted to $outroot" +} + +populate_assets_netcore_mode() { + local outroot="$1" + local rid="$2" + + mkdir -p "$outroot/bin/xray" "$outroot/bin/sing_box" + + if [[ "$WITH_CORE" == "xray" || "$WITH_CORE" == "both" ]]; then + download_xray "$outroot/bin/xray" "$rid" || echo "[!] xray download failed (skipped)" + fi + + if [[ "$WITH_CORE" == "sing-box" || "$WITH_CORE" == "both" ]]; then + download_singbox "$outroot/bin/sing_box" "$rid" || echo "[!] sing-box download failed (skipped)" + fi + + download_geo_assets "$outroot" || echo "[!] Geo rules download failed (skipped)" +} + +stage_runtime_assets() { + local outroot="$1" + local rid="$2" + + mkdir -p "$outroot/bin/xray" "$outroot/bin/sing_box" + + if [[ "$FORCE_NETCORE" -eq 0 ]]; then + if populate_assets_zip_mode "$outroot" "$rid"; then + echo "[*] Using v2rayN bundle archive." + else + echo "[*] Bundle failed, fallback to separate core + rules." + populate_assets_netcore_mode "$outroot" "$rid" + fi + else + echo "[*] --netcore specified: use separate core + rules." + populate_assets_netcore_mode "$outroot" "$rid" + fi +} + +describe_target() { + local short="$1" + + case "$short" in + loongarch64) printf '%s\n%s\n' "linux-loongarch64" "loong64" ;; + *) echo "Unknown arch '$short' (use loongarch64)" >&2; return 1 ;; + esac +} + +publish_binary() { + local rid="$1" + + dotnet clean "$PROJECT" -c Release + rm -rf "$(dirname "$PROJECT")/bin/Release/net10.0" || true + dotnet restore "$PROJECT" + dotnet publish "$PROJECT" -c Release -r "$rid" -p:PublishSingleFile=false -p:SelfContained=true +} + +write_launcher_file() { + local stage="$1" + + install -m 755 /dev/stdin "$stage/usr/bin/v2rayn" <<'EOF' +#!/usr/bin/env bash +set -euo pipefail +DIR="/opt/v2rayN" +cd "$DIR" + +if [[ -x "$DIR/v2rayN" ]]; then + exec "$DIR/v2rayN" "$@" +fi + +for dll in v2rayN.Desktop.dll v2rayN.dll; do + if [[ -f "$DIR/$dll" ]]; then + exec /usr/bin/dotnet "$DIR/$dll" "$@" + fi +done + +echo "v2rayN launcher: no executable found in $DIR" >&2 +ls -l "$DIR" >&2 || true +exit 1 +EOF +} + +write_desktop_file() { + local stage="$1" + + install -m 644 /dev/stdin "$stage/usr/share/applications/v2rayn.desktop" <<'EOF' +[Desktop Entry] +Type=Application +Name=v2rayN +Comment=v2rayN for Debian GNU Linux +Exec=v2rayn +Icon=v2rayn +Terminal=false +Categories=Network; +EOF +} + +write_maintainer_scripts() { + local debian_dir="$1" + + install -m 755 /dev/stdin "$debian_dir/postinst" <<'EOF' +#!/bin/sh +set -e +update-desktop-database /usr/share/applications >/dev/null 2>&1 || true +if command -v gtk-update-icon-cache >/dev/null 2>&1; then + gtk-update-icon-cache -f /usr/share/icons/hicolor >/dev/null 2>&1 || true +fi +exit 0 +EOF + + install -m 755 /dev/stdin "$debian_dir/postrm" <<'EOF' +#!/bin/sh +set -e +update-desktop-database /usr/share/applications >/dev/null 2>&1 || true +if command -v gtk-update-icon-cache >/dev/null 2>&1; then + gtk-update-icon-cache -f /usr/share/icons/hicolor >/dev/null 2>&1 || true +fi +exit 0 +EOF +} + +package_binary() { + local short="$1" + local rid="$2" + local deb_arch="$3" + local pubdir="" + local workdir="" + local stage="" + local debian_dir="" + local project_dir="" + local icon_candidate="" + local shlibs_depends="" + local extra_depends="" + local final_depends="" + local multiarch="" + local sys_libdir="" + local sys_usrlibdir="" + local deb_out="" + + pubdir="$(dirname "$PROJECT")/bin/Release/net10.0/${rid}/publish" + [[ -d "$pubdir" ]] || { echo "Publish directory not found: $pubdir"; return 1; } + + workdir="$(mktemp -d)" + trap '[[ -n "${workdir:-}" ]] && rm -rf "$workdir"' RETURN + + stage="$workdir/${PKGROOT}_${VERSION}_${deb_arch}" + debian_dir="$stage/DEBIAN" + + mkdir -p "$stage/opt/v2rayN" "$stage/usr/bin" "$stage/usr/share/applications" "$stage/usr/share/icons/hicolor/256x256/apps" "$debian_dir" + cp -a "$pubdir/." "$stage/opt/v2rayN/" + + project_dir="$(cd "$(dirname "$PROJECT")" && pwd)" + icon_candidate="$project_dir/v2rayN.png" + [[ -f "$icon_candidate" ]] && cp "$icon_candidate" "$stage/usr/share/icons/hicolor/256x256/apps/v2rayn.png" || true + + stage_runtime_assets "$stage/opt/v2rayN" "$rid" + write_launcher_file "$stage" + write_desktop_file "$stage" + write_maintainer_scripts "$debian_dir" + + extra_depends="libc6 (>= 2.34), fontconfig (>= 2.13.1), desktop-file-utils (>= 0.26), xdg-utils (>= 1.1.3), coreutils (>= 8.32), bash (>= 5.1), libfreetype6 (>= 2.11)" + + mkdir -p "$workdir/debian" + cat > "$workdir/debian/control" < +Standards-Version: 4.7.0 + +Package: v2rayn +Architecture: ${deb_arch} +Description: v2rayN +EOF + + multiarch="$(dpkg-architecture -a"$deb_arch" -qDEB_HOST_MULTIARCH)" + sys_libdir="/lib/$multiarch" + sys_usrlibdir="/usr/lib/$multiarch" + + : > "$debian_dir/substvars" + + mapfile -t ELF_FILES < <( + find "$stage/opt/v2rayN" -type f \( -name "*.so*" -o -perm -111 \) ! -name 'libcoreclrtraceptprovider.so' + ) + + if [[ "${#ELF_FILES[@]}" -gt 0 ]]; then + ( + cd "$workdir" + dpkg-shlibdeps \ + -l"$stage/opt/v2rayN" \ + -l"$sys_libdir" \ + -l"$sys_usrlibdir" \ + -T"$debian_dir/substvars" \ + "${ELF_FILES[@]}" + ) >/dev/null 2>&1 || true + fi + + shlibs_depends="$(sed -n 's/^shlibs:Depends=//p' "$debian_dir/substvars" | head -n1 || true)" + + if [[ -n "$shlibs_depends" ]]; then + shlibs_depends="$(echo "$shlibs_depends" \ + | sed -E 's/ *\([^)]*\)//g' \ + | sed -E 's/ *, */, /g' \ + | sed -E 's/^, *//; s/, *$//')" + final_depends="${shlibs_depends}, ${extra_depends}" + else + final_depends="${extra_depends}" + fi + + cat > "$debian_dir/control" < +Homepage: https://github.com/2dust/v2rayN +Section: net +Priority: optional +Depends: ${final_depends} +Description: v2rayN (Avalonia) GUI client for Linux + Support vless / vmess / Trojan / http / socks / Anytls / Hysteria2 / + Shadowsocks / tuic / WireGuard. +EOF + + find "$stage/opt/v2rayN" -type d -exec chmod 0755 {} + + find "$stage/opt/v2rayN" -type f -exec chmod 0644 {} + + [[ -f "$stage/opt/v2rayN/v2rayN" ]] && chmod 0755 "$stage/opt/v2rayN/v2rayN" || true + + deb_out="$OUTPUT_DIR/v2rayn_${VERSION}_${deb_arch}.deb" + dpkg-deb --root-owner-group --build "$stage" "$deb_out" + + echo "Build done for $short. DEB at:" + echo " $deb_out" + BUILT_DEBS+=("$deb_out") +} + +select_targets() { + printf '%s\n' loongarch64 +} + +build_one_target() { + local short="$1" + local meta=() + local rid="" + local deb_arch="" + + mapfile -t meta < <(describe_target "$short") || return 1 + rid="${meta[0]}" + deb_arch="${meta[1]}" + + echo "[*] Building for target: $short (RID=$rid, DEB arch=$deb_arch)" + publish_binary "$rid" + package_binary "$short" "$rid" "$deb_arch" +} + +print_summary() { + local pkg="" + + echo "" + echo "================ Build Summary =================" + if [[ "${#BUILT_DEBS[@]}" -gt 0 ]]; then + echo "Output directory: $OUTPUT_DIR" + for pkg in "${BUILT_DEBS[@]}"; do + echo "$pkg" + done + else + echo "No DEBs detected in summary (check build logs above)." + fi + echo "===============================================" +} + +main() { + local targets=() + local arch="" + + parse_args "$@" + detect_environment + install_dependencies + prepare_workspace + resolve_version + + mapfile -t targets < <(select_targets) + + for arch in "${targets[@]}"; do + build_one_target "$arch" + done + + print_summary +} + +main "$@" diff --git a/package-debian-riscv.sh b/package-debian-riscv.sh index bcdde11f..e9fcb628 100644 --- a/package-debian-riscv.sh +++ b/package-debian-riscv.sh @@ -12,13 +12,10 @@ MIN_KERNEL="5.10" PKGROOT="v2rayN-publish" PROJECT_HINT="v2rayN.Desktop/v2rayN.Desktop.csproj" OUTPUT_DIR="${HOME}/debbuild" -DOTNET_TFM="net10.0" DOTNET_RISCV_VERSION="10.0.108" DOTNET_RISCV_BASE="https://github.com/xujiegb/dotnet-riscv/releases/download" DOTNET_RISCV_FILE="dotnet-sdk-${DOTNET_RISCV_VERSION}-linux-riscv64.tar.gz" DOTNET_SDK_URL="${DOTNET_RISCV_BASE}/${DOTNET_RISCV_VERSION}/${DOTNET_RISCV_FILE}" -SKIA_VER="${SKIA_VER:-3.119.2}" -HARFBUZZ_VER="${HARFBUZZ_VER:-8.3.1.3}" OS_ID="" OS_NAME="" @@ -27,7 +24,6 @@ HOST_ARCH="" SCRIPT_DIR="" PROJECT="" VERSION="" -BUILT_ALL=0 declare -a BUILT_DEBS=() @@ -261,70 +257,6 @@ resolve_version() { echo "[*] GUI version resolved as: ${VERSION}" } -apply_riscv_patch() { - local f="" - - find . -type f \( -name "*.csproj" -o -name "*.props" -o -name "*.targets" \) \ - -exec sed -Ei 's#[^<]+#'"$DOTNET_TFM"'#g' {} + - - while IFS= read -r -d '' f; do - sed -i \ - -e "s###g" \ - -e "s###g" \ - -e "s###g" \ - -e "s###g" \ - "$f" - - grep -q 'PackageVersion Include="SkiaSharp"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - - grep -q 'PackageVersion Include="SkiaSharp.NativeAssets.Linux"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - - grep -q 'PackageVersion Include="HarfBuzzSharp"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - - grep -q 'PackageVersion Include="HarfBuzzSharp.NativeAssets.Linux"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - done < <(find . -type f -name 'Directory.Packages.props' -print0) - - f="$(find "$DOTNET_ROOT/sdk/$(dotnet --version)" -type f -name 'Microsoft.NETCoreSdk.BundledVersions.props' | head -n1 || true)" - if [[ -f "$f" ]] && ! grep -q 'linux-riscv64' "$f"; then - sed -i \ - -e 's/linux-arm64/&;linux-riscv64/g' \ - -e 's/linux-musl-arm64/&;linux-musl-riscv64/g' \ - "$f" - fi -} - -copy_skiasharp_native_riscv64() { - local outdir="$1" - local skia_so="" - local harfbuzz_so="" - - mkdir -p "$outdir" - - skia_so="$(find "$HOME/.nuget/packages" -path "*/skiasharp.nativeassets.linux/${SKIA_VER}/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" - [[ -n "$skia_so" ]] || skia_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" - - harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/harfbuzzsharp.nativeassets.linux/${HARFBUZZ_VER}/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" - [[ -n "$harfbuzz_so" ]] || harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" - - if [[ -n "$skia_so" && -f "$skia_so" ]]; then - echo "[+] Copy libSkiaSharp.so from NuGet cache" - install -m 755 "$skia_so" "$outdir/libSkiaSharp.so" - else - echo "[WARN] libSkiaSharp.so for linux-riscv64 not found in NuGet cache" - fi - - if [[ -n "$harfbuzz_so" && -f "$harfbuzz_so" ]]; then - echo "[+] Copy libHarfBuzzSharp.so from NuGet cache" - install -m 755 "$harfbuzz_so" "$outdir/libHarfBuzzSharp.so" - else - echo "[WARN] libHarfBuzzSharp.so for linux-riscv64 not found in NuGet cache" - fi -} - xray_url_for_rid() { local rid="$1" local ver="$2" @@ -554,10 +486,10 @@ describe_target() { publish_binary() { local rid="$1" - dotnet clean "$PROJECT" -c Release -p:TargetFramework="$DOTNET_TFM" - rm -rf "$(dirname "$PROJECT")/bin/Release/${DOTNET_TFM}" || true - dotnet restore "$PROJECT" -r "$rid" -p:TargetFramework="$DOTNET_TFM" - dotnet publish "$PROJECT" -c Release -r "$rid" -p:TargetFramework="$DOTNET_TFM" -p:PublishSingleFile=false -p:SelfContained=true + dotnet clean "$PROJECT" -c Release + rm -rf "$(dirname "$PROJECT")/bin/Release/net10.0" || true + dotnet restore "$PROJECT" + dotnet publish "$PROJECT" -c Release -r "$rid" -p:PublishSingleFile=false -p:SelfContained=true } write_launcher_file() { @@ -567,7 +499,6 @@ write_launcher_file() { #!/usr/bin/env bash set -euo pipefail DIR="/opt/v2rayN" -export LD_LIBRARY_PATH="$DIR:${LD_LIBRARY_PATH:-}" cd "$DIR" if [[ -x "$DIR/v2rayN" ]]; then @@ -643,7 +574,7 @@ package_binary() { local sys_usrlibdir="" local deb_out="" - pubdir="$(dirname "$PROJECT")/bin/Release/${DOTNET_TFM}/${rid}/publish" + pubdir="$(dirname "$PROJECT")/bin/Release/net10.0/${rid}/publish" [[ -d "$pubdir" ]] || { echo "Publish directory not found: $pubdir"; return 1; } workdir="$(mktemp -d)" @@ -655,8 +586,6 @@ package_binary() { mkdir -p "$stage/opt/v2rayN" "$stage/usr/bin" "$stage/usr/share/applications" "$stage/usr/share/icons/hicolor/256x256/apps" "$debian_dir" cp -a "$pubdir/." "$stage/opt/v2rayN/" - copy_skiasharp_native_riscv64 "$stage/opt/v2rayN" || echo "[!] SkiaSharp native copy failed (skipped)" - project_dir="$(cd "$(dirname "$PROJECT")" && pwd)" icon_candidate="$project_dir/v2rayN.png" [[ -f "$icon_candidate" ]] && cp "$icon_candidate" "$stage/usr/share/icons/hicolor/256x256/apps/v2rayn.png" || true @@ -732,9 +661,7 @@ EOF find "$stage/opt/v2rayN" -type d -exec chmod 0755 {} + find "$stage/opt/v2rayN" -type f -exec chmod 0644 {} + [[ -f "$stage/opt/v2rayN/v2rayN" ]] && chmod 0755 "$stage/opt/v2rayN/v2rayN" || true - [[ -f "$stage/opt/v2rayN/libSkiaSharp.so" ]] && chmod 0755 "$stage/opt/v2rayN/libSkiaSharp.so" || true - [[ -f "$stage/opt/v2rayN/libHarfBuzzSharp.so" ]] && chmod 0755 "$stage/opt/v2rayN/libHarfBuzzSharp.so" || true - + deb_out="$OUTPUT_DIR/v2rayn_${VERSION}_${deb_arch}.deb" dpkg-deb --root-owner-group --build "$stage" "$deb_out" @@ -787,7 +714,6 @@ main() { install_dependencies prepare_workspace resolve_version - apply_riscv_patch mapfile -t targets < <(select_targets) diff --git a/package-rhel-riscv.sh b/package-rhel-riscv.sh index d1137f76..9c4fa03f 100644 --- a/package-rhel-riscv.sh +++ b/package-rhel-riscv.sh @@ -12,13 +12,10 @@ MIN_KERNEL="5.10" PKGROOT="v2rayN-publish" PROJECT_HINT="v2rayN.Desktop/v2rayN.Desktop.csproj" RPM_TOPDIR="${HOME}/rpmbuild" -DOTNET_TFM="net10.0" DOTNET_RISCV_VERSION="10.0.108" DOTNET_RISCV_BASE="https://github.com/xujiegb/dotnet-riscv/releases/download" DOTNET_RISCV_FILE="dotnet-sdk-${DOTNET_RISCV_VERSION}-linux-riscv64.tar.gz" DOTNET_SDK_URL="${DOTNET_RISCV_BASE}/${DOTNET_RISCV_VERSION}/${DOTNET_RISCV_FILE}" -SKIA_VER="${SKIA_VER:-3.119.2}" -HARFBUZZ_VER="${HARFBUZZ_VER:-8.3.1.3}" OS_ID="" OS_NAME="" @@ -27,7 +24,6 @@ HOST_ARCH="" SCRIPT_DIR="" PROJECT="" VERSION="" -BUILT_ALL=0 declare -a BUILT_RPMS=() @@ -258,70 +254,6 @@ resolve_version() { echo "[*] GUI version resolved as: ${VERSION}" } -apply_riscv_patch() { - local f="" - - find . -type f \( -name "*.csproj" -o -name "*.props" -o -name "*.targets" \) \ - -exec sed -Ei 's#[^<]+#'"$DOTNET_TFM"'#g' {} + - - while IFS= read -r -d '' f; do - sed -i \ - -e "s###g" \ - -e "s###g" \ - -e "s###g" \ - -e "s###g" \ - "$f" - - grep -q 'PackageVersion Include="SkiaSharp"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - - grep -q 'PackageVersion Include="SkiaSharp.NativeAssets.Linux"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - - grep -q 'PackageVersion Include="HarfBuzzSharp"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - - grep -q 'PackageVersion Include="HarfBuzzSharp.NativeAssets.Linux"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - done < <(find . -type f -name 'Directory.Packages.props' -print0) - - f="$(find "$DOTNET_ROOT/sdk/$(dotnet --version)" -type f -name 'Microsoft.NETCoreSdk.BundledVersions.props' | head -n1 || true)" - if [[ -f "$f" ]] && ! grep -q 'linux-riscv64' "$f"; then - sed -i \ - -e 's/linux-arm64/&;linux-riscv64/g' \ - -e 's/linux-musl-arm64/&;linux-musl-riscv64/g' \ - "$f" - fi -} - -copy_skiasharp_native_riscv64() { - local outdir="$1" - local skia_so="" - local harfbuzz_so="" - - mkdir -p "$outdir" - - skia_so="$(find "$HOME/.nuget/packages" -path "*/skiasharp.nativeassets.linux/${SKIA_VER}/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" - [[ -n "$skia_so" ]] || skia_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" - - harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/harfbuzzsharp.nativeassets.linux/${HARFBUZZ_VER}/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" - [[ -n "$harfbuzz_so" ]] || harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" - - if [[ -n "$skia_so" && -f "$skia_so" ]]; then - echo "[+] Copy libSkiaSharp.so from NuGet cache" - install -m 755 "$skia_so" "$outdir/libSkiaSharp.so" - else - echo "[WARN] libSkiaSharp.so for linux-riscv64 not found in NuGet cache" - fi - - if [[ -n "$harfbuzz_so" && -f "$harfbuzz_so" ]]; then - echo "[+] Copy libHarfBuzzSharp.so from NuGet cache" - install -m 755 "$harfbuzz_so" "$outdir/libHarfBuzzSharp.so" - else - echo "[WARN] libHarfBuzzSharp.so for linux-riscv64 not found in NuGet cache" - fi -} - xray_url_for_rid() { local rid="$1" local ver="$2" @@ -551,10 +483,10 @@ describe_target() { publish_binary() { local rid="$1" - dotnet clean "$PROJECT" -c Release -p:TargetFramework="$DOTNET_TFM" - rm -rf "$(dirname "$PROJECT")/bin/Release/${DOTNET_TFM}" || true - dotnet restore "$PROJECT" -r "$rid" -p:TargetFramework="$DOTNET_TFM" - dotnet publish "$PROJECT" -c Release -r "$rid" -p:TargetFramework="$DOTNET_TFM" -p:PublishSingleFile=false -p:SelfContained=true + dotnet clean "$PROJECT" -c Release + rm -rf "$(dirname "$PROJECT")/bin/Release/net10.0" || true + dotnet restore "$PROJECT" + dotnet publish "$PROJECT" -c Release -r "$rid" -p:PublishSingleFile=false -p:SelfContained=true } write_spec_file() { @@ -604,15 +536,12 @@ cp -a * %{buildroot}/opt/v2rayN/ find %{buildroot}/opt/v2rayN -type d -exec chmod 0755 {} + find %{buildroot}/opt/v2rayN -type f -exec chmod 0644 {} + [ -f %{buildroot}/opt/v2rayN/v2rayN ] && chmod 0755 %{buildroot}/opt/v2rayN/v2rayN || : -[ -f %{buildroot}/opt/v2rayN/libSkiaSharp.so ] && chmod 0755 %{buildroot}/opt/v2rayN/libSkiaSharp.so || : -[ -f %{buildroot}/opt/v2rayN/libHarfBuzzSharp.so ] && chmod 0755 %{buildroot}/opt/v2rayN/libHarfBuzzSharp.so || : install -dm0755 %{buildroot}%{_bindir} install -m0755 /dev/stdin %{buildroot}%{_bindir}/v2rayn << 'EOF' #!/usr/bin/bash set -euo pipefail DIR="/opt/v2rayN" -export LD_LIBRARY_PATH="$DIR:${LD_LIBRARY_PATH:-}" if [[ -x "$DIR/v2rayN" ]]; then exec "$DIR/v2rayN" "$@"; fi @@ -673,7 +602,7 @@ package_binary() { local icon_candidate="" local f="" - pubdir="$(dirname "$PROJECT")/bin/Release/${DOTNET_TFM}/${rid}/publish" + pubdir="$(dirname "$PROJECT")/bin/Release/net10.0/${rid}/publish" [[ -d "$pubdir" ]] || { echo "Publish directory not found: $pubdir"; return 1; } workdir="$(mktemp -d)" @@ -682,8 +611,6 @@ package_binary() { mkdir -p "$workdir/$PKGROOT" cp -a "$pubdir/." "$workdir/$PKGROOT/" - copy_skiasharp_native_riscv64 "$workdir/$PKGROOT" || echo "[!] SkiaSharp native copy failed (skipped)" - project_dir="$(cd "$(dirname "$PROJECT")" && pwd)" icon_candidate="$project_dir/v2rayN.png" [[ -f "$icon_candidate" ]] || { echo "Required icon not found: $icon_candidate"; return 1; } @@ -755,7 +682,6 @@ main() { install_dependencies prepare_workspace resolve_version - apply_riscv_patch mapfile -t targets < <(select_targets) diff --git a/v2rayN/Directory.Packages.props b/v2rayN/Directory.Packages.props index ed4c1989..a136d4d7 100644 --- a/v2rayN/Directory.Packages.props +++ b/v2rayN/Directory.Packages.props @@ -34,6 +34,6 @@ - +