Skip to content

Commit 409e339

Browse files
committed
mage: build with OpenSSL
3 build options via TT_CLI_BUILD_SSL environment variable have been added: - no without OpenSSL; - static with statically linked OpenSSL; - shared with dynamically linked OpenSSL; Closes #308
1 parent 96f527f commit 409e339

File tree

11 files changed

+100
-22
lines changed

11 files changed

+100
-22
lines changed

.github/actions/prepare-ce-test-env/action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ runs:
4242
tarantool-version: '${{ inputs.tarantool-version }}'
4343

4444
- name: Build tt
45+
env:
46+
TT_CLI_BUILD_SSL: 'static'
4547
run: mage build
4648
shell: bash

.github/actions/prepare-ee-test-env/action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,7 @@ runs:
6464
shell: bash
6565

6666
- name: Build tt
67+
env:
68+
TT_CLI_BUILD: 'static'
6769
run: mage build
6870
shell: bash

.github/workflows/full-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ jobs:
134134
uses: docker-practice/actions-setup-docker@master
135135

136136
- name: Build tt
137+
env:
138+
TT_CLI_BUILD_SSL: 'static'
137139
run: mage build
138140

139141
- name: Install tarantool

.github/workflows/publish.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ jobs:
2828
cd mage
2929
go run bootstrap.go
3030
31+
- name: Build OpenSSL 3.0
32+
run: |
33+
wget https://github.com/openssl/openssl/releases/download/openssl-3.0.8/openssl-3.0.8.tar.gz
34+
tar -xvf openssl-3.0.8.tar.gz
35+
cd openssl-3.0.8/
36+
./Configure --prefix=${GITHUB_WORKSPACE}/openssl no-shared
37+
make && make install
38+
3139
- name: Setup GoReleaser
3240
run: |
3341
curl -O -L https://github.com/goreleaser/goreleaser/releases/download/v1.12.3/goreleaser_1.12.3_amd64.deb
@@ -45,6 +53,8 @@ jobs:
4553
4654
- name: Build packages
4755
env:
56+
CGO_LDFLAGS: "-L${{ env.GITHUB_WORKSPACE }}/openssl/lib64"
57+
CGO_CFLAGS: "-I${{ env.GITHUB_WORKSPACE }}/openssl/include"
4858
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4959
run: |
5060
goreleaser release ${{ steps.set-goreleaser-flags.outputs.GORELEASER_FLAGS }}

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ jobs:
124124
pip3 install pytest tarantool requests psutil pyyaml netifaces
125125
126126
- name: Build tt
127+
env:
128+
TT_CLI_BUILD_SSL: 'static'
127129
run: mage build
128130

129131
- name: Install tarantool

.goreleaser.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ builds:
1212
dir: cli
1313

1414
env:
15-
- CGO_ENABLED=0
15+
- CGO_ENABLED=1
1616

17-
flags:
18-
- -tags=go_tarantool_ssl_disable
17+
tags:
18+
- netgo
19+
- osusergo
20+
- openssl_static
1921

2022
ldflags:
23+
- -linkmode=external -extldflags -static
2124
- -s -w
2225
- -X github.com/tarantool/tt/cli/version.gitTag={{ .Tag }}
2326
- -X github.com/tarantool/tt/cli/version.gitCommit={{ .ShortCommit }}

