Skip to content

Commit 9b8b900

Browse files
authored
[ML] More CMake tidyups (elastic#2347)
1. We no longer need references to make as we always use cmake 2. Use camelCase for variables in build.gradle 3. Don't require that BOOST_ROOT be an environment variable when building natively on Windows 4. Remove the last occurrence of $ML_KEEP_GOING 5. Include all variations of CMake build directory in Git/Docker ignores 6. Docker builds should not hardcode the "Release" config
1 parent 6153da1 commit 9b8b900

File tree

7 files changed

+82
-103
lines changed

7 files changed

+82
-103
lines changed

Diff for: .dockerignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,4 @@ boost_test_results.xml
8585
cmake_install.cmake
8686
CMakeCache.txt
8787
CMakeFiles/
88-
cmake-build-release/
89-
cmake-build-debug/
88+
cmake-build-*/

Diff for: .gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ build-eclipse/
1717
nb-configuration.xml
1818
nbactions.xml
1919

20-
#vscode files
20+
# vscode files
2121
.vscode
2222
.clangd
2323
.cache
@@ -81,5 +81,4 @@ boost_test_results.xml
8181
cmake_install.cmake
8282
CMakeCache.txt
8383
CMakeFiles/
84-
cmake-build-release/
85-
cmake-build-debug/
84+
cmake-build-*/

Diff for: build.gradle

+23-25
Original file line numberDiff line numberDiff line change
@@ -94,34 +94,31 @@ if (mlDebug.toBoolean()) {
9494
}
9595

9696
String msystem = "$System.env.MSYSTEM"
97-
if ((isWindows && msystem == 'MINGW64') || isMacOsX || isLinux)
98-
{
99-
// Always do the C++ build using bash (Git bash on Windows using MinGW)
100-
project.ext.shell = isWindows ? "C:\\Program Files\\Git\\bin\\bash" : "/bin/bash"
101-
project.ext.set_env = "source ./set_env.sh"
102-
project.ext.shell_flag = "-c"
103-
project.ext.clean_cmd = "rm -rf ${cmakeBuildDir} 3rd_party/eigen"
104-
// Stripping the binaries is not necessary on windows, execute a no-op command instead
105-
project.ext.strip_cmd = isWindows ? true : "dev-tools/strip_binaries.sh"
106-
} else {
97+
if (isWindows && msystem != 'MINGW64') {
10798
project.ext.shell = "cmd.exe"
108-
project.ext.set_env = ".\\set_env.bat"
109-
project.ext.shell_flag = "/c"
110-
project.ext.clean_cmd = "if exist ${cmakeBuildDir}\\ (rmdir /s /q ${cmakeBuildDir}) && if exist 3rd_party\\eigen (rmdir /s /q 3rd_party\\eigen)"
111-
// Stripping the binaries is not necessary on windows, execute a no-op command instead
112-
project.ext.strip_cmd = "cd ."
99+
project.ext.setEnv = ".\\set_env.bat"
100+
project.ext.shellFlag = "/c"
101+
project.ext.cleanCmd = "if exist ${cmakeBuildDir}\\ (rmdir /s /q ${cmakeBuildDir}) && if exist 3rd_party\\eigen (rmdir /s /q 3rd_party\\eigen)"
102+
// Stripping the binaries is not necessary on Windows, execute a no-op command instead
103+
project.ext.stripCmd = "cd ."
104+
} else {
105+
// Use the bash shell for the C++ build (Git bash when on Windows using MinGW)
106+
project.ext.shell = isWindows ? "C:\\Program Files\\Git\\bin\\bash" : "/bin/bash"
107+
project.ext.setEnv = "source ./set_env.sh"
108+
project.ext.shellFlag = "-c"
109+
project.ext.cleanCmd = "rm -rf ${cmakeBuildDir} 3rd_party/eigen"
110+
// Stripping the binaries is not necessary on Windows, execute a no-op command instead
111+
project.ext.stripCmd = isWindows ? 'true' : "dev-tools/strip_binaries.sh"
113112
}
114113

115-
project.ext.make = (isMacOsX || isWindows) ? "gnumake" : "make"
116-
project.ext.cmake = "cmake"
117114
project.ext.numCpus = Runtime.runtime.availableProcessors()
118115
project.ext.makeEnvironment = [ 'CPP_CROSS_COMPILE': cppCrossCompile,
119116
'VERSION_QUALIFIER': versionQualifier,
120117
'SNAPSHOT': (isSnapshot ? 'yes' : 'no'),
121118
'ML_DEBUG': mlDebug ]
122119

123120
configurations.all {
124-
// check for updates every build
121+
// Check for updates every build
125122
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
126123
}
127124

@@ -130,7 +127,7 @@ clean {
130127
exec {
131128
environment makeEnvironment
132129
commandLine shell
133-
args shell_flag, "${set_env} && ${clean_cmd}"
130+
args shellFlag, "${setEnv} && ${cleanCmd}"
134131
workingDir "${projectDir}"
135132
}
136133
}
@@ -139,29 +136,29 @@ clean {
139136
task configure(type: Exec) {
140137
environment makeEnvironment
141138
commandLine shell
142-
args shell_flag, "${set_env} && ${cmake} -B ${cmakeBuildDir} ${cmakeFlags}"
139+
args shellFlag, "${setEnv} && cmake -B ${cmakeBuildDir} ${cmakeFlags}"
143140
workingDir "${projectDir}"
144141
}
145142

146143
task compile(type: Exec) {
147144
environment makeEnvironment
148145
commandLine shell
149-
args shell_flag, "${set_env} && ${cmake} --build ${cmakeBuildDir} --config ${cmakeBuildType} -t install -v -j ${numCpus}"
146+
args shellFlag, "${setEnv} && cmake --build ${cmakeBuildDir} --config ${cmakeBuildType} -v -j ${numCpus} -t install"
150147
workingDir "${projectDir}"
151148
dependsOn 'configure'
152149
}
153150

154151
task strip(type: Exec) {
155152
environment makeEnvironment
156153
commandLine shell
157-
args shell_flag, "${set_env} && ${strip_cmd}"
154+
args shellFlag, "${setEnv} && ${stripCmd}"
158155
workingDir "${projectDir}"
159156
dependsOn 'compile'
160157
}
161158

162159
task format(type: Exec) {
163160
commandLine shell
164-
args shell_flag, "${set_env} && ${cmake} -P cmake/clang-format.cmake"
161+
args shellFlag, "${setEnv} && cmake -P cmake/clang-format.cmake"
165162
workingDir "${projectDir}"
166163
}
167164

@@ -220,7 +217,7 @@ String artifactGroupPath = project.group.replaceAll("\\.", "/")
220217
task test(type: Exec) {
221218
environment makeEnvironment
222219
commandLine shell
223-
args shell_flag, "${set_env} && ${cmake} --build ${cmakeBuildDir} --config ${cmakeBuildType} -v -j ${numCpus} -t test"
220+
args shellFlag, "${setEnv} && cmake --build ${cmakeBuildDir} --config ${cmakeBuildType} -v -j ${numCpus} -t test"
224221
workingDir "${projectDir}"
225222
dependsOn 'strip'
226223
description = 'Run C++ tests'
@@ -428,7 +425,8 @@ task buildDependencyReport(type: Exec) {
428425
outputs.file("${buildDir}/distributions/dependencies-${version}.csv")
429426
environment makeEnvironment
430427
commandLine shell
431-
args '-c', "source ./set_env.sh && 3rd_party/dependency_report.sh --csv \"${outputs.files.singleFile}\""
428+
// TODO: this won't work on Windows outside of Git bash
429+
args shellFlag, "${setEnv} && 3rd_party/dependency_report.sh --csv \"${outputs.files.singleFile}\""
432430
workingDir "${projectDir}"
433431
description = 'Create a CSV report on 3rd party dependencies we redistribute'
434432
}

Diff for: cmake/variables.cmake

+15-9
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,16 @@ list(APPEND ML_COMPILE_DEFINITIONS BOOST_ALL_DYN_LINK BOOST_MATH_NO_LONG_DOUBLE_
3535

3636
if(NOT DEFINED ENV{CMAKE_INSTALL_PREFIX})
3737
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
38-
set(CMAKE_INSTALL_PREFIX ${CPP_PLATFORM_HOME}/controller.app/Contents/)
38+
set(CMAKE_INSTALL_PREFIX "${CPP_PLATFORM_HOME}/controller.app/Contents/")
3939
else()
40-
set(CMAKE_INSTALL_PREFIX ${CPP_PLATFORM_HOME})
41-
message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
40+
set(CMAKE_INSTALL_PREFIX "${CPP_PLATFORM_HOME}")
4241
endif()
4342
else()
44-
set(CMAKE_INSTALL_PREFIX $ENV{CMAKE_INSTALL_PREFIX})
43+
set(CMAKE_INSTALL_PREFIX "$ENV{CMAKE_INSTALL_PREFIX}")
4544
endif()
4645

47-
string(REPLACE "\\" "/" CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
48-
message(STATUS "CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}")
46+
string(REPLACE "\\" "/" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
47+
message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
4948

5049
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
5150
if (CMAKE_CROSSCOMPILING)
@@ -65,12 +64,17 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
6564
endif()
6665
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
6766
set(ML_BOOST_COMPILER_VER "gcc${CMAKE_CXX_COMPILER_VERSION_MAJOR}")
68-
else()
67+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
6968
string(CONCAT BOOST_VCVER "vc" ${VCVER_MAJOR} ${VCVER_MINOR} )
7069
string(SUBSTRING ${BOOST_VCVER} 0 5 BOOST_VCVER)
7170
message(STATUS "BOOST_VCVER ${BOOST_VCVER}")
7271

7372
set(ML_BOOST_COMPILER_VER ${BOOST_VCVER})
73+
if(NOT BOOST_ROOT AND NOT DEFINED ENV{BOOST_ROOT})
74+
set(BOOST_ROOT ${ROOT}/usr/local)
75+
endif()
76+
else()
77+
message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}")
7478
endif()
7579
message(STATUS "ML_BOOST_COMPILER_VER ${ML_BOOST_COMPILER_VER}")
7680

@@ -153,17 +157,19 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
153157
endif()
154158

155159
# Dictate which flags to use for a "Release" build
156-
message(STATUS "CMAKE_CXX_FLAGS_RELEASE = ${CMAKE_CXX_FLAGS_RELEASE}")
157160
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
158-
set(CMAKE_CXX_FLAGS_RELEASE "/O2 /DNDEBUG /DEXCLUDE_TRACE_LOGGING /Qfast_transcendentals /Qvec-report:1")
161+
set(CMAKE_CXX_FLAGS_RELEASE "/O2 /D NDEBUG /D EXCLUDE_TRACE_LOGGING /Qfast_transcendentals /Qvec-report:1")
162+
set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1")
159163
endif()
160164

161165
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
162166
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -DEXCLUDE_TRACE_LOGGING -Wdisabled-optimization -D_FORTIFY_SOURCE=2")
167+
set(CMAKE_CXX_FLAGS_DEBUG "-g")
163168
endif()
164169

165170
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
166171
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -DEXCLUDE_TRACE_LOGGING")
172+
set(CMAKE_CXX_FLAGS_DEBUG "-g")
167173
endif()
168174
message(STATUS "CMAKE_CXX_FLAGS_RELEASE = ${CMAKE_CXX_FLAGS_RELEASE}")
169175
message(STATUS "CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}")

Diff for: dev-tools/docker/docker_entrypoint.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cd "$MY_DIR/../.."
3131
cmake -B cmake-build-docker ${CMAKE_FLAGS}
3232

3333
# Build the code
34-
cmake --build cmake-build-docker --config Release -j`nproc` -v -t install
34+
cmake --build cmake-build-docker -v -j`nproc` -t install
3535

3636
# Strip the binaries
3737
dev-tools/strip_binaries.sh
@@ -62,6 +62,6 @@ if [ "x$1" = "x--test" ] ; then
6262
# failure is the unit tests, and then the detailed test results can be
6363
# copied from the image
6464
echo passed > build/test_status.txt
65-
cmake --build cmake-build-docker --config Release -t test -j`nproc` || echo failed > build/test_status.txt
65+
cmake --build cmake-build-docker -v -j`nproc` -t test || echo failed > build/test_status.txt
6666
fi
6767

Diff for: set_env.bat

+30-31
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
1-
@echo off
2-
REM
3-
REM Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4-
REM or more contributor license agreements. Licensed under the Elastic License
5-
REM 2.0 and the following additional limitation. Functionality enabled by the
6-
REM files subject to the Elastic License 2.0 may only be used in production when
7-
REM invoked by an Elasticsearch process with a license key installed that permits
8-
REM use of machine learning features. You may not use this file except in
9-
REM compliance with the Elastic License 2.0 and the foregoing additional
10-
REM limitation.
11-
REM
12-
13-
REM Set up a build environment, to ensure repeatable builds
14-
15-
REM Initialize the Visual Studio command prompt environment variables
16-
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
17-
18-
REM Set %CPP_SRC_HOME% to be an absolute path to this script's location, as
19-
REM different builds will come from different repositories and go to different
20-
REM staging areas
21-
SET CPP_SRC_HOME=%~dp0
22-
23-
REM Logical filesystem root
24-
SET ROOT=%CD:~0,2%
25-
26-
SET PATH=%ROOT%/PROGRA~1/CMake/bin;%CPP_SRC_HOME%/build/distribution/platform/windows-x86_64/bin;%PATH%
27-
28-
SET BOOST_ROOT=%ROOT%/usr/local
29-
30-
SET INCLUDE=
31-
SET LIBPATH=
1+
@echo off
2+
rem
3+
rem Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4+
rem or more contributor license agreements. Licensed under the Elastic License
5+
rem 2.0 and the following additional limitation. Functionality enabled by the
6+
rem files subject to the Elastic License 2.0 may only be used in production when
7+
rem invoked by an Elasticsearch process with a license key installed that permits
8+
rem use of machine learning features. You may not use this file except in
9+
rem compliance with the Elastic License 2.0 and the foregoing additional
10+
rem limitation.
11+
rem
12+
13+
rem Set up a build environment, to ensure repeatable builds
14+
15+
rem Initialize the Visual Studio command prompt environment variables
16+
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
17+
18+
rem Set %CPP_SRC_HOME% to be an absolute path to this script's location, as
19+
rem different builds will come from different repositories and go to different
20+
rem staging areas
21+
set CPP_SRC_HOME=%~dp0
22+
23+
rem Assume the drive letter where our 3rd party dependencies are installed under
24+
rem \usr\local is the current drive at the time this script is run
25+
set ROOT=%CD:~0,2%
26+
27+
set PATH=C:\Program Files\CMake\bin;%CPP_SRC_HOME%\build\distribution\platform\windows-x86_64\bin;%PATH%
28+
29+
set INCLUDE=
30+
set LIBPATH=

Diff for: set_env.sh

+9-31
Original file line numberDiff line numberDiff line change
@@ -130,44 +130,28 @@ case $SIMPLE_PLATFORM in
130130

131131
esac
132132

133-
# do not cache in Jenkins
133+
# Do not cache in Jenkins
134134
if [ -z "$JOB_NAME" ] ; then
135-
# check if CCACHE is available and use it if it's found
135+
# Check if CCACHE is available and use it if it's found
136136
if [ -d "/usr/lib/ccache" ] ; then
137-
PATH=/usr/lib/ccache/:$PATH
138-
# on centos it should be in /usr/lib64/ccache when installed with yum.
137+
PATH=/usr/lib/ccache:$PATH
138+
# On CentOS it should be in /usr/lib64/ccache when installed with yum.
139139
elif [ -d "/usr/lib64/ccache" ] ; then
140-
PATH=/usr/lib64/ccache/:$PATH
141-
# on Mac it should be /usr/local/lib when installed with brew
140+
PATH=/usr/lib64/ccache:$PATH
141+
# On macOS it should be /usr/local/lib when installed with brew
142142
elif [ -d "/usr/local/lib/ccache" ] ; then
143-
PATH=/usr/local/lib/ccache/:$PATH
143+
PATH=/usr/local/lib/ccache:$PATH
144144
fi
145145
fi
146146

147-
148147
export PATH
149148

150-
# GNU make
151-
case $SIMPLE_PLATFORM in
152-
153-
linux*)
154-
MAKE=`which make`
155-
;;
156-
157-
macos|windows)
158-
MAKE=`which gnumake`
159-
;;
160-
161-
esac
162-
163-
export MAKE
164-
165149
# Localisation - don't use any locale specific functionality
166150
export LC_ALL=C
167151

168152
# Unset environment variables that affect the choice of compiler/linker, or
169-
# where the compiler/linker look for dependencies - we only want what's in our
170-
# Makefiles
153+
# where the compiler/linker look for dependencies - we only want to use what's
154+
# explicitly defined in our build files
171155
unset CPP
172156
unset CC
173157
unset CXX
@@ -186,9 +170,3 @@ else
186170
unset LIBRARY_PATH
187171
fi
188172

189-
# Tell the build to keep going under Jenkins so that we get as many errors as
190-
# possible from an automated build (Jenkins sets $JOB_NAME)
191-
if [ -n "$JOB_NAME" ] ; then
192-
export ML_KEEP_GOING=1
193-
fi
194-

0 commit comments

Comments
 (0)