Skip to content

Commit

Permalink
fix(ci): do not use mongodbtoolchain v4 to compile mongosh MONGOSH-1604
Browse files Browse the repository at this point in the history
… (#1684)

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.
  • Loading branch information
addaleax authored Sep 26, 2023
1 parent 03d1bc9 commit d790fcb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions .evergreen/compile-artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion .evergreen/setup-env.sh
Original file line number Diff line number Diff line change
@@ -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"

Expand Down

0 comments on commit d790fcb

Please sign in to comment.