README.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,29 @@ Build
3737
3838
git clone https://github.com/tarantool/tt --recursive
3939
cd tt
40+
41+
You can build a binary without OpenSSL and TLS support for development
42+
purposes:
43+
44+
.. code-block:: bash
45+
46+
TT_CLI_BUILD_SSL=no mage build
4047
mage build
4148
49+
You can build a binary with statically linked OpenSSL. This build type is used
50+
for releases:
51+
52+
.. code-block:: bash
53+
54+
TT_CLI_BUILD_SSL=static mage build
55+
56+
Finally, you can build a binary with dynamically linked OpenSSL for development
57+
purposes:
58+
59+
.. code-block:: bash
60+
61+
TT_CLI_BUILD_SSL=shared mage build
62+
4263
~~~~~~~~~~~~
4364
Dependencies
4465
~~~~~~~~~~~~

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/spf13/cobra v1.3.0
2323
github.com/stretchr/testify v1.7.1
2424
github.com/tarantool/cartridge-cli v0.0.0-20220605082730-53e6a5be9a61
25-
github.com/tarantool/go-tarantool v1.9.0
25+
github.com/tarantool/go-tarantool v1.10.1-0.20230309143354-e257ff30dd4d
2626
github.com/vmihailenco/msgpack/v5 v5.3.5
2727
github.com/yuin/gopher-lua v0.0.0-20220504180219-658193537a64
2828
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
@@ -78,8 +78,8 @@ require (
7878
github.com/sirupsen/logrus v1.8.1 // indirect
7979
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
8080
github.com/spf13/pflag v1.0.5 // indirect
81-
github.com/tarantool/go-openssl v0.0.8-0.20220711094538-d93c1eff4f49 // indirect
82-
github.com/temoto/robotstxt v1.1.1 // indirect
81+
github.com/tarantool/go-openssl v0.0.8-0.20230307065445-720eeb389195 // indirect
82+
github.com/temoto/robotstxt v1.1.2 // indirect
8383
github.com/tklauser/go-sysconf v0.3.4 // indirect
8484
github.com/tklauser/numcpus v0.2.1 // indirect
8585
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect

go.sum

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN
704704
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
705705
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
706706
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
707+
github.com/markphelps/optional v0.10.0/go.mod h1:Fvjs1vxcm7/wDqJPFGEiEM1RuxFl9GCyxQlj9M9YMAQ=
707708
github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho=
708709
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
709710
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
@@ -1007,15 +1008,15 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69
10071008
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
10081009
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
10091010
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
1010-
github.com/tarantool/go-openssl v0.0.8-0.20220711094538-d93c1eff4f49 h1:rZYYi1cI3QXZ3yRFZd2ItYM1XA2BaJqP0buDroMbjNo=
1011-
github.com/tarantool/go-openssl v0.0.8-0.20220711094538-d93c1eff4f49/go.mod h1:M7H4xYSbzqpW/ZRBMyH0eyqQBsnhAMfsYk5mv0yid7A=
1011+
github.com/tarantool/go-openssl v0.0.8-0.20230307065445-720eeb389195 h1:/AN3eUPsTlvF6W+Ng/8ZjnSU6o7L0H4Wb9GMks6RkzU=
1012+
github.com/tarantool/go-openssl v0.0.8-0.20230307065445-720eeb389195/go.mod h1:M7H4xYSbzqpW/ZRBMyH0eyqQBsnhAMfsYk5mv0yid7A=
10121013
github.com/tarantool/go-prompt v0.2.6-tarantool h1:/dYMRBuM5nE3mleka/mqJWPf8SrJ151U+OqDlTzvES0=
10131014
github.com/tarantool/go-prompt v0.2.6-tarantool/go.mod h1:8enZKIgoGFEQu2XPBK79TguJG2XF3SR4QU2iYI28NSo=
1014-
github.com/tarantool/go-tarantool v1.9.0 h1:qUotwiMNZhi9AvogF3uyswEN2NAFcKJOhcvXiE/P+Rs=
1015-
github.com/tarantool/go-tarantool v1.9.0/go.mod h1:oPjvZNKaN4iKbf8YPo3pGpxzk6cRZF1neAxgq8WcBh8=
1015+
github.com/tarantool/go-tarantool v1.10.1-0.20230309143354-e257ff30dd4d h1:qkKjWaxX8GPdHSP2WETv096vm/MH2iBPOZa6hnJ780s=
1016+
github.com/tarantool/go-tarantool v1.10.1-0.20230309143354-e257ff30dd4d/go.mod h1:oMCTx0UAjEkHjdVdgnh3DjwUxs0xgyvIcaOBV8i4CF4=
10161017
github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I=
1017-
github.com/temoto/robotstxt v1.1.1 h1:Gh8RCs8ouX3hRSxxK7B1mO5RFByQ4CmJZDwgom++JaA=
1018-
github.com/temoto/robotstxt v1.1.1/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo=
1018+
github.com/temoto/robotstxt v1.1.2 h1:W2pOjSJ6SWvldyEuiFXNxz3xZ8aiWX5LbfDiOFd7Fxg=
1019+
github.com/temoto/robotstxt v1.1.2/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo=
10191020
github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0=
10201021
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
10211022
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=

magefile.go

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
)
1818

1919
const (
20+
buildTypeEnv = "TT_CLI_BUILD_SSL"
2021
goPackageName = "github.com/tarantool/tt/cli"
2122

2223
asmflags = "all=-trimpath=${PWD}"
@@ -38,14 +39,25 @@ var (
3839
"-X ${PACKAGE}/version.versionLabel=${VERSION_LABEL}",
3940
"-X ${PACKAGE}/configure.defaultConfigPath=${CONFIG_PATH}",
4041
}
41-
42+
staticLdflags = []string{
43+
"-linkmode=external", "-extldflags", "-static",
44+
}
4245
goExecutableName = "go"
4346
pythonExecutableName = "python3"
4447
ttExecutableName = "tt"
4548

4649
generateModePath = filepath.Join(packagePath, "codegen", "generate_code.go")
4750
)
4851

