Skip to content

Commit 540124a

Browse files
authored
Add Arm64 Build (#36)
1 parent 043622c commit 540124a

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ on: push
44
jobs:
55
weasyprint-build:
66
name: Build WeasyPrint
7-
runs-on: ubuntu-latest
87
strategy:
98
matrix:
109
version: ["3.12", "3.13"]
10+
arch: ["x86_64", "arm64"]
11+
runs-on: ${{ matrix.arch == 'x86_64' && 'ubuntu-24.04' || 'ubuntu-24.04-arm' }}
1112
env:
1213
RUNTIME: ${{ matrix.version }}
14+
ARCH: ${{ matrix.arch }}
1315
steps:
1416
- uses: actions/checkout@v4
1517
- name: Build Layer
16-
run: make build/weasyprint-layer-python${{ matrix.version }}.zip
18+
run: make build/weasyprint-layer-python${{ matrix.version }}-${{ matrix.arch }}.zip
1719
- name: Test weasyprint
1820
run: |
1921
mkdir output
@@ -22,11 +24,11 @@ jobs:
2224
make test.print.report
2325
rm -rf build/opt
2426
env:
25-
TEST_FILENAME: build/test-report-${{ matrix.version }}.pdf
27+
TEST_FILENAME: build/test-report-${{ matrix.version }}-${{ matrix.arch }}.pdf
2628
- name: Upload Build
2729
uses: actions/upload-artifact@v4
2830
with:
29-
name: WeasyPrint Layer Build ${{ matrix.version }}
31+
name: WeasyPrint Layer Build ${{ matrix.version }} ${{ matrix.arch }}
3032
path: build
3133
weasyprint-release:
3234
name: Release WeasyPrint

Makefile

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
PLATFORM ?= linux/amd64
21
RUNTIME ?= 3.12
2+
ARCH ?= x86_64
33
TEST_FILENAME ?= report.pdf
44
DOCKER_RUN=docker run --rm --platform=${PLATFORM} -e RUNTIME_VERSION=${RUNTIME}
55

6+
ifeq ($(ARCH), arm64)
7+
PLATFORM=linux/arm64
8+
else
9+
PLATFORM=linux/amd64
10+
endif
11+
612
.PHONY: stack.deploy.weasyprint clean test.start.container test.print.report
713

8-
all: build/weasyprint-layer-python$(RUNTIME).zip
14+
all: build/weasyprint-layer-python$(RUNTIME)-$(ARCH).zip
915

10-
build/weasyprint-layer-python$(RUNTIME).zip: weasyprint/layer_builder.sh \
16+
build/weasyprint-layer-python$(RUNTIME)-$(ARCH).zip: weasyprint/layer_builder.sh \
1117
build/fonts-layer.zip \
1218
| _build
1319
${DOCKER_RUN} \
1420
-v `pwd`/weasyprint:/out \
1521
--entrypoint "/out/layer_builder.sh" \
1622
-t public.ecr.aws/lambda/python:${RUNTIME}
17-
mv -f ./weasyprint/layer.zip ./build/weasyprint-layer-python${RUNTIME}-no-fonts.zip
23+
mv -f ./weasyprint/layer.zip ./build/weasyprint-layer-python${RUNTIME}-${ARCH}-no-fonts.zip
1824
cd build && rm -rf ./opt && mkdir opt \
1925
&& unzip fonts-layer.zip -d opt \
20-
&& unzip weasyprint-layer-python${RUNTIME}-no-fonts.zip -d opt \
21-
&& cd opt && zip -r9 ../weasyprint-layer-python${RUNTIME}.zip .
26+
&& unzip weasyprint-layer-python${RUNTIME}-${ARCH}-no-fonts.zip -d opt \
27+
&& cd opt && zip -r9 ../weasyprint-layer-python${RUNTIME}-${ARCH}.zip .
2228

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

45-
test.start.container: build/weasyprint-layer-python$(RUNTIME).zip
51+
test.start.container: build/weasyprint-layer-python$(RUNTIME)-$(ARCH).zip
4652
${DOCKER_RUN} \
47-
-e GDK_PIXBUF_MODULE_FILE="/opt/lib/loaders.cache" \
4853
-e FONTCONFIG_PATH="/opt/fonts" \
49-
-e XDG_DATA_DIRS="/opt/lib" \
54+
-e LD_LIBRARY_PATH="/opt/lib" \
5055
-v `pwd`/weasyprint:/var/task \
5156
-v `pwd`/build/opt:/opt \
5257
-p 9000:8080 \

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This is a collection of AWS Lambda layers and functions to render pdf documents and images from HTML.
44

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

88
## Fonts
99

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

2525
Build the layer with:
2626

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

2929
To test your build:
3030

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

4747
Lambda must be configured with these env vars:
4848

49-
GDK_PIXBUF_MODULE_FILE="/opt/lib/loaders.cache"
49+
LD_LIBRARY_PATH="/opt/lib"
5050
FONTCONFIG_PATH="/opt/fonts"
51-
XDG_DATA_DIRS="/opt/lib"
5251

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

5554
To build a layer for python3.13 runime use:
5655

57-
RUNTIME=3.13 make build/weasyprint-layer-python3.13.zip
56+
RUNTIME=3.13 make build/weasyprint-layer-python3.13-x86_64.zip
5857

5958
### Docker Lambda
6059

weasyprint/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
PLATFORM ?= linux/amd64
2-
ifeq ($(PLATFORM), linux/arm64)
1+
ARCH ?= x86_64
2+
ifeq ($(ARCH), arm64)
33
RIE_BIN=aws-lambda-rie-arm64
4+
PLATFORM=linux/arm64
45
else
56
RIE_BIN=aws-lambda-rie
7+
PLATFORM=linux/amd64
68
endif
79

810
${RIE_BIN}/aws-lambda-rie:

0 commit comments

Comments
 (0)