Skip to content

Commit 0303c01

Browse files
committed
mage: build with OpenSSL
3 build options have been added: - static with statically linked OpenSSL; - shared with dynamically linked OpenSSL; - nossl without OpenSSL; Closes #308
1 parent 65ad9d8 commit 0303c01

File tree

11 files changed

+86
-25
lines changed

11 files changed

+86
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ runs:
4242
tarantool-version: '${{ inputs.tarantool-version }}'
4343

4444
- name: Build tt
45-
run: mage build
45+
run: mage build static
4646
shell: bash

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ runs:
6464
shell: bash
6565

6666
- name: Build tt
67-
run: mage build
67+
run: mage build static
6868
shell: bash

.github/workflows/full-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
uses: docker-practice/actions-setup-docker@master
135135

136136
- name: Build tt
137-
run: mage build
137+
run: mage build static
138138

139139
- name: Install tarantool
140140
run: brew 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
pip3 install pytest tarantool requests psutil pyyaml netifaces
125125
126126
- name: Build tt
127-
run: mage build
127+
run: mage build static
128128

129129
- name: Install tarantool
130130
run: brew 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,27 @@ Build
3737
3838
git clone https://github.com/tarantool/tt --recursive
3939
cd tt
40-
mage build
40+
41+
You can build a binary with statically linked OpenSSL. This build type is used
42+
for releases:
43+
44+
.. code-block:: bash
45+
46+
mage build static
47+
48+
You can build a binary with dynamically linked OpenSSL for development
49+
purposes:
50+
51+
.. code-block:: bash
52+
53+
mage build shared
54+
55+
Finnally, you can build the binary without OpenSSL and TLS support for
56+
development purposes:
57+
58+
.. code-block:: bash
59+
60+
mage build nossl
4161
4262
~~~~~~~~~~~~
4363
Dependencies

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/spf13/cobra v1.3.0
2222
github.com/stretchr/testify v1.7.1
2323
github.com/tarantool/cartridge-cli v0.0.0-20220605082730-53e6a5be9a61
24-
github.com/tarantool/go-tarantool v1.9.0
24+
github.com/tarantool/go-tarantool v1.10.1-0.20230309143354-e257ff30dd4d
2525
github.com/vmihailenco/msgpack/v5 v5.3.5
2626
github.com/yuin/gopher-lua v0.0.0-20220504180219-658193537a64
2727
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
@@ -69,7 +69,7 @@ require (
6969
github.com/sirupsen/logrus v1.8.1 // indirect
7070
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
7171
github.com/spf13/pflag v1.0.5 // indirect
72-
github.com/tarantool/go-openssl v0.0.8-0.20220711094538-d93c1eff4f49 // indirect
72+
github.com/tarantool/go-openssl v0.0.8-0.20230307065445-720eeb389195 // indirect
7373
github.com/tklauser/go-sysconf v0.3.4 // indirect
7474
github.com/tklauser/numcpus v0.2.1 // indirect
7575
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect

go.sum

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN
686686
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
687687
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
688688
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
689+
github.com/markphelps/optional v0.10.0/go.mod h1:Fvjs1vxcm7/wDqJPFGEiEM1RuxFl9GCyxQlj9M9YMAQ=
689690
github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho=
690691
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
691692
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
@@ -987,12 +988,12 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69
987988
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
988989
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
989990
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
990-
github.com/tarantool/go-openssl v0.0.8-0.20220711094538-d93c1eff4f49 h1:rZYYi1cI3QXZ3yRFZd2ItYM1XA2BaJqP0buDroMbjNo=
991-
github.com/tarantool/go-openssl v0.0.8-0.20220711094538-d93c1eff4f49/go.mod h1:M7H4xYSbzqpW/ZRBMyH0eyqQBsnhAMfsYk5mv0yid7A=
991+
github.com/tarantool/go-openssl v0.0.8-0.20230307065445-720eeb389195 h1:/AN3eUPsTlvF6W+Ng/8ZjnSU6o7L0H4Wb9GMks6RkzU=
992+
github.com/tarantool/go-openssl v0.0.8-0.20230307065445-720eeb389195/go.mod h1:M7H4xYSbzqpW/ZRBMyH0eyqQBsnhAMfsYk5mv0yid7A=
992993
github.com/tarantool/go-prompt v0.2.6-tarantool h1:/dYMRBuM5nE3mleka/mqJWPf8SrJ151U+OqDlTzvES0=
993994
github.com/tarantool/go-prompt v0.2.6-tarantool/go.mod h1:8enZKIgoGFEQu2XPBK79TguJG2XF3SR4QU2iYI28NSo=
994-
github.com/tarantool/go-tarantool v1.9.0 h1:qUotwiMNZhi9AvogF3uyswEN2NAFcKJOhcvXiE/P+Rs=
995-
github.com/tarantool/go-tarantool v1.9.0/go.mod h1:oPjvZNKaN4iKbf8YPo3pGpxzk6cRZF1neAxgq8WcBh8=
995+
github.com/tarantool/go-tarantool v1.10.1-0.20230309143354-e257ff30dd4d h1:qkKjWaxX8GPdHSP2WETv096vm/MH2iBPOZa6hnJ780s=
996+
github.com/tarantool/go-tarantool v1.10.1-0.20230309143354-e257ff30dd4d/go.mod h1:oMCTx0UAjEkHjdVdgnh3DjwUxs0xgyvIcaOBV8i4CF4=
996997
github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I=
997998
github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0=
998999
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=

magefile.go

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,24 @@ var (
3838
"-X ${PACKAGE}/version.versionLabel=${VERSION_LABEL}",
3939
"-X ${PACKAGE}/configure.defaultConfigPath=${CONFIG_PATH}",
4040
}
41-
41+
staticLdflags = []string{
42+
"-linkmode=external", "-extldflags", "-static",
43+
}
4244
goExecutableName = "go"
4345
pythonExecutableName = "python3"
4446
ttExecutableName = "tt"
4547

4648
generateModePath = filepath.Join(packagePath, "codegen", "generate_code.go")
4749
)
4850

