Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
23 changes: 13 additions & 10 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
[build]
jobs=8

[net]
retry = 3
git-fetch-with-cli = true

[target.x86_64-pc-windows-gnu]
rustflags = [
"-C", "link-arg=-s",
"-C", "link-arg=-Wl,--gc-sections",
]

[target.i686-pc-windows-gnu]
[target.x86_64-pc-windows-msvc]
rustflags = [
"-C", "link-arg=-s",
"-C","link-arg=/DEBUG:NONE",
"-C", "target-feature=+crt-static",
]

[target.x86_64-pc-windows-msvc]
[target.i686-pc-windows-msvc]
rustflags = [
"-C", "link-arg=/DEBUG:NONE",
"-C", "link-args=/SUBSYSTEM:CONSOLE,5.01",
]

[target.'cfg(target_os = "macos")']
rustflags = [
"-C", "link-arg=-dead_strip"
]

[target.'cfg(not(target_os = "macos"))']
[target.'cfg(target_os = "linux")']
rustflags = [
"-C", "link-arg=-Wl,--gc-sections",
"-C", "link-arg=-Wl,--strip-all",
"-C", "link-arg=-Wl,--allow-multiple-definition",
]
]

# [target.'cfg(target_os = "windows")']
# rustflags = [
# "-C", "target-feature=+crt-static",
# ]
165 changes: 165 additions & 0 deletions .github/workflows/bundle-full-source.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
name: bundle-full-source

on:
workflow_dispatch:
inputs:
tag_name:
description: 'Release tag to bundle'
required: true
default: 'v0.0.1'
resource_asset_name:
description: 'Existing release asset name to merge into resources/'
required: true
default: 'resources.zip'
merge_strategy:
description: 'How to handle duplicate files under resources/'
required: true
type: choice
default: 'fail'
options:
- fail
- overwrite
bundle_asset_name:
description: 'Optional override for the uploaded bundle asset name'
required: false
default: ''

permissions:
contents: write

jobs:
bundle-full-source:
runs-on: ubuntu-22.04
env:
TAG_NAME: ${{ inputs.tag_name }}
RESOURCE_ASSET_NAME: ${{ inputs.resource_asset_name }}
MERGE_STRATEGY: ${{ inputs.merge_strategy }}
steps:
- name: Checkout tagged source
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag_name }}
submodules: recursive
fetch-depth: 0

- name: Install Rust toolchain for cargo vendor
uses: dtolnay/rust-toolchain@nightly

- name: Resolve bundle names
id: bundle_names
shell: bash
run: |
version="${TAG_NAME}"
root_dir="malefic-community-${version}-full-source"
bundle_name="${{ inputs.bundle_asset_name }}"

if [[ -z "$bundle_name" ]]; then
bundle_name="${root_dir}.zip"
fi

echo "ROOT_DIR=$root_dir" >> "$GITHUB_OUTPUT"
echo "BUNDLE_NAME=$bundle_name" >> "$GITHUB_OUTPUT"

- name: Download resource archive from release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
mkdir -p .release-assets
gh release download "$TAG_NAME" \
--repo "${GITHUB_REPOSITORY}" \
--pattern "$RESOURCE_ASSET_NAME" \
--dir .release-assets \
--clobber

test -f ".release-assets/$RESOURCE_ASSET_NAME"

- name: Merge resource archive into resources/
shell: bash
run: |
mkdir -p resources .bundle-work/resources-unpacked
unzip -q ".release-assets/$RESOURCE_ASSET_NAME" -d .bundle-work/resources-unpacked

