Skip to content

Commit

Permalink
Add Arm64 Build (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJuki authored Feb 6, 2025
1 parent 043622c commit 540124a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ on: push
jobs:
weasyprint-build:
name: Build WeasyPrint
runs-on: ubuntu-latest
strategy:
matrix:
version: ["3.12", "3.13"]
arch: ["x86_64", "arm64"]
runs-on: ${{ matrix.arch == 'x86_64' && 'ubuntu-24.04' || 'ubuntu-24.04-arm' }}
env:
RUNTIME: ${{ matrix.version }}
ARCH: ${{ matrix.arch }}
steps:
- uses: actions/checkout@v4
- name: Build Layer
run: make build/weasyprint-layer-python${{ matrix.version }}.zip
run: make build/weasyprint-layer-python${{ matrix.version }}-${{ matrix.arch }}.zip
- name: Test weasyprint
run: |
mkdir output
Expand All @@ -22,11 +24,11 @@ jobs:
make test.print.report
rm -rf build/opt
env:
TEST_FILENAME: build/test-report-${{ matrix.version }}.pdf
TEST_FILENAME: build/test-report-${{ matrix.version }}-${{ matrix.arch }}.pdf
- name: Upload Build
uses: actions/upload-artifact@v4
with:
name: WeasyPrint Layer Build ${{ matrix.version }}
name: WeasyPrint Layer Build ${{ matrix.version }} ${{ matrix.arch }}
path: build
weasyprint-release:
name: Release WeasyPrint
Expand Down
23 changes: 14 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
PLATFORM ?= linux/amd64
RUNTIME ?= 3.12
ARCH ?= x86_64
TEST_FILENAME ?= report.pdf
DOCKER_RUN=docker run --rm --platform=${PLATFORM} -e RUNTIME_VERSION=${RUNTIME}

ifeq ($(ARCH), arm64)
PLATFORM=linux/arm64
else
PLATFORM=linux/amd64
endif

.PHONY: stack.deploy.weasyprint clean test.start.container test.print.report

all: build/weasyprint-layer-python$(RUNTIME).zip
all: build/weasyprint-layer-python$(RUNTIME)-$(ARCH).zip

build/weasyprint-layer-python$(RUNTIME).zip: weasyprint/layer_builder.sh \
build/weasyprint-layer-python$(RUNTIME)-$(ARCH).zip: weasyprint/layer_builder.sh \
build/fonts-layer.zip \
| _build
${DOCKER_RUN} \
-v `pwd`/weasyprint:/out \
--entrypoint "/out/layer_builder.sh" \
-t public.ecr.aws/lambda/python:${RUNTIME}
mv -f ./weasyprint/layer.zip ./build/weasyprint-layer-python${RUNTIME}-no-fonts.zip
mv -f ./weasyprint/layer.zip ./build/weasyprint-layer-python${RUNTIME}-${ARCH}-no-fonts.zip
cd build && rm -rf ./opt && mkdir opt \
&& unzip fonts-layer.zip -d opt \
&& unzip weasyprint-layer-python${RUNTIME}-no-fonts.zip -d opt \
&& cd opt && zip -r9 ../weasyprint-layer-python${RUNTIME}.zip .
&& unzip weasyprint-layer-python${RUNTIME}-${ARCH}-no-fonts.zip -d opt \
&& cd opt && zip -r9 ../weasyprint-layer-python${RUNTIME}-${ARCH}.zip .

build/fonts-layer.zip: fonts/layer_builder.sh | _build
${DOCKER_RUN} \
Expand All @@ -42,11 +48,10 @@ stack.deploy:
cd cdk-stacks && npm install && npm run build
cdk deploy --app ./cdk-stacks/bin/app.js --stack PrintStack --parameters uploadBucketName=${BUCKET}

test.start.container: build/weasyprint-layer-python$(RUNTIME).zip
test.start.container: build/weasyprint-layer-python$(RUNTIME)-$(ARCH).zip
${DOCKER_RUN} \
-e GDK_PIXBUF_MODULE_FILE="/opt/lib/loaders.cache" \
-e FONTCONFIG_PATH="/opt/fonts" \
-e XDG_DATA_DIRS="/opt/lib" \
-e LD_LIBRARY_PATH="/opt/lib" \
-v `pwd`/weasyprint:/var/task \
-v `pwd`/build/opt:/opt \
-p 9000:8080 \
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This is a collection of AWS Lambda layers and functions to render pdf documents and images from HTML.

Download layers from release section or build them yourself (requires: make, docker, zip, unzip, jq).
The layers support only Amazon Linux 2023 runtimes, eg. python3.12.
The layers support only Amazon Linux 2023 runtimes, eg. python3.12 and python3.13.

## Fonts

Expand All @@ -24,7 +24,7 @@ Run `make build/ghostscript-layer.zip` to build the layer.

Build the layer with:

$ make build/weasyprint-layer-python3.12.zip
$ make build/weasyprint-layer-python3.12-x86_64.zip

To test your build:

Expand All @@ -42,19 +42,18 @@ Deploy layer:
$ aws lambda publish-layer-version \
--region <region> \
--layer-name <name> \
--zip-file fileb://build/weasyprint-layer-python3.12.zip
--zip-file fileb://build/weasyprint-layer-python3.12-x86_64.zip

Lambda must be configured with these env vars:

GDK_PIXBUF_MODULE_FILE="/opt/lib/loaders.cache"
LD_LIBRARY_PATH="/opt/lib"
FONTCONFIG_PATH="/opt/fonts"
XDG_DATA_DIRS="/opt/lib"

If you are using the release zip files ensure your Lambda instruction set architecture is set to `x86_64` and not `arm64`.
arm64 is also supported! Use the arm64 zip under Releases or build using "ARCH=arm64 make build/weasyprint-layer-python3.12-arm64.zip"

To build a layer for python3.13 runime use:

RUNTIME=3.13 make build/weasyprint-layer-python3.13.zip
RUNTIME=3.13 make build/weasyprint-layer-python3.13-x86_64.zip

### Docker Lambda

Expand Down
6 changes: 4 additions & 2 deletions weasyprint/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
PLATFORM ?= linux/amd64
ifeq ($(PLATFORM), linux/arm64)
ARCH ?= x86_64
ifeq ($(ARCH), arm64)
RIE_BIN=aws-lambda-rie-arm64
PLATFORM=linux/arm64
else
RIE_BIN=aws-lambda-rie
PLATFORM=linux/amd64
endif

${RIE_BIN}/aws-lambda-rie:
Expand Down

0 comments on commit 540124a

Please sign in to comment.