Skip to content

Commit 073d4d9

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 073d4d9

File tree

3 files changed

+173
-0
lines changed

3 files changed

+173
-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

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: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
# Set Bazel version to use
73+
export USE_BAZEL_VERSION=6.5.0
74+
75+
# Step 3: Initialize conda/mamba for this shell session
76+
echo ""
77+
echo "Step 3: Initializing mamba..."
78+
source "$MINIFORGE_DIR/etc/profile.d/conda.sh"
79+
source "$MINIFORGE_DIR/etc/profile.d/mamba.sh"
80+
81+
# Step 4: Create environment from environment.yml if it doesn't exist
82+
echo ""
83+
echo "Step 4: Setting up conda environment '$ENV_NAME'..."
84+
if conda env list | grep -q "^$ENV_NAME "; then
85+
echo "Environment '$ENV_NAME' already exists. Updating it..."
86+
cd "$SCRIPT_DIR"
87+
mamba env update -n "$ENV_NAME" -f environment.yml
88+
else
89+
echo "Creating environment '$ENV_NAME' from environment.yml..."
90+
cd "$SCRIPT_DIR"
91+
mamba env create -f environment.yml
92+
fi
93+
94+
# Step 5: Activate the environment
95+
echo ""
96+
echo "Step 5: Activating environment '$ENV_NAME'..."
97+
conda activate "$ENV_NAME"
98+
99+
# Verify environment
100+
echo ""
101+
echo "Environment verification:"
102+
echo " Python: $(which python) ($(python --version))"
103+
echo " Bazelisk: $(which bazelisk)"
104+
echo " CMake: $(cmake --version | head -n1)"
105+
echo " GCC: $(gcc --version | head -n1)"
106+
107+
# Step 6: Build the wheel
108+
echo ""
109+
echo "Step 6: Building ml-metadata wheel..."
110+
cd "$SCRIPT_DIR"
111+
112+
# Clean previous build artifacts if requested
113+
if [ "$1" = "--clean" ]; then
114+
echo "Cleaning previous build artifacts..."
115+
bazel clean
116+
rm -rf build/ dist/ *.egg-info
117+
fi
118+
119+
# Build the wheel
120+
echo ""
121+
echo "Starting build (this may take several minutes)..."
122+
python setup.py bdist_wheel
123+
124+
# Show results
125+
echo ""
126+
echo "=========================================="
127+
echo "Build completed successfully!"
128+
echo "=========================================="
129+
echo ""
130+
echo "Wheel file(s):"
131+
ls -lh dist/*.whl
132+
echo ""
133+
echo "To install the wheel:"
134+
echo " pip install dist/ml_metadata-*.whl"
135+
echo ""
136+
echo "To rebuild in the future:"
137+
echo " 1. export PATH=\$HOME/.local/bin:\$PATH"
138+
echo " 2. source $MINIFORGE_DIR/etc/profile.d/conda.sh"
139+
echo " 3. conda activate $ENV_NAME"
140+
echo " 4. python setup.py bdist_wheel"
141+
echo ""

0 commit comments

Comments
 (0)