Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions recipes/grain/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

set -xe
export PYTHON_VERSION=$(${PYTHON} -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
export PYTHON_MAJOR_VERSION=$(echo $PYTHON_VERSION | cut -d. -f1)
export PYTHON_MINOR_VERSION=$(echo $PYTHON_VERSION | cut -d. -f2)
export BAZEL_VERSION="7.2.1"
export OUTPUT_DIR="$(pwd)"
export SOURCE_DIR="."
export RUN_TESTS="true"
. "./grain/oss/runner_common.sh"

# Workaround for a timestamp issue: https://github.com/prefix-dev/rattler-build/issues/1865
touch -m -t 203510100101 $(find $BUILD_PREFIX/share/bazel/install -type f)

setup_env_vars_py "$PYTHON_MAJOR_VERSION" "$PYTHON_MINOR_VERSION"

function write_to_bazelrc() {
echo "$1" >> .bazelrc
}

write_to_bazelrc "build --incompatible_default_to_explicit_init_py"
write_to_bazelrc "build --enable_platform_specific_config"
write_to_bazelrc "build:macos --linkopt=-Wl,-undefined,dynamic_lookup"
write_to_bazelrc "build:macos --host_linkopt=-Wl,-undefined,dynamic_lookup"
write_to_bazelrc "build --@rules_python//python/config_settings:python_version=${PYTHON_VERSION}"
write_to_bazelrc "build --cxxopt=-Wno-deprecated-declarations --host_cxxopt=-Wno-deprecated-declarations"
write_to_bazelrc "build --cxxopt=-Wno-parentheses --host_cxxopt=-Wno-parentheses"
write_to_bazelrc "build --cxxopt=-Wno-sign-compare --host_cxxopt=-Wno-sign-compare"
write_to_bazelrc "build --python_path=\"${PYTHON_BIN}\""
write_to_bazelrc "test --@rules_python//python/config_settings:python_version=${PYTHON_VERSION}"
write_to_bazelrc "test --action_env PYTHON_VERSION=${PYTHON_VERSION}"
write_to_bazelrc "test --test_timeout=300"
write_to_bazelrc "common --check_direct_dependencies=error"

bazel clean
bazel build ... --action_env PYTHON_BIN_PATH="${PYTHON_BIN}" --action_env MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}

DEST="${OUTPUT_DIR}"'/all_dist'
mkdir -p "${DEST}"

TMPDIR="$(mktemp -d -t tmp.XXXXXXXXXX)"
cp README.md "${TMPDIR}"
cp setup.py "${TMPDIR}"
cp pyproject.toml "${TMPDIR}"
cp LICENSE "${TMPDIR}"
rsync -avm -L --exclude="__pycache__/*" grain "${TMPDIR}"
rsync -avm -L --include="*.so" --include="*_pb2.py" \
--exclude="*.runfiles" --exclude="*_obj" --include="*/" --exclude="*" \
bazel-bin/grain "${TMPDIR}"

previous_wd="$(pwd)"
cd "${TMPDIR}"
printf '%s : "=== Building wheel\n' "$(date)"
WHEEL_BLD_ARGS="${WHEEL_BLD_ARGS} bdist_wheel --python-tag py3${PYTHON_MINOR_VERSION}"
if [ "$(uname)" == "Darwin" ]; then
WHEEL_BLD_ARGS="${WHEEL_BLD_ARGS} --plat-name macosx_$(echo $MACOSX_DEPLOYMENT_TARGET | tr . _)_$(uname -m)"
fi
$PYTHON setup.py $WHEEL_BLD_ARGS

cp 'dist/'*.whl "${DEST}"

printf '%s : "=== Listing wheel\n' "$(date)"
ls -lrt "${DEST}"/*.whl
cd "${previous_wd}"

printf '%s : "=== Output wheel file is in: %s\n' "$(date)" "${DEST}"

$PYTHON -m pip install ./all_dist/grain*.whl
78 changes: 78 additions & 0 deletions recipes/grain/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{% set name = "Grain" %}
{% set version = "0.2.12" %}
{% set sha256 = "e70a30af2a383ecff4d91dc42322e56f7e566fae949650dfb6eeb52648719b36" %}
# Bazel version is specified upstream, file .bazelversion
{% set bazel_version = "7.2.1" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
url: https://github.com/google/grain/archive/v{{ version }}.tar.gz
sha256: {{ sha256 }}

build:
number: 0
skip: true # [py<310]
skip: true # [win]
skip: true # [osx]

requirements:
build:
- python # [target_platform != build_platform]
- pip # [target_platform != build_platform]
- numpy # [target_platform != build_platform]
- setuptools # [target_platform != build_platform]
- wheel # [target_platform != build_platform]
- bazel 7.2.1
- rsync
- {{ compiler('c') }}
- {{ stdlib('c') }}
- {{ compiler('cxx') }}
host:
- python
- pip
- numpy
- setuptools
- wheel
run:
- python
- etils
- absl-py
- cloudpickle
- dm-tree
- more-itertools >=9.1.0
- numpy
# Upper bound version required by python-specific guarantees for protobuf
# https://protobuf.dev/support/cross-version-runtime-guarantee/#python
- protobuf >=5.28.3,<8.0dev0
- array-record >=0.8.1
- typing_extensions
- importlib_resources
- zipp
- fsspec
- jax >=0.6.0
- jaxlib >=0.6.0

test:
imports:
- grain
- grain.proto.execution_summary_pb2

about:
home: https://pypi.org/project/grain/
summary: Library for reading and processing ML training data.
description: |
Grain is a library for reading data for training and evaluating JAX models.
It's open source, fast and deterministic.
license: Apache-2.0
license_family: Apache
license_file: LICENSE
doc_url: https://google-grain.readthedocs.io/
dev_url: https://github.com/google/grain/

extra:
recipe-maintainers:
- iindyk
- mtsokol