51+
type BuildType string
52+
53+
const (
54+
BuildTypeShared BuildType = "shared"
55+
BuildTypeStatic BuildType = "static"
56+
BuildTypeNossl BuildType = "nossl"
57+
)
58+
4959
func init() {
5060
var err error
5161

@@ -60,7 +70,6 @@ func init() {
6070
panic(err)
6171
}
6272
}
63-
6473
// We want to use Go 1.11 modules even if the source lives inside GOPATH.
6574
// The default is "auto".
6675
os.Setenv("GO111MODULE", "on")
@@ -144,17 +153,35 @@ func PatchCC() error {
144153
}
145154

146155
// Building tt executable.
147-
func Build() error {
156+
func Build(env string) error {
148157
fmt.Println("Building tt...")
149158

150159
mg.Deps(PatchCC)
151160
mg.Deps(GenerateGoCode)
152161

162+
buildLdflags := make([]string, len(ldflags))
163+
copy(buildLdflags, ldflags)
164+
tags := "-tags=netgo,osusergo"
165+
switch BuildType(env) {
166+
case BuildTypeStatic:
167+
if runtime.GOOS != "darwin" {
168+
buildLdflags = append(buildLdflags, staticLdflags...)
169+
}
170+
tags = tags + ",openssl_static"
171+
case BuildTypeShared:
172+
case BuildTypeNossl:
173+
tags = tags + ",go_tarantool_ssl_disable"
174+
default:
175+
return fmt.Errorf("Unsupported build type: %s, supported: "+
176+
"%s, %s, %s\n",
177+
env, BuildTypeStatic, BuildTypeShared, BuildTypeNossl)
178+
}
179+
153180
err := sh.RunWith(
154181
getBuildEnvironment(), goExecutableName, "build",
155182
"-o", ttExecutableName,
156-
"-tags=go_tarantool_ssl_disable",
157-
"-ldflags", strings.Join(ldflags, " "),
183+
tags,
184+
"-ldflags", strings.Join(buildLdflags, " "),
158185
"-asmflags", asmflags,
159186
"-gcflags", gcflags,
160187
packagePath,
@@ -210,11 +237,11 @@ func Unit() error {
210237
mg.Deps(GenerateGoCode)
211238

212239
if mg.Verbose() {
213-
return sh.RunV(goExecutableName, "test", "-v", "-tags", "go_tarantool_ssl_disable",
240+
return sh.RunV(goExecutableName, "test", "-v",
214241
fmt.Sprintf("%s/...", packagePath))
215242
}
216243

217-
return sh.RunV(goExecutableName, "test", "-tags", "go_tarantool_ssl_disable", fmt.Sprintf("%s/...", packagePath))
244+
return sh.RunV(goExecutableName, "test", fmt.Sprintf("%s/...", packagePath))
218245
}
219246

220247
// Run unit tests with a Tarantool instance integration.
@@ -225,11 +252,11 @@ func UnitFull() error {
225252

226253
if mg.Verbose() {
227254
return sh.RunV(goExecutableName, "test", "-v", fmt.Sprintf("%s/...", packagePath),
228-
"-tags", "integration,go_tarantool_ssl_disable")
255+
"-tags", "integration")
229256
}
230257

231258
return sh.RunV(goExecutableName, "test", fmt.Sprintf("%s/...", packagePath),
232-
"-tags", "integration,go_tarantool_ssl_disable")
259+
"-tags", "integration")
233260
}
234261

235262
// Run integration tests, excluding slow tests.
@@ -320,6 +347,6 @@ func getBuildEnvironment() map[string]string {
320347
"VERSION_LABEL": os.Getenv("VERSION_LABEL"),
321348
"PWD": currentDir,
322349
"CONFIG_PATH": getDefaultConfigPath(),
323-
"CGO_ENABLED": "0",
350+
"CGO_ENABLED": "1",
324351
}
325352
}

test/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def tt_cmd(session_tmpdir):
4141
build_env = os.environ.copy()
4242
build_env["TTEXE"] = tt_path
4343

44-
process = subprocess.run(["mage", "-v", "build"], cwd=tt_base_path, env=build_env)
44+
process = subprocess.run(["mage", "-v", "build", "static"], cwd=tt_base_path, env=build_env)
4545
assert process.returncode == 0, "Failed to build Tarantool CLI executable"
4646

4747
return tt_path

0 commit comments

Comments
 (0)