Skip to content

Commit 7424cff

Browse files
committed
feat: Add native Linux build with mamba environment
Add automated setup script and environment configuration for building ml-metadata natively on Linux without Docker. - environment.yml: mamba environment with Python 3.11, GCC toolchain - setup_and_build.sh: automated Miniforge/Bazelisk install and build - .bazelrc: GCC compatibility flags (C11/C++17, warning suppressions) Enables building on SSH/bare metal systems without sudo access.
1 parent 5c8be32 commit 7424cff

File tree

4 files changed

+172
-0
lines changed

4 files changed

+172
-0
lines changed

.bazelrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,19 @@ build --protocopt=--experimental_allow_proto3_optional
2626
build --incompatible_require_linker_input_cc_api=false
2727
build:macos --apple_platform_type=macos
2828
build:macos_arm64 --cpu=darwin_arm64
29+
build --conlyopt=-std=c11
30+
build --host_conlyopt=-std=c11
31+
build --cxxopt=-std=c++17
32+
build --host_cxxopt=-std=c++17
33+
build --copt=-Wno-error
34+
build --cxxopt=-Wno-error
35+
build --cxxopt=-fpermissive
36+
build --copt=-Wno-array-parameter
37+
build --copt=-Wno-implicit-function-declaration
38+
build --host_copt=-Wno-error
39+
build --host_cxxopt=-Wno-error
40+
build --host_cxxopt=-fpermissive
41+
build --host_copt=-Wno-array-parameter
42+
build --host_copt=-Wno-implicit-function-declaration
43+
build --linkopt=-Wl,--no-as-needed
44+
build --host_linkopt=-Wl,--no-as-needed

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.5.0

environment.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: ml-metadata-build
2+
channels:
3+
- conda-forge
4+
- defaults
5+
dependencies:
6+
- python=3.11
7+
- cmake=3.31
8+
- make
9+
- pkg-config
10+
- c-compiler
11+
- cxx-compiler
12+
- openjdk=21
13+
- setuptools
14+
- wheel
15+
- pip
16+

