ยง2023-07-21

Note: In order to compile C-based Python modules, you'll also need the Python and OpenSSL C headers. Run:

Fedora/RHEL - dnf install python3-devel openssl-devel
Ubuntu (20.04 and newer)/Debian (Bullseye and newer) - apt install python-dev-is-python3 libssl-dev
Ubuntu (18.04 and older)/Debian (Buster and older) - apt install python3.7-dev libssl-dev

  1. Requirements
$ sudo apt update && sudo apt -y upgrade
$ sudo apt install -y build-essential libcurl4-openssl-dev liblzma-dev libssl-dev python3-dev git openssl-devel?
  1. Python3
$ python3 --version
Python 3.10.6
$ sudo apt install python3.10-venv
$ python3 -m venv ~/PYTHON-3.10.6
$ source ~/PYTHON-3.10.6/bin/activate
(PYTHON-3.10.6) orangepi@orangepi5plus: pip3 cache purge
  1. git clone mongo
 $ git clone https://github.com/mongodb/mongo.git && cd mongo
 $ git checkout r7.0.0-rc8 -b test
Updating files: 100% (10380/10380), done.
Switched to a new branch 'test'
  1. pip requirements
$ pip3 install -r etc/pip/compile-requirements.txt
...
Successfully installed Cheetah3-3.2.6.post1 PyYAML-6.0 anyio-3.7.1 boto3-1.28.8 botocore-1.31.8 certifi-2023.5.7 
cffi-1.15.1 charset-normalizer-2.0.12 cryptography-36.0.2 distro-1.8.0 dnspython-2.4.0 exceptiongroup-1.1.2 gitdb-4.0.10 
gitpython-3.1.32 h11-0.14.0 httpcore-0.17.3 idna-3.4 jmespath-1.0.1 mongo-ninja-python-1.11.1.5 mongo-tooling-metrics-1.0.8 
packaging-21.3 psutil-5.8.0 pycparser-2.21 pydantic-1.10.11 pymongo-4.3.3 pymongo-auth-aws-1.1.0 pyparsing-3.1.0 
python-dateutil-2.8.2 regex-2021.11.10 requests-2.26.0 requirements_parser-0.3.1 s3transfer-0.6.1 setuptools-58.5.3 
six-1.16.0 smmap-5.0.0 sniffio-1.3.0 types-PyYAML-6.0.12.11 types-setuptools-57.4.18 
typing-extensions-4.7.1 urllib3-1.26.16

if pip install psutil errors then sudo apt install gcc python3-dev will fix it.

  1. make it
$ cat ~/scripts/buildMongo.sh 
#!/bin/bash

# -j number of CPUS, no plus 2
# execute form git clone https://github.com/mongodb/mongo.git && cd mongo
# under python3 eviromental control
# git checkout r7.0.0-rc8 -b test
time python3 buildscripts/scons.py install-core -j 8 --ssl --linker=gold CFLAGS="-march=armv8-a+crc -mtune=generic" --disable-warnings-as-errors

real   2338m1.180s
user   4999m58.357s
sys     657m34.984s

$ ./mongod --version
db version v7.0.0-rc8
Build Info: {
    "version": "7.0.0-rc8",
    "gitVersion": "27da922959c12df48ae2ecf8aad0f37f42f71451",
    "openSSLVersion": "OpenSSL 3.0.2 15 Mar 2022",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distarch": "aarch64",
        "target_arch": "aarch64"
    }
}
$ ./mongos --version
mongos version v7.0.0-rc8
Build Info: {
    "version": "7.0.0-rc8",
    "gitVersion": "27da922959c12df48ae2ecf8aad0f37f42f71451",
    "openSSLVersion": "OpenSSL 3.0.2 15 Mar 2022",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distarch": "aarch64",
        "target_arch": "aarch64"
    }
}

alexlai@hc4Jammy:~/build/mongo/build/install/bin$ strip --strip-all mongod
alexlai@hc4Jammy:~/build/mongo/build/install/bin$ strip --strip-all mongos
alexlai@hc4Jammy:~/build/mongo/build/install/bin$ ls -l
total 6915784
-rwxrwxr-x 2 alexlai alexlai  122370408 Jul 23 06:11 mongod
-rwxrwxr-x 1 alexlai alexlai 4361409040 Jul 23 06:09 mongod.unstripped
-rwxrwxr-x 2 alexlai alexlai   88525736 Jul 23 06:11 mongos
-rwxrwxr-x 1 alexlai alexlai 2452038576 Jul 23 06:10 mongos.unstripped
-rwxrw-r-- 2 alexlai alexlai       1782 Jul 21 14:01 resmoke.py
alexlai@hc4Jammy:~/build/mongo/build/install/bin$ ./mongod --version
db version v7.0.0-rc8
Build Info: {
    "version": "7.0.0-rc8",
    "gitVersion": "27da922959c12df48ae2ecf8aad0f37f42f71451",
    "openSSLVersion": "OpenSSL 3.0.2 15 Mar 2022",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distarch": "aarch64",
        "target_arch": "aarch64"
    }
}
alexlai@hc4Jammy:~/build/mongo/build/install/bin$ ./mongos --version
mongos version v7.0.0-rc8
Build Info: {
    "version": "7.0.0-rc8",
    "gitVersion": "27da922959c12df48ae2ecf8aad0f37f42f71451",
    "openSSLVersion": "OpenSSL 3.0.2 15 Mar 2022",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distarch": "aarch64",
        "target_arch": "aarch64"
    }
}
After

real   128m19.736s
user    76m6.809s
sys     15m51.545s

Failed to compile
After 

real    42m25.682s
user    42m7.112s
sys      5m41.894s