Skip to content

Commit 797abbd

Browse files
committed
编译脚本支持GCC
1 parent bce8176 commit 797abbd

File tree

8 files changed

+74
-4
lines changed

8 files changed

+74
-4
lines changed

build/build.sh

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function build() {
5353

5454
# generate files
5555
echo "generating files ..."
56-
go run -tags $TAG "$ROOT"/../cmd/edge-admin/main.go generate
56+
env CGO_ENABLED=0 go run -tags $TAG "$ROOT"/../cmd/edge-admin/main.go generate
5757
if [ "$(which uglifyjs)" ]; then
5858
echo "compress to component.js ..."
5959
uglifyjs --compress --mangle -- "${JS_ROOT}"/components.src.js > "${JS_ROOT}"/components.js
@@ -99,11 +99,34 @@ function build() {
9999
rm -f "$(basename "$EDGE_API_ZIP_FILE")"
100100
cd - || exit
101101

102+
# find gcc
103+
GCC_DIR=""
104+
CC_PATH=""
105+
CXX_PATH=""
106+
if [ "${ARCH}" == "amd64" ]; then
107+
GCC_DIR="/usr/local/gcc/x86_64-unknown-linux-gnu/bin"
108+
CC_PATH="x86_64-unknown-linux-gnu-gcc"
109+
CXX_PATH="x86_64-unknown-linux-gnu-g++"
110+
fi
111+
if [ "${ARCH}" == "arm64" ]; then
112+
GCC_DIR="/usr/local/gcc/aarch64-unknown-linux-gnu/bin"
113+
CC_PATH="aarch64-unknown-linux-gnu-gcc"
114+
CXX_PATH="aarch64-unknown-linux-gnu-g++"
115+
fi
116+
102117
# build
103118
echo "building ${NAME} ..."
104-
env GOOS="$OS" GOARCH="$ARCH" go build -trimpath -tags $TAG -ldflags="-s -w" -o "$DIST"/bin/${NAME} "$ROOT"/../cmd/edge-admin/main.go
119+
if [ -f "${GCC_DIR}/${CC_PATH}" ]; then
120+
echo " building ${NAME} with gcc ..."
121+
env CC="${GCC_DIR}/${CC_PATH}" \
122+
CXX="${GCC_DIR}/${CXX_PATH}" \
123+
CGO_ENABLED=1 \
124+
GOOS="$OS" GOARCH="$ARCH" go build -trimpath -tags "${TAG} gcc" -ldflags="-s -w" -o "$DIST"/bin/${NAME} "$ROOT"/../cmd/edge-admin/main.go
125+
else
126+
GOOS="$OS" GOARCH="$ARCH" go build -trimpath -tags $TAG -ldflags="-s -w" -o "$DIST"/bin/${NAME} "$ROOT"/../cmd/edge-admin/main.go
127+
fi
105128
if [ ! -f "${DIST}/bin/${NAME}" ]; then
106-
echo "build failed!"
129+
echo "build '${NAME}' failed!"
107130
exit
108131
fi
109132

build/generate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
JS_ROOT=../web/public/js
44

55
echo "generating component.src.js ..."
6-
go run -tags=community ../cmd/edge-admin/main.go generate
6+
env CGO_ENABLED=0 go run -tags=community ../cmd/edge-admin/main.go generate
77

88
if [ "$(which uglifyjs)" ]; then
99
echo "compress to component.js ..."

internal/waf/injectionutils/utils_sqli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2023 GoEdge CDN [email protected]. All rights reserved. Official site: https://goedge.cn .
2+
//go:build gcc
23

34
package injectionutils
45

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2023 GoEdge CDN [email protected]. All rights reserved. Official site: https://goedge.cn .
2+
//go:build !gcc
3+
4+
package injectionutils
5+
6+
// DetectSQLInjectionCache detect sql injection in string with cache
7+
func DetectSQLInjectionCache(input string, isStrict bool, cacheLife int) bool {
8+
// stub
9+
return false
10+
}
11+
12+
// DetectSQLInjection detect sql injection in string
13+
func DetectSQLInjection(input string, isStrict bool) bool {
14+
// stub
15+
return false
16+
}
17+
18+
func detectSQLInjectionOne(input string) bool {
19+
// stub
20+
return false
21+
}

internal/waf/injectionutils/utils_sqli_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2023 GoEdge CDN [email protected]. All rights reserved. Official site: https://goedge.cn .
2+
//go:build gcc
23

34
package injectionutils_test
45

internal/waf/injectionutils/utils_xss.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2023 GoEdge CDN [email protected]. All rights reserved. Official site: https://goedge.cn .
2+
//go:build gcc
23

34
package injectionutils
45

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2023 GoEdge CDN [email protected]. All rights reserved. Official site: https://goedge.cn .
2+
//go:build !gcc
3+
4+
package injectionutils
5+
6+
const MaxCacheDataSize = 1 << 20
7+
8+
func DetectXSSCache(input string, isStrict bool, cacheLife int) bool {
9+
// stub
10+
return false
11+
}
12+
13+
// DetectXSS detect XSS in string
14+
func DetectXSS(input string, isStrict bool) bool {
15+
// stub
16+
return false
17+
}
18+
19+
func detectXSSOne(input string, isStrict bool) bool {
20+
// stub
21+
return false
22+
}

internal/waf/injectionutils/utils_xss_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2023 GoEdge CDN [email protected]. All rights reserved. Official site: https://goedge.cn .
2+
//go:build gcc
23

34
package injectionutils_test
45

0 commit comments

Comments
 (0)