Skip to content

Commit 139704f

Browse files
Update from-source.zh-cn.md & from-source.en-us.md - Cross Compile Using Zig (#25194)
## Compile & Cross Compile Gitea With CGO Dependencies Using Zig --------- Co-authored-by: Jason Song <[email protected]>
1 parent 6da19d7 commit 139704f

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

docs/content/doc/installation/from-source.en-us.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,61 @@ Similarly, a script for zsh-completion can be found at [`contrib/autocompletion/
206206
`.zshrc`.
207207

208208
YMMV and these scripts may need further improvement.
209+
210+
## Compile or cross-compile using Linux with Zig
211+
212+
Follow [Getting Started of Zig](https://ziglang.org/learn/getting-started/#installing-zig) to install zig.
213+
214+
- Compile (Linux ➝ Linux)
215+
216+
```sh
217+
CC="zig cc -target x86_64-linux-gnu" \
218+
CGO_ENABLED=1 \
219+
CGO_CFLAGS="-O2 -g -pthread" \
220+
CGO_LDFLAGS="-linkmode=external -v"
221+
GOOS=linux \
222+
GOARCH=amd64 \
223+
TAGS="bindata sqlite sqlite_unlock_notify" \
224+
make build
225+
```
226+
227+
- Cross-compile (Linux ➝ Windows)
228+
229+
```sh
230+
CC="zig cc -target x86_64-windows-gnu" \
231+
CGO_ENABLED=1 \
232+
CGO_CFLAGS="-O2 -g -pthread" \
233+
GOOS=windows \
234+
GOARCH=amd64 \
235+
TAGS="bindata sqlite sqlite_unlock_notify" \
236+
make build
237+
```
238+
239+
## Compile or cross-compile with Zig using Windows
240+
241+
Compile with `GIT BASH`.
242+
243+
- Compile (Windows ➝ Windows)
244+
245+
```sh
246+
CC="zig cc -target x86_64-windows-gnu" \
247+
CGO_ENABLED=1 \
248+
CGO_CFLAGS="-O2 -g -pthread" \
249+
GOOS=windows \
250+
GOARCH=amd64 \
251+
TAGS="bindata sqlite sqlite_unlock_notify" \
252+
make build
253+
```
254+
255+
- Cross-compile (Windows ➝ Linux)
256+
257+
```sh
258+
CC="zig cc -target x86_64-linux-gnu" \
259+
CGO_ENABLED=1 \
260+
CGO_CFLAGS="-O2 -g -pthread" \
261+
CGO_LDFLAGS="-linkmode=external -v"
262+
GOOS=linux \
263+
GOARCH=amd64 \
264+
TAGS="bindata sqlite sqlite_unlock_notify" \
265+
make build
266+
```

docs/content/doc/installation/from-source.zh-cn.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,61 @@ GOOS=linux GOARCH=arm64 make build
103103
```bash
104104
CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata sqlite sqlite_unlock_notify" make build
105105
```
106+
107+
## 使用Linux与Zig编译或交叉编译
108+
109+
按照[Getting Started of Zig](https://ziglang.org/learn/getting-started/#installing-zig)来安装zig。
110+
111+
- 编译(Linux ➝ Linux)
112+
113+
```sh
114+
CC="zig cc -target x86_64-linux-gnu" \
115+
CGO_ENABLED=1 \
116+
CGO_CFLAGS="-O2 -g -pthread" \
117+
CGO_LDFLAGS="-linkmode=external -v"
118+
GOOS=linux \
119+
GOARCH=amd64 \
120+
TAGS="bindata sqlite sqlite_unlock_notify" \
121+
make build
122+
```
123+
124+
- 交叉编译(Linux ➝ Windows)
125+
126+
```sh
127+
CC="zig cc -target x86_64-windows-gnu" \
128+
CGO_ENABLED=1 \
129+
CGO_CFLAGS="-O2 -g -pthread" \
130+
GOOS=windows \
131+
GOARCH=amd64 \
132+
TAGS="bindata sqlite sqlite_unlock_notify" \
133+
make build
134+
```
135+
136+
## 使用Windows与Zig编译或交叉编译
137+
138+
使用`GIT BASH`编译。
139+
140+
- 编译(Windows ➝ Windows)
141+
142+
```sh
143+
CC="zig cc -target x86_64-windows-gnu" \
144+
CGO_ENABLED=1 \
145+
CGO_CFLAGS="-O2 -g -pthread" \
146+
GOOS=windows \
147+
GOARCH=amd64 \
148+
TAGS="bindata sqlite sqlite_unlock_notify" \
149+
make build
150+
```
151+
152+
- 交叉编译(Windows ➝ Linux)
153+
154+
```sh
155+
CC="zig cc -target x86_64-linux-gnu" \
156+
CGO_ENABLED=1 \
157+
CGO_CFLAGS="-O2 -g -pthread" \
158+
CGO_LDFLAGS="-linkmode=external -v"
159+
GOOS=linux \
160+
GOARCH=amd64 \
161+
TAGS="bindata sqlite sqlite_unlock_notify" \
162+
make build
163+
```

0 commit comments

Comments
 (0)