From d790fcb54b6562826eae688997f4ead4db017a58 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 26 Sep 2023 14:39:34 +0200 Subject: [PATCH] fix(ci): do not use mongodbtoolchain v4 to compile mongosh MONGOSH-1604 (#1684) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On x64 Linux, the v4 mongodbtoolchain gcc is configured with `--with-arch=sandybridge`, raising the minimum CPU requirements to that level. In particular, availability of the AVX CPU feature is made a prerequisite for the generated executables to run. It is possible to override this default for the v4 mongodbtoolchain when compiling a specific executable. However, another quirk of this toolchain (and reason why we want to migrate away from it) is that it statically links in the C++ standard library, which has unfortunately been compiled using the compiler's defaults. On the server side, 5.0+ uses AVX as a minimum hardware requirement, but since mongosh 2.x is intended to support both 4.2 and 4.4, we should stick to the requirements of these older versions. So, for now, just switch back to the v3 mongodbtoolchain, which seems to work fine in terms of compiling mongosh. The Node.js configure script *does* warn that the gcc version (8.5.0) in this toolchain is no longer officially supported, so that underlines the importance of switching away from the server’s toolchain in the near future (MONGOSH-864). We “test” this by inspecting the generated binary and looking at the instructions it contains, rather than trying to emulate older hardware. --- .evergreen/compile-artifact.sh | 20 ++++++++++++++++++-- .evergreen/setup-env.sh | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.evergreen/compile-artifact.sh b/.evergreen/compile-artifact.sh index 606ebd666..ffef8040b 100755 --- a/.evergreen/compile-artifact.sh +++ b/.evergreen/compile-artifact.sh @@ -45,8 +45,8 @@ elif [ -n "$MONGOSH_SHARED_OPENSSL" ]; then exit 1 fi - tar xzvf openssl-*.tar.gz - + tar xzvf openssl-*.tar.gz + # pushd fails on RHEL8 because openssl-* expands to 2 different files. For example: # pushd openssl-1.1.1o openssl-1.1.1o.tar.gz # .evergreen/compile-artifact.sh: line 49: pushd: too many arguments @@ -76,6 +76,22 @@ dist/mongosh --version dist/mongosh --build-info dist/mongosh --build-info | grep -q '"distributionKind": "compiled"' +if uname -a | grep -q 'Linux.*x86_64'; then + # Very crude test to check whether the generated executable was built + # with -mavx when it should not have been. Ideally, we'd be running + # on older hardware to verify minimum requirements, but that's not easily + # possible in CI, so we just check whether the generated executable contains + # a specific (common) AVX instruction. We can't just check whether the + # instruction exists at all in the executable or not, because Node.js + # includes libraries that provide both AVX and non-AVX versions of their + # code (and similar for other hardware features) and then choose which code + # path to take at runtime. + # As of mongosh 2.0.1, the difference is 308 vs 5084, so take 1250 + # as the cutoff at which we need to be 'suspicious' that we might have + # accidentally raised hardware requirements by changing how we compile mongosh. + test $(objdump -d dist/mongosh | grep '\bvmovd\b' | wc -l) -lt 1250 +fi + tar cvzf dist.tgz dist source .evergreen/compilation-context-expansions.sh diff --git a/.evergreen/setup-env.sh b/.evergreen/setup-env.sh index 14238bdcd..5be6e4d85 100755 --- a/.evergreen/setup-env.sh +++ b/.evergreen/setup-env.sh @@ -1,7 +1,7 @@ set -e set -x export BASEDIR="$PWD/.evergreen" -export PATH="/cygdrive/c/python/Python311/Scripts:/cygdrive/c/python/Python311:/cygdrive/c/Python311/Scripts:/cygdrive/c/Python311:/opt/python/3.6/bin:$BASEDIR/mingit/cmd:$BASEDIR/mingit/mingw64/libexec/git-core:$BASEDIR/git-2:$BASEDIR/npm-9/node_modules/.bin:$BASEDIR/node-v$NODE_JS_VERSION-win-x64:/opt/java/jdk16/bin:/opt/chefdk/gitbin:/cygdrive/c/cmake/bin:/opt/mongodbtoolchain/v4/bin:/opt/mongodbtoolchain/v3/bin:$PATH" +export PATH="/cygdrive/c/python/Python311/Scripts:/cygdrive/c/python/Python311:/cygdrive/c/Python311/Scripts:/cygdrive/c/Python311:/opt/python/3.6/bin:$BASEDIR/mingit/cmd:$BASEDIR/mingit/mingw64/libexec/git-core:$BASEDIR/git-2:$BASEDIR/npm-9/node_modules/.bin:$BASEDIR/node-v$NODE_JS_VERSION-win-x64:/opt/java/jdk16/bin:/opt/chefdk/gitbin:/cygdrive/c/cmake/bin:/opt/mongodbtoolchain/v3/bin:$PATH" export IS_MONGOSH_EVERGREEN_CI=1 export DEBUG="mongodb*,$DEBUG"