Skip to content

Commit

Permalink
feat(build) disable cgo
Browse files Browse the repository at this point in the history
  • Loading branch information
ccebot committed Dec 19, 2023
1 parent 18aff1f commit 1edb9ba
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .zd.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version = 3.1.0
Version =
Language = zh

42 changes: 42 additions & 0 deletions Build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 构建指南

推荐在`Ubuntu 18.04.6`下构建,其他版本未测试

## 安装依赖

### 安装node

```bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
nvm install v14.21.3 --default
npm install -g yarn
```

### 安装Go

```bash
wget https://golang.google.cn/dl/go1.21.5.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz
export PATH="$HOME/go/bin:/usr/local/go/bin:$PATH"
export GOPROXY='https://goproxy.cn,direct'
```

### 安装系统依赖

```bash
apt install -y zip unzip sqlite3 wine64
```

### 安装rsrc

```bash
wget https://github.com/akavel/rsrc/releases/download/v0.10.2/rsrc_linux_amd64
chmod +x rsrc_linux_amd64
mv rsrc_linux_amd64 /usr/bin/rsrc
```

## 构建

```bash
make default
```
65 changes: 27 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ clear:
prepare_build: clear update_version_in_config gen_version_file prepare_res

win64: prepare_build compile_launcher_win64 compile_server_win64 package_gui_win64_client compile_command_win64 copy_files package package_upgrade
win32: prepare_build compile_launcher_win32 compile_server_win32 package_gui_win32_client compile_command_win32 copy_files package package_upgrade
# win32: prepare_build compile_launcher_win32 compile_server_win32 package_gui_win32_client compile_command_win32 copy_files package package_upgrade
linux: prepare_build compile_server_linux package_gui_linux_client compile_command_linux copy_files package package_upgrade
linux_arm64: prepare_build compile_server_linux_arm64 package_gui_linux_client_arm64 compile_command_linux_arm64 copy_files package package_upgrade
mac: prepare_build compile_server_mac package_gui_mac_client compile_command_mac copy_files package package_upgrade

compile_all: compile_win64 compile_win32 compile_linux compile_mac
compile_all: compile_win64 compile_linux compile_mac

compile_win64: compile_launcher_win64 compile_server_win64 package_gui_win64_client compile_command_win64
compile_win32: compile_launcher_win32 compile_server_win32 package_gui_win32_client compile_command_win32
# compile_win32: compile_launcher_win32 compile_server_win32 package_gui_win32_client compile_command_win32
compile_linux: compile_server_linux package_gui_linux_client compile_command_linux
compile_linux_arm64: compile_server_linux_arm64 package_gui_linux_client_arm64 compile_command_linux_arm64
compile_mac: compile_server_mac package_gui_mac_client compile_command_mac
Expand All @@ -69,11 +69,11 @@ prepare_res:

build_ui:
@echo 'compile ui'
@cd ui && yarn build --dest ../client/ui && cd ..
@cd ui && yarn install && yarn build --dest ../client/ui && cd ..

compile_server_win64:
@echo 'start compile win64'
@CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ GOOS=windows GOARCH=amd64 \
@GOOS=windows GOARCH=amd64 \
${BUILD_CMD_WIN} -x -v \
-o ${BIN_DIR}/win64/server.exe ${SERVER_MAIN_FILE}

Expand All @@ -83,7 +83,7 @@ compile_server_win64:
compile_server_win32:
@echo 'start compile server win32'
@rm -rf ${BIN_DIR}/win32/server.exe
@CGO_ENABLED=1 CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ GOOS=windows GOARCH=386 \
@GOOS=windows GOARCH=386 \
${BUILD_CMD_WIN} -x -v \
-o ${BIN_DIR}/win32/server.exe ${SERVER_MAIN_FILE}

Expand All @@ -93,23 +93,17 @@ compile_server_win32:
compile_server_linux:
@echo 'start compile server linux'
@rm -rf ${BIN_DIR}/linux/server
ifeq ($(OS),"Mac")
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=/usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-gcc CXX=/usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-g++ \
${BUILD_CMD_UNIX} \
-o ${BIN_DIR}/linux/server ${SERVER_MAIN_FILE}
else
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=gcc CXX=g++ \
@GOOS=linux GOARCH=amd64 \
${BUILD_CMD_UNIX} \
-o ${BIN_DIR}/linux/server ${SERVER_MAIN_FILE}
endif

@rm -rf "${CLIENT_OUT_DIR_UPGRADE}linux" && mkdir -p "${CLIENT_OUT_DIR_UPGRADE}linux" && \
cp ${BIN_DIR}/linux/server "${CLIENT_OUT_DIR_UPGRADE}linux/"