52+
type BuildType string
53+
54+
const (
55+
BuildTypeDefault BuildType = ""
56+
BuildTypeNoCgo BuildType = "no"
57+
BuildTypeShared BuildType = "shared"
58+
BuildTypeStatic BuildType = "static"
59+
)
60+
4961
func init() {
5062
var err error
5163

@@ -60,7 +72,6 @@ func init() {
6072
panic(err)
6173
}
6274
}
63-
6475
// We want to use Go 1.11 modules even if the source lives inside GOPATH.
6576
// The default is "auto".
6677
os.Setenv("GO111MODULE", "on")
@@ -143,18 +154,41 @@ func PatchCC() error {
143154
return nil
144155
}
145156

146-
// Building tt executable.
157+
// Building tt executable. Supported environment variables:
158+
// TT_CLI_BUILD_SSL=(no|static|shared)
147159
func Build() error {
148160
fmt.Println("Building tt...")
149161

150162
mg.Deps(PatchCC)
151163
mg.Deps(GenerateGoCode)
152164

165+
buildLdflags := make([]string, len(ldflags))
166+
copy(buildLdflags, ldflags)
167+
tags := "-tags=netgo,osusergo"
168+
169+
buildType := os.Getenv(buildTypeEnv)
170+
switch BuildType(buildType) {
171+
case BuildTypeDefault:
172+
fallthrough
173+
case BuildTypeNoCgo:
174+
tags = tags + ",go_tarantool_ssl_disable"
175+
case BuildTypeStatic:
176+
if runtime.GOOS != "darwin" {
177+
buildLdflags = append(buildLdflags, staticLdflags...)
178+
}
179+
tags = tags + ",openssl_static"
180+
case BuildTypeShared:
181+
default:
182+
return fmt.Errorf("Unsupported build type: %s, supported: "+
183+
"%s, %s, %s\n",
184+
buildType, BuildTypeNoCgo, BuildTypeStatic, BuildTypeShared)
185+
}
186+
153187
err := sh.RunWith(
154188
getBuildEnvironment(), goExecutableName, "build",
155189
"-o", ttExecutableName,
156-
"-tags=go_tarantool_ssl_disable",
157-
"-ldflags", strings.Join(ldflags, " "),
190+
tags,
191+
"-ldflags", strings.Join(buildLdflags, " "),
158192
"-asmflags", asmflags,
159193
"-gcflags", gcflags,
160194
packagePath,
@@ -210,11 +244,11 @@ func Unit() error {
210244
mg.Deps(GenerateGoCode)
211245

212246
if mg.Verbose() {
213-
return sh.RunV(goExecutableName, "test", "-v", "-tags", "go_tarantool_ssl_disable",
247+
return sh.RunV(goExecutableName, "test", "-v",
214248
fmt.Sprintf("%s/...", packagePath))
215249
}
216250

217-
return sh.RunV(goExecutableName, "test", "-tags", "go_tarantool_ssl_disable", fmt.Sprintf("%s/...", packagePath))
251+
return sh.RunV(goExecutableName, "test", fmt.Sprintf("%s/...", packagePath))
218252
}
219253

220254
// Run unit tests with a Tarantool instance integration.
@@ -225,11 +259,11 @@ func UnitFull() error {
225259

226260
if mg.Verbose() {
227261
return sh.RunV(goExecutableName, "test", "-v", fmt.Sprintf("%s/...", packagePath),
228-
"-tags", "integration,go_tarantool_ssl_disable")
262+
"-tags", "integration")
229263
}
230264

231265
return sh.RunV(goExecutableName, "test", fmt.Sprintf("%s/...", packagePath),
232-
"-tags", "integration,go_tarantool_ssl_disable")
266+
"-tags", "integration")
233267
}
234268

235269
// Run integration tests, excluding slow tests.
@@ -320,6 +354,6 @@ func getBuildEnvironment() map[string]string {
320354
"VERSION_LABEL": os.Getenv("VERSION_LABEL"),
321355
"PWD": currentDir,
322356
"CONFIG_PATH": getDefaultConfigPath(),
323-
"CGO_ENABLED": "0",
357+
"CGO_ENABLED": "1",
324358
}
325359
}

test/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def tt_cmd(session_tmpdir):
4040

4141
build_env = os.environ.copy()
4242
build_env["TTEXE"] = tt_path
43+
build_env["TT_CLI_BUILD_SSL"] = "static"
4344

4445
process = subprocess.run(["mage", "-v", "build"], cwd=tt_base_path, env=build_env)
4546
assert process.returncode == 0, "Failed to build Tarantool CLI executable"

0 commit comments

Comments
 (0)