Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update CI to use GitHub actions and build for osx, windows, linux #51

Merged
merged 10 commits into from Jan 13, 2021
150 changes: 150 additions & 0 deletions .github/workflows/python-publish.yml
@@ -0,0 +1,150 @@

name: Build binary weheels and upload to PyPI

on:
release:
types: [created]

# on:
# pull_request:
# branches:
# - master

jobs:
build-source-distribution:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
- name: Build
run: python setup.py sdist
- uses: actions/upload-artifact@v2
with:
name: python-package-distributions
path: dist
build-linux:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
- name: Build
run: |
./scripts/manylinux/build.sh
- name: Test Import
run: |
pip install cffi pycparser
pip install --no-index --find-links=wheels google-crc32c
python ./scripts/check_cffi_crc32c.py
- uses: actions/upload-artifact@v2
with:
name: python-package-distributions
path: ./wheels/google_crc32c*.whl

build-macos:
runs-on: macos-latest
strategy:
matrix:
python: [3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
- name: Build
run: |
./scripts/osx/build_gh_action.sh
- name: Test Import
run: |
pip install cffi pycparser
pip install --no-index --find-links=wheels google-crc32c
python ./scripts/check_cffi_crc32c.py
- uses: actions/upload-artifact@v2
with:
name: python-package-distributions
path: ./wheels/google_crc32c*.whl

build-windows:
runs-on: windows-latest
strategy:
matrix:
python: [3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
with:
# Use 16.x
vs-version: '[16.0, 17.0)'
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
- name: Build
run: |
where python
./scripts/windows/build.bat ${{ matrix.python }}
- name: Test Import
run: |
./scripts/windows/test.bat ${{ matrix.python }}
- uses: actions/upload-artifact@v2
with:
name: python-package-distributions
path: ./wheels/google_crc32c*.whl


publish:
needs:
- build-linux
- build-macos
- build-windows
- build-source-distribution
runs-on: ubuntu-latest
steps:
- name: Download all the dists
uses: actions/download-artifact@v2
with:
name: python-package-distributions
path: dist/
- name: Download all the wheels
uses: actions/download-artifact@v2
with:
name: python-package-distributions
path: wheels/
- name: What will we publish?
run: ls wheels
- name: Publish Source Distribution
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: dist
skip_existing: true
# repository_url: https://test.pypi.org/legacy/
- name: Publish Wheels
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: wheels
skip_existing: true
# repository_url: https://test.pypi.org/legacy/
42 changes: 42 additions & 0 deletions scripts/osx/build_gh_action.sh
@@ -0,0 +1,42 @@
#!/bin/bash
# Copyright 2018 Google LLC
#
# 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
#
# https://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.

set -e -x
echo "BUILDING FOR OSX"

# ``readlink -f`` is not our friend on OS X. This relies on **some**
# ``python`` being installed.
SCRIPT_FI=$(python -c "import os; print(os.path.realpath('${0}'))")
OSX_DIR=$(dirname ${SCRIPT_FI})
SCRIPTS_DIR=$(dirname ${OSX_DIR})
export REPO_ROOT=$(dirname ${SCRIPTS_DIR})

# Build and install `libcrc32c`
export PY_BIN="python3"
export CRC32C_INSTALL_PREFIX="${REPO_ROOT}/usr"

cd ${REPO_ROOT}
git submodule update --init --recursive

${OSX_DIR}/build_c_lib.sh

# Build wheel
export PY_BIN="python3"
export PY_TAG="*"
${OSX_DIR}/build_python_wheel.sh


# Clean up.
rm -fr ${CRC32C_INSTALL_PREFIX}
99 changes: 43 additions & 56 deletions scripts/windows/build.bat
Expand Up @@ -13,73 +13,60 @@
@rem limitations under the License.


@REM available windows versions on CI as of 2019-Nov-25
@REM -3.7-64
@REM -3.7-32
@REM -3.6-64
@REM -3.6-32
@REM -3.5-64
@REM -3.5-32
@REM -3.4-64
@REM -3.4-32
@REM -2.7-64
@REM -2.7-32

py -3.7 -m pip install cmake

@rem First, build libcrc32c
set CRC32C_INSTALL_PREFIX=%KOKORO_ARTIFACTS_DIR%\bin_win64\

echo %CRC32C_INSTALL_PREFIX%

pushd google_crc32c
git submodule update --init --recursive
mkdir build

@REM 64 Bit Builds.
@REM removed -DCRC32C_BUILD_TESTS=no
set CMAKE_GENERATOR="Visual Studio 15 2017"
C:\Python37\Scripts\cmake -G %CMAKE_GENERATOR% -A x64 -DCRC32C_BUILD_BENCHMARKS=no -DBUILD_SHARED_LIBS=yes ^
-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=yes -DCMAKE_INSTALL_PREFIX:PATH=%CRC32C_INSTALL_PREFIX% .
setlocal ENABLEDELAYEDEXPANSION

C:\Python37\Scripts\cmake --build . --config RelWithDebInfo --target install
dir %CRC32C_INSTALL_PREFIX% /b /s
popd
set CMAKE_GENERATOR="Visual Studio 16 2019"
set CONFIGURATION=RelWithDebInfo
set CRC32C_INSTALL_PREFIX=%cd%\build\%CONFIGURATION%

copy %CRC32C_INSTALL_PREFIX%bin\google_crc32c.dll .
@rem Path to cmake, env var to make it easier to point to a specific version
set cmake=cmake

@rem update python deps and build wheels (requires CRC32C_INSTALL_PREFIX is set)
FOR %%V IN (3.6-64,3.7-64) DO (
py -%%V -m pip install --upgrade pip setuptools wheel
py -%%V -m pip wheel . --wheel-dir wheels/
@rem python version should be set as an argument, if not, default to python 3.9
set PYTHON_VERSION=%1
if "%PYTHON_VERSION%"=="" (
echo "Python version was not provided, using Python 3.9"
set PYTHON_VERSION=3.9
)

py -0
py -%PYTHON_VERSION% -m pip install cmake

@REM 32 Bit Builds.
@REM removed -DCRC32C_BUILD_TESTS=no
git submodule update --init --recursive

set CMAKE_GENERATOR="Visual Studio 15 2017"
pushd google_crc32c
@rem reset hard to cleanup any changes done by 64-bit build.
git reset --hard
FOR %%V IN (32,64) DO (
set TARGET_PLATFORM="x64"

del /s /q CMakeFiles\
del CMakeCache.txt
set CRC32C_INSTALL_PREFIX=%KOKORO_ARTIFACTS_DIR%\bin_win32\
if "%%V"=="32" (
set TARGET_PLATFORM="Win32"
)
echo "Target Platform: !TARGET_PLATFORM!"

C:\Python37\Scripts\cmake -G %CMAKE_GENERATOR% -A Win32 -DCRC32C_BUILD_BENCHMARKS=no -DBUILD_SHARED_LIBS=yes ^
-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=yes -DCMAKE_INSTALL_PREFIX:PATH=%CRC32C_INSTALL_PREFIX% .
pushd google_crc32c

C:\Python37\Scripts\cmake --build . --config RelWithDebInfo --target install
dir %CRC32C_INSTALL_PREFIX% /b /s
popd
@rem reset hard to cleanup any changes done by a previous build.
git reset --hard
git clean -fxd

copy %CRC32C_INSTALL_PREFIX%bin\google_crc32c.dll .
del /s /q CMakeFiles\
del CMakeCache.txt

@rem update python deps and build wheels (requires CRC32C_INSTALL_PREFIX is set)
FOR %%V IN (3.6-32,3.7-32) DO (
py -%%V -m pip install --upgrade pip setuptools wheel
py -%%V -m pip wheel . --wheel-dir wheels/
)
mkdir build
cd build

echo "Running cmake with Generator: %CMAKE_GENERATOR%, Platform: !TARGET_PLATFORM!, Install Prefix: %CRC32C_INSTALL_PREFIX%"

%cmake% -G %CMAKE_GENERATOR% -A !TARGET_PLATFORM! -DCRC32C_BUILD_BENCHMARKS=no -DCRC32C_BUILD_TESTS=no -DBUILD_SHARED_LIBS=yes -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=yes -DCRC32C_USE_GLOG=0 -DCMAKE_INSTALL_PREFIX:PATH=%CRC32C_INSTALL_PREFIX% ..

%cmake% --build . --config "%CONFIGURATION%" --target install

dir %CRC32C_INSTALL_PREFIX% /b /s
popd

dir %CRC32C_INSTALL_PREFIX%\bin
echo "Copying Binary to root: %CRC32C_INSTALL_PREFIX%\bin\crc32c.dll"
copy %CRC32C_INSTALL_PREFIX%\bin\crc32c.dll .

py -%PYTHON_VERSION%-%%V -m pip install --upgrade pip setuptools wheel
py -%PYTHON_VERSION%-%%V -m pip wheel . --wheel-dir wheels/
)
14 changes: 10 additions & 4 deletions scripts/windows/test.bat
Expand Up @@ -12,13 +12,19 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.

@rem python version should be set as an argument, if not, default to python 3.9
set PYTHON_VERSION=%1
if "%PYTHON_VERSION%"=="" (
echo "Python version was not provided, using Python 3.9"
set PYTHON_VERSION=3.9
)

@rem update python deps and build wheels (requires CRC32C_INSTALL_PREFIX is set)
@rem FOR %%V IN (3.5-64,3.5-32,3.6-64,3.6-32,3.7-64,3.7-32) DO (
@rem FOR %%V IN (3.5-64,3.6-64,3.7-64) DO (
FOR %%V IN (3.5-64,3.5-32,3.6-64,3.6-32,3.7-64,3.7-32) DO (

py -%%V -m pip install --no-index --find-links=wheels google-crc32c
@REM FOR %%V IN (3.9-64,3.9-32) DO (
FOR %%V IN (%PYTHON_VERSION%-32, %PYTHON_VERSION%-64) DO (
py -%%V -m pip install cffi pyparser
py -%%V -m pip install --no-index --find-links=wheels google-crc32c --force-reinstall
py -%%V -m pip install pytest
py -%%V -m pytest tests
)
7 changes: 6 additions & 1 deletion src/google_crc32c/__config__.py
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import os
import sys

import pkg_resources

Expand All @@ -27,12 +28,16 @@ def modify_path():
if path is None:
return

# 3.6, 3.7 use path
crwilcox marked this conversation as resolved.
Show resolved Hide resolved
try:
extra_dll_dir = pkg_resources.resource_filename("google_crc32c", "extra-dll")
if os.path.isdir(extra_dll_dir):
# Python 3.6, 3.7 use path
os.environ["PATH"] = path + os.pathsep + extra_dll_dir
# Python 3.8+ uses add_dll_directory.
if sys.version_info[0] == 3 and sys.version_info[1] >= 8:
os.add_dll_directory(extra_dll_dir)
except ImportError:
pass


modify_path()
12 changes: 0 additions & 12 deletions tests/conftest.py
Expand Up @@ -13,19 +13,7 @@
# limitations under the License.

"""py.test shared testing configuration.

This

* Monkey-patches ``mock`` as ``unittest.mock`` for Python 2.7.
"""

import sys
import unittest
crwilcox marked this conversation as resolved.
Show resolved Hide resolved

import six

if six.PY2:
import mock

unittest.mock = mock
sys.modules["unittest.mock"] = unittest.mock