shopt -s dotglob nullglob
extracted=(.bundle-work/resources-unpacked/*)
merge_root=".bundle-work/resources-unpacked"

if [[ ${#extracted[@]} -eq 1 && -d "${extracted[0]}" && "$(basename "${extracted[0]}")" == "resources" ]]; then
merge_root="${extracted[0]}"
fi

if [[ "$MERGE_STRATEGY" == "fail" ]]; then
conflicts=()

while IFS= read -r -d '' file; do
rel_path="${file#${merge_root}/}"
if [[ -e "resources/${rel_path}" ]]; then
conflicts+=("${rel_path}")
fi
done < <(find "$merge_root" -type f -print0)

if [[ ${#conflicts[@]} -gt 0 ]]; then
echo "::error::Detected conflicting resource files:"
printf ' - %s\n' "${conflicts[@]:0:20}"
if [[ ${#conflicts[@]} -gt 20 ]]; then
echo " - ... and $(( ${#conflicts[@]} - 20 )) more"
fi
exit 1
fi
fi

rsync -a "${merge_root}/" resources/

- name: Vendor Rust dependencies
shell: bash
run: |
mkdir -p .bundle-work .cargo

cargo vendor --locked --versioned-dirs vendor \
--sync examples/ffi/rust/Cargo.toml \
--sync examples/starship/Cargo.toml \
--sync lib/rage/Cargo.toml \
--sync malefic-3rd-template/Cargo.toml \
--sync malefic-proxydll/Cargo.toml \
--sync malefic-starship/Cargo.toml \
> .bundle-work/cargo-vendor-config.toml

if [[ -f .cargo/config.toml ]]; then
cp .cargo/config.toml .bundle-work/base-config.toml
printf '\n' >> .bundle-work/base-config.toml
cat .bundle-work/base-config.toml .bundle-work/cargo-vendor-config.toml > .cargo/config.toml
else
cp .bundle-work/cargo-vendor-config.toml .cargo/config.toml
fi

- name: Build complete source archive
shell: bash
run: |
root_dir="${{ steps.bundle_names.outputs.ROOT_DIR }}"
bundle_name="${{ steps.bundle_names.outputs.BUNDLE_NAME }}"
stage_dir="dist/${root_dir}"

mkdir -p "$stage_dir"
rsync -a ./ "$stage_dir"/ \
--exclude '.git' \
--exclude '.bundle-work' \
--exclude '.release-assets' \
--exclude 'dist' \
--exclude 'target' \
--exclude '.DS_Store'

(
cd dist
zip -qry -y "$bundle_name" "$root_dir"
)

- name: Upload complete source archive
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
bundle_name="${{ steps.bundle_names.outputs.BUNDLE_NAME }}"
gh release upload "$TAG_NAME" \
"dist/${bundle_name}" \
--repo "${GITHUB_REPOSITORY}" \
--clobber
157 changes: 157 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
name: check

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
workflow_dispatch:
inputs:
target:
description: '指定 target(留空跑全部)'
required: false
default: ''
phase:
description: 'check / feature / test / mutant / profile / all'
required: false
default: 'all'
toolchain:
description: 'Rust toolchain (e.g. nightly-2024-09-18)'
required: false
default: 'nightly-2024-09-18'

permissions:
contents: read

jobs:
check-linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-musl
- x86_64-pc-windows-gnu
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.GH_PAT }}

- name: Detect legacy check scripts
id: legacy_check
shell: bash
run: |
if [[ -f scripts/check/check.sh && -f scripts/check/profile.sh ]]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "Legacy scripts/check not found, skip legacy check steps."
fi

- name: Install Rust toolchain
if: steps.legacy_check.outputs.exists == 'true'
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ github.event.inputs.toolchain || 'nightly-2024-09-18' }}
targets: ${{ matrix.target }}

- name: Install cross-compilation tools
if: steps.legacy_check.outputs.exists == 'true'
run: |
sudo apt-get update
sudo apt-get install -y gcc-mingw-w64-x86-64 musl-tools protobuf-compiler
sudo ln -sf /usr/bin/musl-gcc /usr/local/bin/x86_64-linux-musl-gcc

- name: Rust cache
if: steps.legacy_check.outputs.exists == 'true'
uses: Swatinem/rust-cache@v2
with:
shared-key: "check-${{ matrix.target }}"
cache-targets: true
cache-all-crates: true
save-if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}

- name: Fix line endings
if: steps.legacy_check.outputs.exists == 'true'
run: |
sudo apt-get install -y dos2unix 2>/dev/null || true
find scripts/check -name '*.sh' -exec dos2unix {} + 2>/dev/null || \
find scripts/check -name '*.sh' -exec sed -i 's/\r$//' {} +

- name: Determine phase
id: phase
if: steps.legacy_check.outputs.exists == 'true'
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "value=${{ github.event.inputs.phase || 'all' }}" >> $GITHUB_OUTPUT
else
echo "value=test" >> $GITHUB_OUTPUT
fi

- name: Run checks
if: steps.legacy_check.outputs.exists == 'true'
run: |
chmod +x scripts/check/check.sh scripts/check/profile.sh
./scripts/check/check.sh --target ${{ matrix.target }} --phase ${{ steps.phase.outputs.value }} --ci

check-darwin:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.GH_PAT }}

- name: Detect legacy check scripts
id: legacy_check
shell: bash
run: |
if [[ -f scripts/check/check.sh && -f scripts/check/profile.sh ]]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "Legacy scripts/check not found, skip legacy check steps."
fi

- name: Install protobuf
if: steps.legacy_check.outputs.exists == 'true'
run: brew install protobuf

- name: Install Rust toolchain
if: steps.legacy_check.outputs.exists == 'true'
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ github.event.inputs.toolchain || 'nightly-2024-09-18' }}

- name: Rust cache
if: steps.legacy_check.outputs.exists == 'true'
uses: Swatinem/rust-cache@v2
with:
shared-key: "check-aarch64-apple-darwin"
cache-targets: true
cache-all-crates: true
save-if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}

- name: Fix line endings
if: steps.legacy_check.outputs.exists == 'true'
run: |
find scripts/check -name '*.sh' -exec sed -i '' 's/\r$//' {} +

- name: Determine phase
id: phase
if: steps.legacy_check.outputs.exists == 'true'
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "value=${{ github.event.inputs.phase || 'all' }}" >> $GITHUB_OUTPUT
else
echo "value=test" >> $GITHUB_OUTPUT
fi

- name: Run checks
if: steps.legacy_check.outputs.exists == 'true'
run: |
chmod +x scripts/check/check.sh scripts/check/profile.sh
./scripts/check/check.sh --target aarch64-apple-darwin --phase ${{ steps.phase.outputs.value }} --ci
Loading
Loading