ci: build windows asset in docker
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user