Skip to content

Commit

Permalink
Build PyVelox Wheels for Linux and MacOS (x86_64) (facebookincubator#…
Browse files Browse the repository at this point in the history
…3884)

Summary:
This PR sets up a CI Job to build pyvelox wheels for x86_64 MacOS and Linux for python 3.9 - 3.11. The wheels are uploaded as artifacts. We can easily add a job to publish them to pypi regularly.

Pull Request resolved: facebookincubator#3884

Reviewed By: amitkdutta

Differential Revision: D43377917

Pulled By: kgpai

fbshipit-source-id: d413c40c9f80189ab9ecd4444685a59cc11091f9
  • Loading branch information
assignUser authored and facebook-github-bot committed Feb 21, 2023
1 parent e4a2c99 commit e09c078
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 9 deletions.
178 changes: 178 additions & 0 deletions .github/workflows/build_pyvelox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Build Pyvelox Wheels

on:
workflow_dispatch:
inputs:
version:
description: 'pyvelox version'
required: false
ref:
description: 'git ref to build'
required: false
publish:
description: 'publish to PyPI'
required: false
type: boolean
default: false
# schedule:
# - cron: '15 0 * * *'
pull_request:
paths:
- 'velox/**'
- '!velox/docs/**'
- 'third_party/**'
- 'pyvelox/**'
- '.github/workflows/build_pyvelox.yml'

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.repository }}-${{ github.head_ref || github.sha }}
cancel-in-progress: true

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, macos-11]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref || github.ref }}
fetch-depth: 0
submodules: recursive

- uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: "Determine Version"
if: ${{ !inputs.version && github.event_name != 'pull_request' }}
id: version
run: |
# count number of commits since last tag matching a regex
# and use that to determine the version number
# e.g. if the last tag is 0.0.1, and there have been 5 commits since then
# the version will be 0.0.1a5
git fetch --tags
INITIAL_COMMIT=5d4db2569b7c249644bf36a543ba1bd8f12bf77c
# Can't use PCRE for portability
BASE_VERSION=$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+' version.txt)
LAST_TAG=$(git describe --tags --match "pyvelox-v[0-9]*" --abbrev=0 || echo $INITIAL_COMMIT)
COMMITS_SINCE_TAG=$(git rev-list --count ${LAST_TAG}..HEAD)
if [ "$LAST_TAG" = "$INITIAL_COMMIT" ]; then
VERSION=$BASE_VERSION
else
VERSION=$(echo $LAST_TAG | sed '/pyvelox-v//')
fi
# NEXT_VERSION=$(echo $VERSION | awk -F. -v OFS=. '{$NF++ ; print}')
echo "build_version=${VERSION}a${COMMITS_SINCE_TAG}" >> $GITHUB_OUTPUT
- run: mkdir -p .ccache
- name: "Restore ccache"
uses: actions/cache/restore@v3
id: restore-cache
with:
path: ".ccache"
key: ccache-wheels-${{ matrix.os }}-${{ github.sha }}
restore-keys: |
ccache-wheels-${{ matrix.os }}-
- if: matrix.os == 'macos-11'
run: |
echo "OPENSSL_ROOT_DIR=/usr/local/opt/[email protected]/" >> $GITHUB_ENV
- name: "Create sdist"
if: matrix.os == 'ubuntu-22.04'
env:
BUILD_VERSION: "${{ inputs.version || steps.version.outputs.build_version }}"
run: |
python setup.py sdist --dist-dir wheelhouse
- name: Build wheels
uses: pypa/[email protected]
env:
# required for preadv/pwritev
MACOSX_DEPLOYMENT_TARGET: "11.0"
CIBW_ARCHS: "x86_64"
# On PRs only build for Python 3.7
CIBW_BUILD: ${{ github.event_name == 'pull_request' && 'cp37-*' || 'cp3*' }}
CIBW_SKIP: "*musllinux* cp36-*"
CIBW_MANYLINUX_X86_64_IMAGE: "ghcr.io/facebookincubator/velox-dev:torcharrow-avx"
CIBW_BEFORE_ALL_MACOS: >
bash {package}/scripts/setup-macos.sh &&
bash {package}/scripts/setup-macos.sh install_folly
CIBW_BEFORE_ALL_LINUX: >
mkdir -p /output &&
cp -R /host${{ github.workspace }}/.ccache /output/.ccache &&
ccache -s
CIBW_ENVIRONMENT_PASS_LINUX: CCACHE_DIR BUILD_VERSION
CIBW_TEST_COMMAND: "cd {project}/pyvelox && python -m unittest -v"
CIBW_TEST_SKIP: "*macos*"
CCACHE_DIR: "${{ matrix.os != 'macos-11' && '/output' || github.workspace }}/.ccache"
BUILD_VERSION: "${{ inputs.version || steps.version.outputs.build_version }}"
with:
output-dir: wheelhouse

