Skip to content

Commit

Permalink
Merge pull request #4 from joehoyle/linux-arm
Browse files Browse the repository at this point in the history
Build for Linux Arm + PHP versions
  • Loading branch information
joehoyle authored May 17, 2022
2 parents b4f2f8c + 036ee38 commit c4cb389
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 20 deletions.
108 changes: 88 additions & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,93 @@ name: Build
on: [push]

jobs:
build:
runs-on: ${{matrix.os}}
linux:
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
strategy:
matrix:
include:
- build: linux
-
target: x86_64-unknown-linux-gnu
platform: linux/amd64
php-version: '8.0'
-
os: ubuntu-latest
rust: stable
target: aarch64-unknown-linux-gnu
platform: linux/arm64
php-version: '8.0'
-
target: x86_64-unknown-linux-gnu
file: libv8js.so
# - build: linux-aarch64
# os: ubuntu-latest
# rust: stable
# target: aarch64-unknown-linux-gnu
# cross: true
- build: macos-aarch64
os: macos-latest
rust: stable
platform: linux/amd64
php-version: '8.1'
-
os: ubuntu-latest
target: aarch64-unknown-linux-gnu
platform: linux/arm64
php-version: '8.1'
steps:
- name: Checkout
uses: actions/checkout@v1

- name: Setup QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host

- name: Setup docker
uses: docker/build-push-action@v2
with:
context: .
platforms: ${{ matrix.platform }}
push: true
tags: localhost:5000/phpv8js-build:latest
build-args: |
FROM_PHP=${{ matrix.php-version }}
- name: Build
run: docker run --rm -v $PWD:/code localhost:5000/phpv8js-build:latest bash -c 'rustup target add ${{ matrix.target }} ; cargo build --release --target ${{ matrix.target }}'

- name: Rename file
run: cp target/${{ matrix.target }}/release/libv8js.so php${{ matrix.php-version }}-${{ matrix.target }}-libv8js.so

- uses: actions/upload-artifact@v3
with:
name: php${{ matrix.php-version }}-${{ matrix.target }}
path: php${{ matrix.php-version }}-${{ matrix.target }}-libv8js.so
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
php${{ matrix.php-version }}-${{ matrix.target }}-libv8js.so
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

macos:
runs-on: macos-latest
strategy:
matrix:
include:
-
target: aarch64-apple-darwin
file: libv8js.dylib
- build: macos
os: macos-latest
rust: stable
php-version: '8.0'
-
target: x86_64-apple-darwin
file: libv8js.dylib
php-version: '8.0'
-
target: aarch64-apple-darwin
php-version: '8.1'
-
target: x86_64-apple-darwin
php-version: '8.1'
steps:
- name: Checkout
uses: actions/checkout@v1
Expand All @@ -39,6 +101,8 @@ jobs:
target: ${{ matrix.target }}
default: true
override: true
- name: Setup PHP version
run: brew install php@${{ matrix.php-version }} && brew unlink php && brew link --force php@${{ matrix.php-version }}
- name: Build
uses: actions-rs/cargo@v1
with:
Expand All @@ -47,13 +111,17 @@ jobs:
args: --release --target ${{ matrix.target }} --lib

- name: Rename file
run: mv target/${{ matrix.target }}/release/${{ matrix.file }} target/${{ matrix.target }}-${{ matrix.file }}
run: mv target/${{ matrix.target }}/release/libv8js.dylib target/php${{ matrix.php-version }}-${{ matrix.target }}-libv8js.dylib

- uses: actions/upload-artifact@v3
with:
name: php${{ matrix.php-version }}-${{ matrix.target }}
path: target/php${{ matrix.php-version }}-${{ matrix.target }}-libv8js.dylib
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
target/${{ matrix.target }}-${{ matrix.file }}
target/php${{ matrix.php-version }}-${{ matrix.target }}-libv8js.dylib
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Define versions used to select image versions
# (ARGs declared before FROM can't be used outside of FROMs)
ARG FROM_PHP=8.0

# Select distro
ARG FROM_DISTRO=bullseye

FROM php:${FROM_PHP}-fpm-${FROM_DISTRO}

RUN apt-get update && apt install curl build-essential gcc libclang-dev make -y

RUN curl https://sh.rustup.rs -sSf | bash -s -- -y

RUN echo 'source $HOME/.cargo/env' >> $HOME/.bashrc
ENV PATH="/root/.cargo/bin:${PATH}"

WORKDIR /code
ENTRYPOINT [ "" ]

0 comments on commit c4cb389

Please sign in to comment.