Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4877,6 +4877,7 @@ functions:
binary: bash .evergreen/compile-artifact.sh
env:
NODE_JS_VERSION: ${node_js_version}
MONGOSH_SHARED_OPENSSL: ${mongosh_shared_openssl}
- command: s3.put
params:
aws_key: ${aws_key}
Expand Down Expand Up @@ -9057,13 +9058,37 @@ buildvariants:
executable_os_id: linux-x64
tasks:
- name: compile_artifact
- name: linux_x64_build_openssl11
display_name: "RHEL 7.0 x64 (build, shared OpenSSL 1.1)"
run_on: rhel70-build
expansions:
executable_os_id: linux-x64-openssl11
mongosh_shared_openssl: openssl11
tasks:
- name: compile_artifact
- name: linux_x64_build_openssl3
display_name: "RHEL 7.0 x64 (build, shared OpenSSL 3)"
run_on: rhel70-build
expansions:
executable_os_id: linux-x64-openssl3
mongosh_shared_openssl: openssl3
tasks:
- name: compile_artifact
- name: linux_arm64_build
display_name: "Amazon 2 arm64 (build)"
run_on: amazon2-arm64-small
expansions:
executable_os_id: linux-arm64
tasks:
- name: compile_artifact
- name: linux_arm64_build_openssl11
display_name: "Amazon 2 arm64 (build, shared OpenSSL 1.1)"
run_on: amazon2-arm64-small
expansions:
executable_os_id: linux-arm64-openssl11
mongosh_shared_openssl: openssl11
tasks:
- name: compile_artifact
- name: linux_ppc64le_build
display_name: "RHEL 8.1 PPC (build)"
run_on: rhel81-power8-small
Expand Down
48 changes: 46 additions & 2 deletions .evergreen/compile-artifact.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
set -e
set -x

cd $(pwd)

Expand All @@ -13,9 +14,52 @@ if uname -a | grep -q 'Linux.*x86_64'; then
export CXX="$PWD/tmp/.sccache/sccache g++"
fi

rm -rf /tmp/m && mkdir -pv /tmp/m # Node.js compilation can fail on long path prefixes
trap "rm -rf /tmp/m" EXIT
export TMP=/tmp/m
export TMPDIR=/tmp/m

# The CI machines we have for Windows and x64 macOS are not
# able to compile OpenSSL with assembly support,
# so we revert back to the slower version.
if [ "$OS" == "Windows_NT" ]; then
export NODE_JS_CONFIGURE_ARGS='["openssl-no-asm"]'
elif uname -a | grep -q 'Darwin.*x86_64'; then
export NODE_JS_CONFIGURE_ARGS='["--openssl-no-asm"]'
elif [ -n "$MONGOSH_SHARED_OPENSSL" ]; then
pushd /tmp/m
if [ "$MONGOSH_SHARED_OPENSSL" == "openssl11" ]; then
curl -sSfLO https://www.openssl.org/source/openssl-1.1.1o.tar.gz
MONGOSH_OPENSSL_LIBNAME=:libcrypto.so.1.1,:libssl.so.1.1
elif [ "$MONGOSH_SHARED_OPENSSL" == "openssl3" ]; then
curl -sSfLO https://www.openssl.org/source/openssl-3.0.2.tar.gz
MONGOSH_OPENSSL_LIBNAME=:libcrypto.so.3,:libssl.so.3
else
echo "Unknown MONGOSH_SHARED_OPENSSL value: $MONGOSH_SHARED_OPENSSL"
exit 1
fi

tar xzvf openssl-*.tar.gz
pushd openssl-*
./config --prefix=/tmp/m/opt --libdir=lib shared
make -j12
make -j12 install install_ssldirs

popd # openssl-*
popd # /tmp/m

export NODE_JS_CONFIGURE_ARGS='[
"--shared-openssl",
"--shared-openssl-includes=/tmp/m/opt/include",
"--shared-openssl-libpath=/tmp/m/opt/lib",
"--shared-openssl-libname='"$MONGOSH_OPENSSL_LIBNAME"'",
"--shared-zlib"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t know why specifically this is necessary, but it’s definitely related to the Node.js build system being a bit wonky around zlib support (because Node.js itself doesn’t bundle the original zlib, and instead uses an API-compatible fork from Chromium). I guess the --shared-openssl setting has some influence on the zlib build. In any case, this should be fairly unproblematic since zlib is almost universally available on Linux.

]'
export LD_LIBRARY_PATH=/tmp/m/opt/lib
fi