- name: "Move .ccache to workspace"
if: matrix.os != 'macos-11'
run: |
mkdir -p .ccache
cp -R ./wheelhouse/.ccache/* .ccache
- name: "Save ccache"
uses: actions/cache/save@v3
id: cache
with:
path: ".ccache"
key: ccache-wheels-${{ matrix.os }}-${{ github.sha }}

- uses: actions/upload-artifact@v3
with:
name: wheels
path: |
./wheelhouse/*.whl
./wheelhouse/*.tar.gz
publish_wheels:
name: Publish Wheels to PyPI
if: ${{ github.event_name == 'schedule' || inputs.publish }}
needs: build_wheels
runs-on: ubuntu-22.04
steps:
- uses: actions/download-artifact@v3
with:
name: wheels
path: ./wheelhouse

- run: ls wheelhouse

- uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Publish a Python distribution to PyPI
uses: pypa/[email protected]
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: wheelhouse
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ option(VELOX_ENABLE_S3 "Build S3 Connector" OFF)
option(VELOX_ENABLE_HDFS "Build Hdfs Connector" OFF)
option(VELOX_ENABLE_PARQUET "Enable Parquet support" OFF)
option(VELOX_ENABLE_ARROW "Enable Arrow support" OFF)
option(VELOX_ENABLE_CCACHE "Use ccache if installed." ON)

option(VELOX_BUILD_TEST_UTILS "Builds Velox test utilities" OFF)
option(VELOX_BUILD_PYTHON_PACKAGE "Builds Velox Python bindings" OFF)
Expand Down Expand Up @@ -143,6 +144,21 @@ if(${VELOX_BUILD_PYTHON_PACKAGE})
set(VELOX_ENABLE_BENCHMARKS_BASIC OFF)
endif()

if(VELOX_ENABLE_CCACHE
AND NOT CMAKE_C_COMPILER_LAUNCHER
AND NOT CMAKE_CXX_COMPILER_LAUNCHER)

find_program(CCACHE_FOUND ccache)

if(CCACHE_FOUND)
message(STATUS "Using ccache: ${CCACHE_FOUND}")
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_FOUND})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_FOUND})
# keep comments as they might matter to the compiler
set(ENV{CCACHE_COMMENTS} "1")
endif()
endif()

if(VELOX_ENABLE_S3)
# Set AWS_ROOT_DIR if you have a custom install location of AWS SDK CPP.
if(AWSSDK_ROOT_DIR)
Expand Down Expand Up @@ -318,7 +334,7 @@ find_package(gflags COMPONENTS shared)
find_package(glog REQUIRED)

set_source(fmt)
resolve_dependency(fmt 8.0.1)
resolve_dependency(fmt)

find_library(EVENT event)

Expand Down
8 changes: 8 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
inculde *.txt
include *.cmake
graft CMake
graft third_party
graft velox
graft pyvelox
graft scripts
prune velox/docs
6 changes: 6 additions & 0 deletions scripts/setup-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ function install_fmt {
cmake_install -DFMT_TEST=OFF
}

function install_folly {
github_checkout facebook/folly "v2022.11.14.00"
OPENSSL_ROOT_DIR=$(brew --prefix [email protected]) \
cmake_install -DBUILD_TESTS=OFF
}

function install_double_conversion {
github_checkout google/double-conversion v3.1.5
cmake_install -DBUILD_TESTING=OFF
Expand Down
13 changes: 8 additions & 5 deletions scripts/setup-velox-torcharrow.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set -efx -o pipefail
SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}")
source $SCRIPTDIR/setup-helper-functions.sh
CPU_TARGET="${CPU_TARGET:-avx}"
CONDA=${1:-true}
export CFLAGS=$(get_cxx_flags $CPU_TARGET)
export CXXFLAGS=$CFLAGS # Used by boost.

Expand All @@ -45,11 +46,12 @@ yum -y install bzip2-devel \
wget \
zlib-devel

#Install conda
rpm --import https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc
if [ "$CONDA" = true ]; then
#Install conda
rpm --import https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc

# Add the Anaconda repository
cat <<EOF > /etc/yum.repos.d/conda.repo
# Add the Anaconda repository
cat <<EOF > /etc/yum.repos.d/conda.repo
[conda]
name=Conda
baseurl=https://repo.anaconda.com/pkgs/misc/rpmrepo/conda
Expand All @@ -58,7 +60,8 @@ gpgcheck=1
gpgkey=https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc
EOF

yum -y install conda
yum -y install conda
fi

function cmake_install {
cmake -B "$1-build" -GNinja -DCMAKE_CXX_STANDARD=17 \
Expand Down
9 changes: 7 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

ROOT_DIR = Path(__file__).parent.resolve()

with open("README.md") as f:
readme = f.read()


# Override build directory
class BuildCommand(distutils.command.build.build):
Expand Down Expand Up @@ -158,10 +161,12 @@ def build_extension(self, ext):
name="pyvelox",
version=VERSION,
description="Python bindings and extensions for Velox",
long_description=readme,
long_description_content_type="text/markdown",
url="https://github.com/facebookincubator/velox",
author="Meta",
author_email="[email protected]",
license="BSD",
license="Apache License 2.0",
install_requires=[
"cffi",
"typing",
Expand All @@ -172,7 +177,7 @@ def build_extension(self, ext):
classifiers=[
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"License :: OSI Approved :: Apache Software License",
"Operating System :: POSIX :: Linux",
"Programming Language :: C++",
"Programming Language :: Python :: 3.7",
Expand Down
2 changes: 1 addition & 1 deletion velox/duckdb/memory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

add_library(velox_duckdb_allocator Allocator.cpp)

target_link_libraries(velox_duckdb_allocator velox_dwio_common duckdb ${FMT})
target_link_libraries(velox_duckdb_allocator velox_dwio_common duckdb fmt::fmt)

if(NOT VELOX_DISABLE_GOOGLETEST)
target_link_libraries(velox_duckdb_allocator gtest)
Expand Down

0 comments on commit e09c078

Please sign in to comment.