@@ -21,6 +21,22 @@ log_error() {
2121 echo -e " ${RED} [ERROR]${NC} $1 " >&2
2222}
2323
24+ # Elevation helper.
25+ #
26+ # This script is both a developer convenience and cibuildwheel's `before-all`
27+ # (see [tool.cibuildwheel] in pyproject.toml), where it runs as root inside the
28+ # manylinux container with no sudo available. Running as root leaves SUDO empty,
29+ # so every command below is byte-for-byte what it was before this helper existed.
30+ SUDO=" "
31+ if [[ ${EUID} -ne 0 ]]; then
32+ if command -v sudo > /dev/null 2>&1 ; then
33+ SUDO=" sudo"
34+ else
35+ log_error " This script needs root privileges, but neither root nor sudo is available."
36+ exit 1
37+ fi
38+ fi
39+
2440# Install and configure g++ version
2541install_gcc () {
2642 log_info " Installing and configuring g++ version..."
@@ -96,7 +112,7 @@ install_zstd() {
96112 pushd _build > /dev/null
97113 cmake -G Ninja ..
98114 ninja
99- ninja install
115+ ${SUDO} ninja install
100116 popd > /dev/null
101117 popd > /dev/null
102118 popd > /dev/null
@@ -114,7 +130,7 @@ install_xgboost() {
114130 pushd build > /dev/null
115131 cmake -G Ninja ..
116132 ninja
117- ninja install
133+ ${SUDO} ninja install
118134 popd > /dev/null
119135 popd > /dev/null
120136 popd > /dev/null
@@ -132,16 +148,45 @@ install_lightgbm() {
132148 pushd build > /dev/null
133149 cmake -G Ninja ..
134150 ninja
135- ninja install
151+ ${SUDO} ninja install
136152 popd > /dev/null
137153 popd > /dev/null
138154 popd > /dev/null
139155}
140156
141- # Detect OS and install dependencies
142- if [[ " $OSTYPE " == " linux-gnu" * ]]; then
143- log_info " Detected Linux system, installing dependencies via yum..."
144-
157+ # Detect OS and install dependencies.
158+ #
159+ # Dispatch on the available package manager rather than on $OSTYPE alone, so that
160+ # this covers the same platforms as upstream's
161+ # src/libCacheSim/scripts/install_dependency.sh (Debian/Ubuntu/WSL, macOS,
162+ # CentOS/RHEL). macOS is matched first; the manylinux images used for the release
163+ # wheels ship yum/dnf but no apt-get, so they still take the yum branch below.
164+ if [[ " $OSTYPE " == " darwin" * ]]; then
165+ log_info " Detected macOS system, installing dependencies via brew..."
166+
167+ # Install basic dependencies via Homebrew
168+ brew install glib google-perftools argp-standalone xxhash llvm wget cmake ninja zstd xgboost lightgbm
169+
170+ elif command -v apt-get > /dev/null 2>&1 ; then
171+ log_info " Detected Debian/Ubuntu system, installing dependencies via apt..."
172+
173+ ${SUDO} apt-get update
174+ # CMakeLists.txt requires pkg-config, GLib 2.0 and Zstandard; the rest mirrors
175+ # upstream's setup_ubuntu. Unlike the yum branch there is no need to build CMake
176+ # or Zstd from source, since apt ships cmake >= 3.15 and libzstd-dev.
177+ ${SUDO} apt-get install -y --no-install-recommends \
178+ build-essential pkg-config git wget cmake ninja-build \
179+ libglib2.0-dev libzstd-dev \
180+ libgoogle-perftools-dev google-perftools xxhash libunwind-dev
181+
182+ # Needed by the optional learned algorithms (ENABLE_GLCACHE / ENABLE_3L_CACHE /
183+ # ENABLE_LRB); no distro packages provide the CMake config files these need.
184+ install_xgboost
185+ install_lightgbm
186+
187+ elif command -v yum > /dev/null 2>&1 || command -v dnf > /dev/null 2>&1 ; then
188+ log_info " Detected CentOS/RHEL system, installing dependencies via yum..."
189+
145190 # Enable EPEL repository
146191 yum install -y epel-release
147192
@@ -167,15 +212,9 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
167212 install_zstd
168213 install_xgboost
169214 install_lightgbm
170-
171- elif [[ " $OSTYPE " == " darwin" * ]]; then
172- log_info " Detected macOS system, installing dependencies via brew..."
173-
174- # Install basic dependencies via Homebrew
175- brew install glib google-perftools argp-standalone xxhash llvm wget cmake ninja zstd xgboost lightgbm
176-
215+
177216else
178- log_error " Unsupported operating system: $OSTYPE "
217+ log_error " Unsupported operating system: $OSTYPE (no brew, apt-get, yum or dnf found) "
179218 exit 1
180219fi
181220
0 commit comments