setup_and_build.sh

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/bin/bash
2+
set -e # Exit on any error
3+
4+
# Configuration
5+
MINIFORGE_DIR="$HOME/miniforge3"
6+
ENV_NAME="ml-metadata-build"
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
9+
echo "=========================================="
10+
echo "ML-Metadata Native Build Setup Script"
11+
echo "=========================================="
12+
echo ""
13+
14+
# Step 1: Install Miniforge (includes mamba) if not already installed
15+
if [ ! -d "$MINIFORGE_DIR" ]; then
16+
echo "Step 1: Installing Miniforge (includes mamba)..."
17+
cd /tmp
18+
19+
# Detect architecture
20+
if [ "$(uname -m)" = "x86_64" ]; then
21+
MINIFORGE_URL="https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh"
22+
elif [ "$(uname -m)" = "aarch64" ]; then
23+
MINIFORGE_URL="https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-aarch64.sh"
24+
else
25+
echo "Unsupported architecture: $(uname -m)"
26+
exit 1
27+
fi
28+
29+
wget "$MINIFORGE_URL" -O miniforge.sh
30+
bash miniforge.sh -b -p "$MINIFORGE_DIR"
31+
rm miniforge.sh
32+
33+
echo "Miniforge installed to $MINIFORGE_DIR"
34+
else
35+
echo "Step 1: Miniforge already installed at $MINIFORGE_DIR"
36+
fi
37+
38+
# Step 2: Install Bazelisk if not already installed
39+
BIN_DIR="$HOME/.local/bin"
40+
mkdir -p "$BIN_DIR"
41+
42+
if [ ! -f "$BIN_DIR/bazelisk" ]; then
43+
echo ""
44+
echo "Step 2: Installing Bazelisk..."
45+
cd /tmp
46+
47+
# Detect architecture
48+
if [ "$(uname -m)" = "x86_64" ]; then
49+
BAZELISK_URL="https://github.com/bazelbuild/bazelisk/releases/download/v1.25.0/bazelisk-linux-amd64"
50+
elif [ "$(uname -m)" = "aarch64" ]; then
51+
BAZELISK_URL="https://github.com/bazelbuild/bazelisk/releases/download/v1.25.0/bazelisk-linux-arm64"
52+
else
53+
echo "Unsupported architecture: $(uname -m)"
54+
exit 1
55+
fi
56+
57+
wget "$BAZELISK_URL" -O "$BIN_DIR/bazelisk"
58+
chmod +x "$BIN_DIR/bazelisk"
59+
60+
# Create bazel symlink
61+
ln -sf "$BIN_DIR/bazelisk" "$BIN_DIR/bazel"
62+
63+
echo "Bazelisk installed to $BIN_DIR/bazelisk"
64+
else
65+
echo ""
66+
echo "Step 2: Bazelisk already installed at $BIN_DIR/bazelisk"
67+
fi
68+
69+
# Add to PATH for this session
70+
export PATH="$BIN_DIR:$PATH"
71+
72+
# Step 3: Initialize conda/mamba for this shell session
73+
echo ""
74+
echo "Step 3: Initializing mamba..."
75+
source "$MINIFORGE_DIR/etc/profile.d/conda.sh"
76+
source "$MINIFORGE_DIR/etc/profile.d/mamba.sh"
77+
78+
# Step 4: Create environment from environment.yml if it doesn't exist
79+
echo ""
80+
echo "Step 4: Setting up conda environment '$ENV_NAME'..."
81+
if conda env list | grep -q "^$ENV_NAME "; then
82+
echo "Environment '$ENV_NAME' already exists. Updating it..."
83+
cd "$SCRIPT_DIR"
84+
mamba env update -n "$ENV_NAME" -f environment.yml
85+
else
86+
echo "Creating environment '$ENV_NAME' from environment.yml..."
87+
cd "$SCRIPT_DIR"
88+
mamba env create -f environment.yml
89+
fi
90+
91+
# Step 5: Activate the environment
92+
echo ""
93+
echo "Step 5: Activating environment '$ENV_NAME'..."
94+
conda activate "$ENV_NAME"
95+
96+
# Verify environment
97+
echo ""
98+
echo "Environment verification:"
99+
echo " Python: $(which python) ($(python --version))"
100+
echo " Bazelisk: $(which bazelisk)"
101+
echo " CMake: $(cmake --version | head -n1)"
102+
echo " GCC: $(gcc --version | head -n1)"
103+
104+
# Step 6: Build the wheel
105+
echo ""
106+
echo "Step 6: Building ml-metadata wheel..."
107+
cd "$SCRIPT_DIR"
108+
109+
# Clean previous build artifacts if requested
110+
if [ "$1" = "--clean" ]; then
111+
echo "Cleaning previous build artifacts..."
112+
bazel clean
113+
rm -rf build/ dist/ *.egg-info
114+
fi
115+
116+
# Build the wheel
117+
echo ""
118+
echo "Starting build (this may take several minutes)..."
119+
python setup.py bdist_wheel
120+
121+
# Show results
122+
echo ""
123+
echo "=========================================="
124+
echo "Build completed successfully!"
125+
echo "=========================================="
126+
echo ""
127+
echo "Wheel file(s):"
128+
ls -lh dist/*.whl
129+
echo ""
130+
echo "To install the wheel:"
131+
echo " pip install dist/ml_metadata-*.whl"
132+
echo ""
133+
echo "To rebuild in the future:"
134+
echo " 1. export PATH=\$HOME/.local/bin:\$PATH"
135+
echo " 2. source $MINIFORGE_DIR/etc/profile.d/conda.sh"
136+
echo " 3. conda activate $ENV_NAME"
137+
echo " 4. python setup.py bdist_wheel"
138+
echo ""
139+

0 commit comments

Comments
 (0)