Skip to content

Commit

Permalink
install: support of tarantool non-static build
Browse files Browse the repository at this point in the history
Added new option --dynamic for tt install tarantool command.
This options enables dynamic linking for building tarantool executable.
  • Loading branch information
psergee authored and LeonidVas committed Apr 26, 2023
1 parent e2b4a23 commit b35f0a7
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- ``--dynamic`` option for `tt install tarantool` command to build non-static tarantool executable.

## [1.0.2] - 2023-04-21

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func newInstallTarantoolCmd() *cobra.Command {

tntCmd.Flags().BoolVarP(&installCtx.BuildInDocker, "use-docker", "", false,
"build tarantool in Ubuntu 18.04 docker container")
tntCmd.Flags().BoolVarP(&installCtx.Dynamic, "dynamic", "", false,
"use dynamic linking for building tarantool")

return tntCmd
}
Expand Down
81 changes: 59 additions & 22 deletions cli/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ type InstallCtx struct {
verbose bool
// Version of the program to install.
version string
// Dynamic flag enables dynamic linking.
Dynamic bool
}

// Package is a struct containing sys and install name of the package.
Expand Down Expand Up @@ -570,44 +572,77 @@ func patchTarantool(srcPath string, tarVersion string,
return nil
}

// buildTarantool builds tarantool from source.
func buildTarantool(srcPath string, tarVersion string,
installCtx InstallCtx, logFile *os.File) error {

buildPath := filepath.Join(srcPath, "/static-build/build")
err := os.MkdirAll(buildPath, defaultDirPermissions)
if err != nil {
return err
}
// prepareCmakeOpts prepares cmake command line options for tarantool building.
func prepareCmakeOpts(buildPath string, tntVersion string,
installCtx InstallCtx) ([]string, error) {
cmakeOpts := []string{".."}

// Disable backtrace feature for versions 1.10.X.
// This feature is not supported by a backported static build.
btFlag := "ON"
if tarVersion != "master" {
version, err := version.Parse(tarVersion)
if tntVersion != "master" {
version, err := version.Parse(tntVersion)
if err != nil {
return err
return cmakeOpts, err
}
if version.Major == 1 {
btFlag = "OFF"
}
}

cmakeOpts = append(cmakeOpts, `-DCMAKE_TARANTOOL_ARGS=-DCMAKE_BUILD_TYPE=RelWithDebInfo;`+
`-DENABLE_WERROR=OFF;-DENABLE_BACKTRACE=`+btFlag)

if installCtx.Dynamic {
cmakeOpts = append(cmakeOpts, "-DCMAKE_INSTALL_PREFIX="+filepath.Join(buildPath,
"tarantool-prefix"))
} else {
cmakeOpts = append(cmakeOpts, "-DCMAKE_INSTALL_PREFIX="+buildPath)
}

return cmakeOpts, nil
}

// prepareMakeOpts prepares make command line options for tarantool building.
func prepareMakeOpts(installCtx InstallCtx) []string {
makeOpts := []string{}
if installCtx.Dynamic {
makeOpts = append(makeOpts, "install")
}
if _, isMakeFlagsSet := os.LookupEnv("MAKEFLAGS"); !isMakeFlagsSet {
maxThreads := fmt.Sprint(runtime.NumCPU())
makeOpts = append(makeOpts, "-j", maxThreads)
}
return makeOpts
}

// buildTarantool builds tarantool from source. Returns a path, where build artifacts are placed.
func buildTarantool(srcPath string, tarVersion string,
installCtx InstallCtx, logFile *os.File) (string, error) {

err = util.ExecuteCommand("cmake", installCtx.verbose, logFile, buildPath,
"..", `-DCMAKE_TARANTOOL_ARGS="-DCMAKE_BUILD_TYPE=RelWithDebInfo;`+
`-DENABLE_WERROR=OFF;-DENABLE_BACKTRACE=`+btFlag,
"-DCMAKE_INSTALL_PREFIX="+buildPath)
buildPath := filepath.Join(srcPath, "/static-build/build")
if installCtx.Dynamic {
buildPath = filepath.Join(srcPath, "/dynamic-build")
}
err := os.MkdirAll(buildPath, defaultDirPermissions)
if err != nil {
return err
return "", err
}

return util.ExecuteCommand("make", installCtx.verbose, logFile, buildPath, makeOpts...)
cmakeOpts, err := prepareCmakeOpts(buildPath, tarVersion, installCtx)
if err != nil {
return "", err
}

err = util.ExecuteCommand("cmake", installCtx.verbose, logFile, buildPath, cmakeOpts...)
if err != nil {
return "", err
}

makeOpts := prepareMakeOpts(installCtx)

return buildPath, util.ExecuteCommand("make", installCtx.verbose, logFile, buildPath,
makeOpts...)
}

// copyLocalTarantool finds and copies local tarantool folder to tmp folder.
Expand Down Expand Up @@ -723,6 +758,9 @@ func installTarantoolInDocker(tntVersion, binDir, incDir string, installCtx Inst
if installCtx.Local {
tntInstallCommandLine = append(tntInstallCommandLine, "--local-repo")
}
if installCtx.Dynamic {
tntInstallCommandLine = append(tntInstallCommandLine, "--dynamic")
}

// Exclude last element from incDir path, because it already has "include" subdir appended.
// So we get the parent of incDir to get original include path.
Expand Down Expand Up @@ -850,7 +888,7 @@ func installTarantool(binDir string, incDir string, installCtx InstallCtx,

// Build tarantool.
log.Infof("Building tarantool...")
err = buildTarantool(path, tarVersion, installCtx, logFile)
buildPath, err := buildTarantool(path, tarVersion, installCtx, logFile)
if err != nil {
printLog(logFile.Name())
return err
Expand All @@ -872,9 +910,8 @@ func installTarantool(binDir string, incDir string, installCtx InstallCtx,
printLog(logFile.Name())
return err
}
buildPath := filepath.Join(path, "/static-build/build")
binPath := filepath.Join(buildPath, "/tarantool-prefix/bin/tarantool")
incPath := filepath.Join(buildPath, "/tarantool-prefix/include/tarantool") + "/"
binPath := filepath.Join(buildPath, "tarantool-prefix", "bin", "tarantool")
incPath := filepath.Join(buildPath, "tarantool-prefix", "include", "tarantool") + "/"
err = copyBuildedTarantool(binPath, incPath, binDir, incDir, versionStr, installCtx,
logFile)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def tmpdir_with_tarantool(tt_cmd, request):
tt_process.wait()
assert tt_process.returncode == 0

init_cmd = [tt_cmd, "install", "tarantool"]
init_cmd = [tt_cmd, "install", "tarantool", "--dynamic"]
tt_process = subprocess.Popen(
init_cmd,
cwd=tmpdir,
Expand Down

0 comments on commit b35f0a7

Please sign in to comment.