Skip to content

Commit 0fae13f

Browse files
committed
Use --auto-install-deps instead of --auto-install-gcc
1 parent ac89981 commit 0fae13f

2 files changed

Lines changed: 29 additions & 21 deletions

File tree

jvector-native/src/main/c/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ The script:
7171
4. Optionally re-generates the Java FFM bindings via `jextract` (only needed
7272
when `jvector_simd.h` changes — see [Updating the Java bindings](#updating-the-java-bindings)).
7373

74+
To install all required dependencies automatically (g++, meson, ninja) and then build, pass `--auto-install-deps`:
75+
76+
```bash
77+
bash jextract_vector_simd.sh --auto-install-deps
78+
```
79+
80+
This is the easiest way to get started on a fresh Ubuntu machine. For other
81+
distributions the script will print an error indicating which install commands
82+
need to be added.
83+
7484
To build without regenerating bindings (e.g. when `jextract` is not installed):
7585

7686
```bash

jvector-native/src/main/c/jextract_vector_simd.sh

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ set -e
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
1919

20-
if [ "$1" == "--auto-install-gcc" ] || [ "$1" == "--auto-install-g++" ] ; then AUTO_INSTALL_GCC=true ; shift ; fi
21-
printf "AUTO_INSTALL_GCC=%s\n" "${AUTO_INSTALL_GCC}"
20+
if [ "$1" == "--auto-install-deps" ] ; then AUTO_INSTALL_DEPS=true ; shift ; fi
21+
printf "AUTO_INSTALL_DEPS=%s\n" "${AUTO_INSTALL_DEPS}"
2222

2323
mkdir -p ../resources
2424
# compile jvector_simd_check.cpp as x86-64
@@ -39,20 +39,28 @@ fi
3939
# Desired minimum GCC version
4040
MIN_GCC_VERSION=11
4141

42-
if ! command -v g++ &> /dev/null; then
43-
if [ "$AUTO_INSTALL_GCC" == "true" ]
44-
then
42+
# Ensures $1 (a command) is available. If not and AUTO_INSTALL_DEPS=true, runs
43+
# the Ubuntu apt/pip install given in $2; otherwise prints $2 as a hint and exits.
44+
# Usage: require_cmd <cmd> <ubuntu-install-cmd>
45+
require_cmd() {
46+
local cmd="$1" ubuntu_install="$2"
47+
if command -v "${cmd}" &> /dev/null; then return; fi
48+
if [ "${AUTO_INSTALL_DEPS}" == "true" ]; then
4549
LSB_RELEASE=$(lsb_release --id --short)
4650
printf "LSB_RELEASE=%s\n" "${LSB_RELEASE}"
47-
if [ "${LSB_RELEASE}" == "Ubuntu" ]
48-
then sudo apt update && sudo apt install -y g++
49-
else printf "distribution %s needs a g++ install command in %s\n" "${LSB_RELEASE}" "${0}" ; exit 2
51+
if [ "${LSB_RELEASE}" == "Ubuntu" ]; then
52+
eval "sudo apt-get update && ${ubuntu_install}"
53+
else
54+
printf "distribution %s needs a '%s' install command in %s\n" "${LSB_RELEASE}" "${cmd}" "${0}" ; exit 2
5055
fi
5156
else
52-
echo "g++ is not installed. Please install g++ 11+ to build supporting native libraries."
53-
exit 2
57+
printf "'%s' is not installed. To install it, run: %s\n" "${cmd}" "${ubuntu_install}" ; exit 2
5458
fi
55-
fi
59+
}
60+
61+
require_cmd g++ "sudo apt-get install -y g++"
62+
require_cmd meson "sudo apt-get install -y meson"
63+
require_cmd ninja "sudo apt-get install -y ninja-build"
5664

5765
# Check g++ version
5866
CURRENT_GPP_VERSION=$(g++ -dumpversion)
@@ -63,16 +71,6 @@ if [ "$(printf '%s\n' "$MIN_GCC_VERSION" "$CURRENT_GPP_VERSION" | sort -V | head
6371
exit 1
6472
fi
6573

66-
# Check meson and ninja are available
67-
if ! command -v meson &> /dev/null; then
68-
echo "meson is not installed. Please install it: pip install meson or sudo apt install meson"
69-
exit 2
70-
fi
71-
if ! command -v ninja &> /dev/null; then
72-
echo "ninja is not installed. Please install it: sudo apt install ninja-build"
73-
exit 2
74-
fi
75-
7674
BUILD_DIR="build"
7775
rm -rf ../resources/libjvector.so
7876

0 commit comments

Comments
 (0)