export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
mkdir -pv /tmp/m # Node.js compilation can fail on long path prefixes
(env TMP=/tmp/m TMPDIR=/tmp/m npm run evergreen-release compile && rm -rf /tmp/m) || (rm -rf /tmp/m; false)
npm run evergreen-release compile
dist/mongosh --version
dist/mongosh --build-info
dist/mongosh --build-info | grep -q '"distributionKind": "compiled"'
Expand Down
25 changes: 25 additions & 0 deletions .evergreen/evergreen.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ functions:
binary: bash .evergreen/compile-artifact.sh
env:
NODE_JS_VERSION: ${node_js_version}
MONGOSH_SHARED_OPENSSL: ${mongosh_shared_openssl}
- command: s3.put
params:
aws_key: ${aws_key}
Expand Down Expand Up @@ -965,13 +966,37 @@ buildvariants:
executable_os_id: linux-x64
tasks:
- name: compile_artifact
- name: linux_x64_build_openssl11
display_name: "RHEL 7.0 x64 (build, shared OpenSSL 1.1)"
run_on: rhel70-build
expansions:
executable_os_id: linux-x64-openssl11
mongosh_shared_openssl: openssl11
tasks:
- name: compile_artifact
- name: linux_x64_build_openssl3
display_name: "RHEL 7.0 x64 (build, shared OpenSSL 3)"
run_on: rhel70-build
expansions:
executable_os_id: linux-x64-openssl3
mongosh_shared_openssl: openssl3
tasks:
- name: compile_artifact
- name: linux_arm64_build
display_name: "Amazon 2 arm64 (build)"
run_on: amazon2-arm64-small
expansions:
executable_os_id: linux-arm64
tasks:
- name: compile_artifact
- name: linux_arm64_build_openssl11
display_name: "Amazon 2 arm64 (build, shared OpenSSL 1.1)"
run_on: amazon2-arm64-small
expansions:
executable_os_id: linux-arm64-openssl11
mongosh_shared_openssl: openssl11
tasks:
- name: compile_artifact
- name: linux_ppc64le_build
display_name: "RHEL 8.1 PPC (build)"
run_on: rhel81-power8-small
Expand Down
14 changes: 7 additions & 7 deletions packages/build/src/compile/signable-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-nested-ternary */
import os from 'os';
import { promises as fs } from 'fs';
import Module from 'module';
import pkgUp from 'pkg-up';
Expand Down Expand Up @@ -116,13 +114,15 @@ export class SignableCompiler {
requireRegexp: /\bget_console_process_list\.node$/
} : null;

let configureArgs: string[] = [];

if (process.env.NODE_JS_CONFIGURE_ARGS) {
configureArgs = JSON.parse(process.env.NODE_JS_CONFIGURE_ARGS);
}

// This compiles the executable along with Node from source.
// Evergreen and XCode don't have up to date libraries to compile
// open ssl with asm so we revert back to the slower version.
await compileJSFileAsBinary({
configureArgs:
os.platform() === 'win32' ? ['openssl-no-asm'] :
os.platform() === 'darwin' ? ['--openssl-no-asm'] : [],
configureArgs,
sourceFile: this.sourceFile,
targetFile: this.targetFile,
nodeVersionRange: this.nodeVersionRange,
Expand Down
21 changes: 13 additions & 8 deletions packages/cli-repl/src/build-info.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
import os from 'os';

export type BuildInfo = {
version: string;
nodeVersion: string;
distributionKind: 'unpackaged' | 'packaged' | 'compiled';
buildArch: string;
buildPlatform: string;
buildArch: typeof process['arch'];
buildPlatform: typeof process['platform'];
buildTarget: string;
buildTime: string | null;
gitVersion: string | null;
opensslVersion: string;
sharedOpenssl: boolean;
};

/**
* Return an object with information about this mongosh instance,
* in particular, when it was built and how.
*/
export function buildInfo(): BuildInfo {
const runtimeData = {
nodeVersion: process.version,
opensslVersion: process.versions.openssl,
sharedOpenssl: !!process.config.variables.node_shared_openssl
};
try {
const buildInfo = { ...require('./build-info.json'), nodeVersion: process.version };
const buildInfo = { ...require('./build-info.json'), ...runtimeData };
delete buildInfo.segmentApiKey;
return buildInfo;
} catch {
const { version } = require('../package.json');
return {
version,
distributionKind: 'unpackaged',
buildArch: os.arch(),
buildPlatform: os.platform(),
buildArch: process.arch,
buildPlatform: process.platform,
buildTarget: 'unknown',
buildTime: null,
gitVersion: null,
nodeVersion: process.version
...runtimeData
};
}
}
6 changes: 4 additions & 2 deletions packages/cli-repl/test/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ describe('e2e', function() {
const data = JSON.parse(shell.output);
expect(Object.keys(data)).to.deep.equal([
'version', 'distributionKind', 'buildArch', 'buildPlatform',
'buildTarget', 'buildTime', 'gitVersion', 'nodeVersion'
'buildTarget', 'buildTime', 'gitVersion', 'nodeVersion',
'opensslVersion', 'sharedOpenssl'
]);
expect(data.version).to.be.a('string');
expect(data.nodeVersion).to.be.a('string');
expect(data.distributionKind).to.be.a('string');
expect(['unpackaged', 'packaged', 'compiled'].includes(data.distributionKind)).to.be.true;
expect(data.buildArch).to.be.a('string');
expect(data.buildPlatform).to.be.a('string');
expect(data.buildTarget).to.be.a('string');
expect(data.opensslVersion).to.be.a('string');
expect(data.sharedOpenssl).to.be.a('boolean');
if (data.distributionKind !== 'unpackaged') {
expect(data.buildTime).to.be.a('string');
expect(data.gitVersion).to.be.a('string');
Expand Down