Skip to content

Commit 6e7f857

Browse files
committed
feat: add CI & optimize: docs
1 parent 58ff0dc commit 6e7f857

52 files changed

Lines changed: 725 additions & 164 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
types: [opened, synchronize, reopened, labeled]
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
vet_build_test:
15+
name: Vet & Build
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
os: [ubuntu-latest, windows-latest]
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- uses: actions/setup-go@v5
25+
with:
26+
go-version-file: go.mod
27+
28+
- name: Find and remove all .cpp files
29+
run: |
30+
find . -name "*.cpp" -type f -delete
31+
shell: bash
32+
33+
- name: Run go vet
34+
run: go vet ./...
35+
36+
- name: Build all packages
37+
run: go build ./...
38+
39+
- name: Build cmd/gen
40+
run: go build ./cmd/gen
41+
42+
43+
run-test:
44+
name: Run Test (${{ matrix.name }})
45+
runs-on: ${{ matrix.os }}
46+
needs: [vet_build_test]
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
include:
51+
- os: ubuntu-latest
52+
name: Linux
53+
cmake_extra_args: -DCMAKE_INSTALL_PREFIX=/usr/local
54+
install_cmd: >-
55+
sudo cmake --install level-zero-build &&
56+
sudo cp level-zero-build/lib/libze_null.so /usr/local/lib/ &&
57+
sudo ldconfig
58+
- os: windows-latest
59+
name: Windows
60+
cmake_extra_args: ""
61+
install_cmd: >-
62+
for dll in $(find level-zero-build -name "*.dll");
63+
do cp "$dll" /c/Windows/System32/;
64+
done
65+
steps:
66+
- uses: actions/checkout@v4
67+
68+
- uses: actions/setup-go@v5
69+
with:
70+
go-version-file: go.mod
71+
72+
- name: Download Intel Level Zero Source Code
73+
shell: bash
74+
run: |
75+
# The apt runtime package (libze1) does NOT ship libze_null, which is
76+
# required for ZE_ENABLE_NULL_DRIVER=1. Build from source instead so the
77+
# loader and the null driver are both present
78+
RELEASE=$(curl -sf https://api.github.com/repos/oneapi-src/level-zero/releases/latest \
79+
| jq -r '.tag_name')
80+
git clone https://github.com/oneapi-src/level-zero.git --depth=1 \
81+
--branch "$RELEASE" level-zero-src
82+
83+
- name: Build & Install Intel Level Zero
84+
shell: bash
85+
run: |
86+
cmake -S level-zero-src -B level-zero-build \
87+
-DCMAKE_BUILD_TYPE=Release \
88+
-DBUILD_TESTING=OFF \
89+
${{ matrix.cmake_extra_args }}
90+
cmake --build level-zero-build --config Release --parallel $(nproc)
91+
${{ matrix.install_cmd }}
92+
93+
- name: Run examples
94+
shell: bash
95+
env:
96+
# Activate the Level Zero null driver (ze_null) so the loader
97+
# can enumerate a fake device on runners without real Intel GPU hardware.
98+
ZE_ENABLE_NULL_DRIVER: "1"
99+
run: go test -v -count=1 ./...
100+
101+
go-generate:
102+
name: Run all Generates & Commit
103+
runs-on: ubuntu-latest
104+
needs: [vet_build_test]
105+
steps:
106+
- uses: actions/checkout@v4
107+
with:
108+
ref: ${{ github.head_ref || github.ref_name }}
109+
token: ${{ secrets.GITHUB_TOKEN }}
110+
111+
- uses: actions/setup-go@v5
112+
with:
113+
go-version-file: go.mod
114+
115+
- name: Download SYCL Linux
116+
run: |
117+
wget -q -O /tmp/sycl_linux.tar.gz https://github.com/intel/llvm/releases/download/v6.3.0/sycl_linux.tar.gz
118+
mkdir -p /tmp/sycl_linux
119+
tar -xzf /tmp/sycl_linux.tar.gz -C /tmp/sycl_linux
120+
121+
- name: Add SYCL bin to PATH
122+
run: |
123+
ls -hl /tmp/sycl_linux
124+
echo "/tmp/sycl_linux/bin" >> $GITHUB_PATH
125+
126+
- name: Install ocloc
127+
run: |
128+
wget -qO- https://repositories.intel.com/gpu/intel-graphics.key \
129+
| sudo gpg --dearmor --output /usr/share/keyrings/intel-graphics.gpg
130+
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/gpu/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) unified" \
131+
| sudo tee /etc/apt/sources.list.d/intel-gpu.list
132+
sudo apt-get update -q
133+
sudo apt-get install -y intel-ocloc libigdfcl2 libigc2
134+
135+
- name: Run go generate
136+
run: |
137+
go generate ./...
138+
gofmt -w .
139+
140+
- name: Run golangci-lint
141+
uses: golangci/golangci-lint-action@v9
142+
with:
143+
version: v2.11
144+
args: --fix
145+
env:
146+
CGO_ENABLED: "0"
147+
148+
- name: Check for changes
149+
id: diff
150+
run: |
151+
if [ -n "$(git diff --name-only)" ]; then
152+
echo "changed=true" >> "$GITHUB_OUTPUT"
153+
fi
154+
155+
- name: Commit and push to PR branch
156+
if: steps.diff.outputs.changed == 'true' && github.event_name == 'pull_request'
157+
id: push_to_pr
158+
continue-on-error: true
159+
run: |
160+
git config user.name "github-actions[bot]"
161+
git config user.email "github-actions[bot]@users.noreply.github.com"
162+
git add -A
163+
git commit -m "chore: run go generate"
164+
git push
165+
166+
- name: Comment on PR if push failed
167+
if: steps.diff.outputs.changed == 'true' && github.event_name == 'pull_request' && steps.push_to_pr.outcome == 'failure'
168+
uses: actions/github-script@v7
169+
with:
170+
script: |
171+
github.rest.issues.createComment({
172+
issue_number: context.issue.number,
173+
owner: context.repo.owner,
174+
repo: context.repo.repo,
175+
body: '`go generate` produced file changes but could not be pushed automatically (likely a fork PR). Please run `go generate ./... && gofmt -w .` locally and push the changes.'
176+
})
177+
178+
- name: Create Pull Request
179+
if: steps.diff.outputs.changed == 'true' && github.event_name == 'push'
180+
uses: peter-evans/create-pull-request@v7
181+
with:
182+
token: ${{ secrets.GITHUB_TOKEN }}
183+
commit-message: "chore: run go generate"
184+
title: "chore: run go generate"
185+
body: |
186+
Automated PR created by CI.
187+
188+
`go generate .` detected generated file differences and applied updates.
189+
branch: auto/go-generate
190+
delete-branch: true
191+

