Skip to content

Commit da3a272

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 da3a272

File tree

9 files changed

+79
-19
lines changed

9 files changed

+79
-19
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

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)