ci: build windows asset in docker
Release / Prepare release (push) Successful in 6s
Release / Build release assets (push) Has been cancelled

This commit is contained in:
chuan
2026-05-09 23:14:59 +08:00
Unverified
parent cde74ce27f
commit d2ae9671ce
2 changed files with 41 additions and 75 deletions
+11 -69
View File
@@ -13,6 +13,7 @@ env:
GITEA_SERVER_URL: https://git.pchuan.top
RUST_IMAGE: docker.m.daocloud.io/library/rust:1-bookworm
CARGO_REGISTRY: sparse+https://rsproxy.cn/index/
APT_MIRROR: https://mirrors.ustc.edu.cn/ubuntu
CARGO_TERM_COLOR: always
jobs:
@@ -116,88 +117,28 @@ jobs:
echo "RELEASE_TAG=${release_tag}" >> "${GITHUB_ENV}"
echo "VERSION=${release_tag#v}" >> "${GITHUB_ENV}"
- name: Configure Cargo mirror
- name: Build release assets
shell: bash
run: |
set -euo pipefail
mkdir -p "${HOME}/.cargo"
cat > "${HOME}/.cargo/config.toml" <<EOF
[source.crates-io]
replace-with = "mirror"
[source.mirror]
registry = "${CARGO_REGISTRY}"
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
ar = "x86_64-w64-mingw32-ar"
EOF
- name: Install Windows cross compile dependencies
shell: bash
run: |
set -euo pipefail
apt_run() {
if command -v sudo >/dev/null 2>&1; then
sudo "$@"
else
"$@"
fi
}
rewrite_apt_sources() {
local files=()
[[ -f /etc/apt/sources.list ]] && files+=(/etc/apt/sources.list)
while IFS= read -r file; do
files+=("${file}")
done < <(find /etc/apt/sources.list.d -type f \( -name "*.list" -o -name "*.sources" \) 2>/dev/null)
if [[ "${#files[@]}" -gt 0 ]]; then
apt_run sed -i \
-e 's|http://archive.ubuntu.com/ubuntu|https://mirrors.ustc.edu.cn/ubuntu|g' \
-e 's|https://archive.ubuntu.com/ubuntu|https://mirrors.ustc.edu.cn/ubuntu|g' \
-e 's|http://security.ubuntu.com/ubuntu|https://mirrors.ustc.edu.cn/ubuntu|g' \
-e 's|https://security.ubuntu.com/ubuntu|https://mirrors.ustc.edu.cn/ubuntu|g' \
-e 's|http://ports.ubuntu.com/ubuntu-ports|https://mirrors.ustc.edu.cn/ubuntu-ports|g' \
-e 's|https://ports.ubuntu.com/ubuntu-ports|https://mirrors.ustc.edu.cn/ubuntu-ports|g' \
"${files[@]}"
fi
}
rewrite_apt_sources
apt_run apt-get update
apt_run apt-get install -y --no-install-recommends binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64-posix mingw-w64-x86-64-dev
rustup target add x86_64-pc-windows-gnu
- name: Build Windows x64
shell: bash
run: |
set -euo pipefail
mkdir -p dist
cargo build --release --target x86_64-pc-windows-gnu
cp target/x86_64-pc-windows-gnu/release/cdxs.exe "dist/cdxs-${VERSION}-windows-x64.exe"
- name: Build Linux assets
shell: bash
run: |
set -euo pipefail
build_linux() {
build_asset() {
local target_name="$1"
local rust_target="$2"
local platform="$3"
local container_binary="$4"
local output_name="$5"
local image_tag="cdxs-build:${target_name}-${GITHUB_RUN_ID:-manual}"
local container_name="cdxs-build-${target_name}-${GITHUB_RUN_ID:-manual}"
mkdir -p dist
docker buildx build \
--platform "${platform}" \
--target builder \
--build-arg "RUST_TARGET=${rust_target}" \
--build-arg "RUST_IMAGE=${RUST_IMAGE}" \
--build-arg "CARGO_REGISTRY=${CARGO_REGISTRY}" \
--build-arg "APT_MIRROR=${APT_MIRROR}" \
--load \
-t "${image_tag}" \
-f scripts/docker/Dockerfile.release \
@@ -205,12 +146,13 @@ jobs:
local container_id
container_id="$(docker create --name "${container_name}" "${image_tag}")"
docker cp "${container_id}:/out/cdxs" "dist/cdxs-${VERSION}-${target_name}"
docker cp "${container_id}:/out/${container_binary}" "dist/${output_name}"
docker rm -f "${container_name}" >/dev/null
}
build_linux linux-x64 x86_64-unknown-linux-gnu linux/amd64
build_linux linux-arm64 aarch64-unknown-linux-gnu linux/arm64
build_asset windows-x64 x86_64-pc-windows-gnu linux/amd64 cdxs.exe "cdxs-${VERSION}-windows-x64.exe"
build_asset linux-x64 x86_64-unknown-linux-gnu linux/amd64 cdxs "cdxs-${VERSION}-linux-x64"
build_asset linux-arm64 aarch64-unknown-linux-gnu linux/arm64 cdxs "cdxs-${VERSION}-linux-arm64"
- name: Upload release assets
shell: bash
+30 -6
View File
@@ -3,26 +3,50 @@ FROM --platform=$BUILDPLATFORM ${RUST_IMAGE} AS builder
ARG RUST_TARGET=x86_64-unknown-linux-gnu
ARG CARGO_REGISTRY=sparse+https://rsproxy.cn/index/
ARG APT_MIRROR=https://mirrors.ustc.edu.cn/ubuntu
WORKDIR /app
RUN mkdir -p /usr/local/cargo \
&& printf '[source.crates-io]\nreplace-with = "mirror"\n\n[source.mirror]\nregistry = "%s"\n' "${CARGO_REGISTRY}" > /usr/local/cargo/config.toml
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
gcc-aarch64-linux-gnu \
libc6-dev-arm64-cross \
RUN find /etc/apt/sources.list.d -type f \( -name "*.list" -o -name "*.sources" \) -print0 2>/dev/null \
| xargs -0 -r sed -i \
-e "s|http://archive.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
-e "s|https://archive.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
-e "s|http://security.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
-e "s|https://security.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
&& if [ -f /etc/apt/sources.list ]; then \
sed -i \
-e "s|http://archive.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
-e "s|https://archive.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
-e "s|http://security.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
-e "s|https://security.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
/etc/apt/sources.list; \
fi \
&& apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates \
&& case "${RUST_TARGET}" in \
aarch64-unknown-linux-gnu) \
apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu libc6-dev-arm64-cross ;; \
x86_64-pc-windows-gnu) \
apt-get install -y --no-install-recommends binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64-posix mingw-w64-x86-64-dev ;; \
esac \
&& rm -rf /var/lib/apt/lists/*
RUN rustup target add ${RUST_TARGET}
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
ENV CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc
ENV CARGO_TARGET_X86_64_PC_WINDOWS_GNU_AR=x86_64-w64-mingw32-ar
COPY Cargo.toml Cargo.lock ./
COPY src ./src
RUN cargo build --release --target ${RUST_TARGET} \
&& mkdir -p /out \
&& cp target/${RUST_TARGET}/release/cdxs /out/cdxs
&& if [ "${RUST_TARGET}" = "x86_64-pc-windows-gnu" ]; then \
cp target/${RUST_TARGET}/release/cdxs.exe /out/cdxs.exe; \
else \
cp target/${RUST_TARGET}/release/cdxs /out/cdxs; \
fi