.golangci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
version: "2"
2+
3+
formatters:
4+
enable:
5+
- gofmt
6+
- goimports
7+
8+
linters:
9+
default: none
10+
enable:
11+
- errcheck
12+
- staticcheck
13+
- govet
14+
- ineffassign
15+
- unused
16+
- misspell
17+
- unconvert
18+
- revive
19+
exclusions:
20+
rules:
21+
- path: \.cpp$
22+
linters:
23+
- typecheck
24+
- path: ^cmd/
25+
linters:
26+
- errcheck
27+
- staticcheck
28+
- govet
29+
- ineffassign
30+
- unused
31+
- misspell
32+
- unconvert
33+
- revive
34+
- linters:
35+
- errcheck
36+
source: "^\\s*defer "
37+
38+
issues:
39+
max-issues-per-linter: 0
40+
max-same-issues: 0

bezier.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func quadraticBezierLen(x0, y0, x1, y1, x2, y2 float64) int {
3232
return n
3333
}
3434

35+
// QuadraticBezier computes points along a quadratic Bezier curve defined by
36+
// (x0, y0), (x1, y1), (x2, y2).
37+
//
38+
// QuadraticBezier 计算由 (x0, y0)、(x1, y1)、(x2, y2) 定义的二次贝塞尔曲线上的点。
3539
func QuadraticBezier(x0, y0, x1, y1, x2, y2 float64) []Point {
3640
n := quadraticBezierLen(x0, y0, x1, y1, x2, y2)
3741
result := make([]Point, n)
@@ -45,6 +49,10 @@ func cubicBezierLen(x0, y0, x1, y1, x2, y2, x3, y3 float64) int {
4549
return n
4650
}
4751

52+
// CubicBezier computes points along a cubic Bezier curve defined by
53+
// (x0, y0), (x1, y1), (x2, y2), (x3, y3).
54+
//
55+
// CubicBezier 计算由 (x0, y0)、(x1, y1)、(x2, y2)、(x3, y3) 定义的三次贝塞尔曲线上的点。
4856
func CubicBezier(x0, y0, x1, y1, x2, y2, x3, y3 float64) []Point {
4957
n := cubicBezierLen(x0, y0, x1, y1, x2, y2, x3, y3)
5058
result := make([]Point, n)

color.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
"unsafe"
99
)
1010

11+
// Predefined colors.
12+
//
13+
// 预定义颜色。
1114
var (
1215
White = color.RGBA{255, 255, 255, 255}
1316
Black = color.RGBA{0, 0, 0, 255}

0 commit comments

Comments
 (0)