compile_server_linux_arm64:
@echo 'start compile server linux for arm64'
@rm -rf ${BIN_DIR}/linux_arm64/server
@CGO_ENABLED=1 GOOS=linux GOARCH=arm64 GOARM=7 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ AR=aarch64-linux-gnu-ar \
@GOOS=linux GOARCH=arm64 GOARM=7 \
${BUILD_CMD_UNIX} \
-o ${BIN_DIR}/linux_arm64/server ${SERVER_MAIN_FILE}

Expand All @@ -118,7 +112,7 @@ compile_server_linux_arm64:

compile_server_mac:
@echo 'start compile server mac'
@CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC=gcc CXX=g++ \
@GOOS=darwin GOARCH=amd64 \
${BUILD_CMD_UNIX} \
-o ${BIN_DIR}/darwin/server ${SERVER_MAIN_FILE}

Expand All @@ -131,7 +125,7 @@ package_gui_win64_client:
@rm -rf ${CLIENT_BIN_DIR}/* && mkdir -p ${CLIENT_BIN_DIR}win32
@cp -rf ${BIN_DIR}/win64/server.exe ${CLIENT_BIN_DIR}win32/server.exe

@cd client && npm run package-win64 && cd ..
@cd client && npm install && npm run package-win64 && cd ..
@rm -rf ${CLIENT_OUT_DIR_EXECUTABLE}win64 && mkdir -p ${CLIENT_OUT_DIR_EXECUTABLE}win64 && \
mv ${CLIENT_OUT_DIR}${PROJECT}-win32-x64 ${CLIENT_OUT_DIR_EXECUTABLE}win64/gui

Expand All @@ -140,7 +134,7 @@ package_gui_win32_client:
@rm -rf ${CLIENT_BIN_DIR}/* && mkdir -p ${CLIENT_BIN_DIR}win32
@cp -rf ${BIN_DIR}/win32/server.exe ${CLIENT_BIN_DIR}win32/server.exe

@cd client && npm run package-win32 && cd ..
@cd client && npm install && npm run package-win32 && cd ..
@rm -rf ${CLIENT_OUT_DIR_EXECUTABLE}win32 && mkdir -p ${CLIENT_OUT_DIR_EXECUTABLE}win32 && \
mv ${CLIENT_OUT_DIR}${PROJECT}-win32-ia32 ${CLIENT_OUT_DIR_EXECUTABLE}win32/gui

Expand All @@ -149,7 +143,7 @@ package_gui_linux_client:
@rm -rf ${CLIENT_BIN_DIR}/* && mkdir -p ${CLIENT_BIN_DIR}linux
@cp -rf ${BIN_DIR}/linux/server ${CLIENT_BIN_DIR}linux/server

@cd client && npm run package-linux && cp -r icon out/${PROJECT}-linux-x64 && cd ..
@cd client && npm install && npm run package-linux && cp -r icon out/${PROJECT}-linux-x64 && cd ..
@rm -rf ${CLIENT_OUT_DIR_EXECUTABLE}linux && mkdir -p ${CLIENT_OUT_DIR_EXECUTABLE}linux && \
mv ${CLIENT_OUT_DIR}${PROJECT}-linux-x64 ${CLIENT_OUT_DIR_EXECUTABLE}linux/gui

Expand All @@ -158,7 +152,7 @@ package_gui_linux_client_arm64:
@rm -rf ${CLIENT_BIN_DIR}/* && mkdir -p ${CLIENT_BIN_DIR}linux
@cp -rf ${BIN_DIR}/linux_arm64/server ${CLIENT_BIN_DIR}linux/server

@cd client && npm run package-linux-arm64 && cp -r icon out/${PROJECT}-linux-arm64 && cd ..
@cd client && npm install && npm run package-linux-arm64 && cp -r icon out/${PROJECT}-linux-arm64 && cd ..
@rm -rf ${CLIENT_OUT_DIR_EXECUTABLE}linux_arm64 && mkdir -p ${CLIENT_OUT_DIR_EXECUTABLE}linux_arm64 && \
mv ${CLIENT_OUT_DIR}${PROJECT}-linux-arm64 ${CLIENT_OUT_DIR_EXECUTABLE}linux_arm64/gui

Expand All @@ -167,7 +161,7 @@ package_gui_mac_client:
@rm -rf ${CLIENT_BIN_DIR}/* && mkdir -p ${CLIENT_BIN_DIR}darwin
@cp -rf ${BIN_DIR}/darwin/server ${CLIENT_BIN_DIR}darwin/server

@cd client && npm run package-mac && cd ..
@cd client && npm install && npm run package-mac && cd ..
@rm -rf ${CLIENT_OUT_DIR_EXECUTABLE}darwin && mkdir -p ${CLIENT_OUT_DIR_EXECUTABLE}darwin && \
mv ${CLIENT_OUT_DIR}${PROJECT}-darwin-x64 ${CLIENT_OUT_DIR_EXECUTABLE}darwin/gui && \
mv ${CLIENT_OUT_DIR_EXECUTABLE}darwin/gui/zd.app ${CLIENT_OUT_DIR_EXECUTABLE}darwin/zd.app && rm -rf ${CLIENT_OUT_DIR_EXECUTABLE}darwin/gui
Expand All @@ -176,58 +170,53 @@ package_gui_mac_client:
# launcher
compile_launcher_win64:
@echo 'start compile win64 launcher'
@~/go/bin/rsrc -arch amd64 -manifest xdoc/main.manifest -ico xdoc/favicon.ico -o cmd/launcher/main.syso
@rsrc -arch amd64 -manifest xdoc/main.manifest -ico xdoc/favicon.ico -o cmd/launcher/main.syso
@cd cmd/launcher && \
CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ GOOS=windows GOARCH=amd64 \
GOOS=windows GOARCH=amd64 \
${BUILD_CMD_WIN} -x -v \
-o ../../${BIN_DIR}/win64/${PROJECT}-gui.exe && \
cd ..

compile_launcher_win32:
@echo 'start compile win32 launcher'
@~/go/bin/rsrc -arch 386 -manifest xdoc/main.manifest -ico xdoc/favicon.ico -o cmd/launcher/main.syso
@rsrc -arch 386 -manifest xdoc/main.manifest -ico xdoc/favicon.ico -o cmd/launcher/main.syso
@cd cmd/launcher && \
CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ GOOS=windows GOARCH=386 \
GOOS=windows GOARCH=386 \
${BUILD_CMD_WIN} -x -v \
-o ../../${BIN_DIR}/win32/${PROJECT}-gui.exe && \
cd ..

# command line
compile_command_win64:
@echo 'start compile win64'
@CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ GOOS=windows GOARCH=amd64 \
@GOOS=windows GOARCH=amd64 \
${BUILD_CMD_WIN} -x -v \
-o ${BIN_DIR}/win64/${PROJECT}.exe ${COMMAND_MAIN_FILE}

compile_command_win32:
@echo 'start compile win32'
@CGO_ENABLED=1 CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ GOOS=windows GOARCH=386 \
@GOOS=windows GOARCH=386 \
${BUILD_CMD_WIN} -x -v \
-o ${BIN_DIR}/win32/${PROJECT}.exe ${COMMAND_MAIN_FILE}

compile_command_linux:
@echo 'start compile linux'
@rm -rf ${BIN_DIR}/linux/${PROJECT}
ifeq ($(OS),"Mac")
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=/usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-gcc CXX=/usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-g++ \
@GOOS=linux GOARCH=amd64 \
${BUILD_CMD_UNIX} \
-o ${BIN_DIR}/linux/${PROJECT} ${COMMAND_MAIN_FILE}
else
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=gcc CXX=g++ \
${BUILD_CMD_UNIX} \
-o ${BIN_DIR}/linux/${PROJECT} ${COMMAND_MAIN_FILE}
endif


compile_command_linux_arm64:
@echo 'start compile linux for arm64'
@rm -rf ${BIN_DIR}/linux_arm64/${PROJECT}
@CGO_ENABLED=1 GOOS=linux GOARCH=arm64 GOARM=7 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ AR=aarch64-linux-gnu-ar \
@GOOS=linux GOARCH=arm64 GOARM=7 \
${BUILD_CMD_UNIX} \
-o ${BIN_DIR}/linux_arm64/${PROJECT} ${COMMAND_MAIN_FILE}

compile_command_mac:
@echo 'start compile mac'
@CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 \
@GOOS=darwin GOARCH=amd64 \
${BUILD_CMD_UNIX} \
-o ${BIN_DIR}/darwin/${PROJECT} ${COMMAND_MAIN_FILE}

Expand Down Expand Up @@ -265,9 +254,9 @@ copy_files:
@rm -rf ${BIN_OUT}darwin/runtime/php \
${BIN_OUT}darwin/runtime/protobuf/bin/linux \
${BIN_OUT}darwin/runtime/protobuf/bin/win*
@rm -rf ${BIN_OUT}win32/runtime/protobuf/bin/mac \
${BIN_OUT}win32/runtime/protobuf/bin/linux \
${BIN_OUT}win32/runtime/protobuf/bin/win64
# @rm -rf ${BIN_OUT}win32/runtime/protobuf/bin/mac \
# ${BIN_OUT}win32/runtime/protobuf/bin/linux \
# ${BIN_OUT}win32/runtime/protobuf/bin/win64
@rm -rf ${BIN_OUT}win64/runtime/protobuf/bin/mac \
${BIN_OUT}win64/runtime/protobuf/bin/linux \
${BIN_OUT}win64/runtime/protobuf/bin/win32
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.1
3.1
69 changes: 37 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ require (
)

require (
github.com/BurntSushi/toml v1.0.0 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
github.com/CloudyKit/jet/v6 v6.1.0 // indirect
github.com/Shopify/goreferrer v0.0.0-20210630161223-536fa16abd6f // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/CloudyKit/jet/v6 v6.2.0 // indirect
github.com/Joker/jade v1.1.3 // indirect
github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06 // indirect
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -30,11 +31,12 @@ require (
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.1.0 // indirect
github.com/gobwas/ws v1.3.0 // indirect
github.com/goccy/go-json v0.9.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gomarkdown/markdown v0.0.0-20231115200524-a660076da3fd // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/invopop/yaml v0.2.0 // indirect
github.com/iris-contrib/go.uuid v2.0.0+incompatible // indirect
Expand All @@ -44,23 +46,24 @@ require (
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kataras/blocks v0.0.5 // indirect
github.com/kataras/golog v0.1.7 // indirect
github.com/kataras/neffos v0.0.19 // indirect
github.com/kataras/pio v0.0.10 // indirect
github.com/kataras/sitemap v0.0.5 // indirect
github.com/kataras/tunnel v0.0.3 // indirect
github.com/klauspost/compress v1.14.4 // indirect
github.com/kataras/blocks v0.0.8 // indirect
github.com/kataras/golog v0.1.11 // indirect
github.com/kataras/neffos v0.0.22 // indirect
github.com/kataras/pio v0.0.13 // indirect
github.com/kataras/sitemap v0.0.6 // indirect
github.com/kataras/tunnel v0.0.4 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/mailgun/raymond/v2 v2.0.48 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mediocregopher/radix/v3 v3.8.0 // indirect
github.com/microcosm-cc/bluemonday v1.0.18 // indirect
github.com/mediocregopher/radix/v3 v3.8.1 // indirect
github.com/microcosm-cc/bluemonday v1.0.26 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/nats-io/nats.go v1.13.1-0.20220121202836-972a071d373d // indirect
github.com/nats-io/nkeys v0.3.0 // indirect
github.com/nats-io/nats.go v1.28.0 // indirect
github.com/nats-io/nkeys v0.4.6 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/nwaples/rardecode v1.1.0 // indirect
github.com/ozontech/allure-go/pkg/allure v0.6.6 // indirect
Expand All @@ -72,24 +75,26 @@ require (
github.com/richardlehane/msoleps v1.0.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/schollz/closestmatch v2.1.0+incompatible // indirect
github.com/stretchr/testify v1.8.2 // indirect
github.com/tdewolff/minify/v2 v2.10.0 // indirect
github.com/tdewolff/parse/v2 v2.5.27 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/tdewolff/minify/v2 v2.20.10 // indirect
github.com/tdewolff/parse/v2 v2.7.7 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/yosssi/ace v0.0.5 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.27.1 // indirect
modernc.org/libc v1.35.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
modernc.org/libc v1.37.6 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/sqlite v1.27.0 // indirect
modernc.org/sqlite v1.28.0 // indirect
)

require (
Expand All @@ -103,11 +108,11 @@ require (
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
github.com/facebookgo/structtag v0.0.0-20150214074306-217e25fb9691 // indirect
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect
github.com/fatih/color v1.13.0
github.com/fatih/color v1.15.0
github.com/golang/protobuf v1.5.2
github.com/iris-contrib/middleware/cors v0.0.0-20220417122231-60b1fdb1e02b
github.com/jinzhu/copier v0.2.5
github.com/kataras/iris/v12 v12.2.0-alpha9
github.com/kataras/iris/v12 v12.2.8
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/mattn/go-runewidth v0.0.10
github.com/mholt/archiver/v3 v3.5.0
Expand All @@ -120,10 +125,10 @@ require (
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/xuri/efp v0.0.0-20210128032744-13be4fd5dcb5 // indirect
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
gopkg.in/ini.v1 v1.66.4
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.5.2
gorm.io/gorm v1.25.5
gorm.io/plugin/dbresolver v1.2.0
gorm.io/plugin/dbresolver v1.5.0
)
Loading

0 comments on commit 1edb9ba

Please sign in to comment.