Skip to content

Commit

Permalink
Add CGO tests (#13)
Browse files Browse the repository at this point in the history
* Add CGO tests

* Try to install libjpegturbo

* Conditionally install libjpeg turbo

* Always build with libjpeg turbo

* Drop sudo for drew

* Add libturbojpeg-dev for linux

* Disable CGO for webassembly builds

* Improve workflows

* Fix library install

* Install pkgconfig

* Try to find jpeg turbo

* Copy header file

* Compile libjpegturbo

* Change cd in workflow

* Fix?

* Fix paths

* Fix turbo include path

* Add start of windows support

* Fix windows pdfium download

* Try to fix exe

* Fix windows build

* Try to add include libjpegturbo header

* Try to add include libjpegturbo header

* Test

* Try to install libjpeg turbo

* Try to install libjpeg turbo

* Add bin path to cgoflags

* Try to fix windows

* Split op linux cgo and linux musl cgo

* Fix linux build

* Update readme

* Rename workflows, add native workflows

* Update readme

* Add sleep for libjpeg turbo silent install

* Update tests

* Try to fix pkgconfig for windows

* Add jpegturbo pkg config for musl

* Fix libjpegturbo build

* Temporarily build artifacts for normal builds

* Add more builds

* Remove builds
  • Loading branch information
jerbob92 authored Sep 30, 2023
1 parent 0a66ab4 commit 1f70fec
Show file tree
Hide file tree
Showing 7 changed files with 405 additions and 42 deletions.
33 changes: 0 additions & 33 deletions .github/workflows/go.yml

This file was deleted.

9 changes: 9 additions & 0 deletions .github/workflows/libturbojpeg.pc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
prefix=/opt/libjpegturbo/libjpeg-turbo-3.0.0
libdir=/opt/libjpegturbo/libjpeg-turbo-3.0.0/build
includedir=/opt/libjpegturbo/libjpeg-turbo-3.0.0

Name: libturbojpeg
Description: A SIMD-accelerated JPEG codec that provides the TurboJPEG API
Version: 3.0.0
Libs: -L${libdir} -lturbojpeg
Cflags: -I${includedir}
11 changes: 11 additions & 0 deletions .github/workflows/pdfium-windows.pc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=D:/opt/pdfium
libdir=D:/opt/pdfium/bin
includedir=D:/opt/pdfium/include

Name: PDFium
Description: PDFium
Version: 6029
Requires:

Libs: -L${libdir} -lpdfium
Cflags: -I${includedir}
11 changes: 11 additions & 0 deletions .github/workflows/pdfium.pc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=/opt/pdfium
libdir=/opt/pdfium/lib
includedir=/opt/pdfium/include

Name: PDFium
Description: PDFium
Version: 6029
Requires:

Libs: -L${libdir} -lpdfium
Cflags: -I${includedir}
178 changes: 170 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,199 @@ on:
release:
types: [created]

env:
GO_VERSION: "1.21"
PDFIUM_VERSION: "6029"

jobs:
build:
release-webassembly:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, macos-latest, windows-latest ]
go: [ "1.21" ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
env:
CGO_ENABLED: 0
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
go-version: ${{ env.GO_VERSION }}
- name: Build Linux
if: matrix.os == 'ubuntu-20.04'
if: matrix.os == 'ubuntu-latest'
run: |
go build -ldflags "-X 'github.com/klippa-app/pdfium-cli/version.VERSION=${{ github.event.release.name }}'" -o artifacts/pdfium-linux-x64 main.go
GOARCH=amd64 go build -ldflags "-X 'github.com/klippa-app/pdfium-cli/version.VERSION=${{ github.event.release.name }}'" -o artifacts/pdfium-webassembly-linux-amd64 main.go
GOARCH=arm64 go build -ldflags "-X 'github.com/klippa-app/pdfium-cli/version.VERSION=${{ github.event.release.name }}'" -o artifacts/pdfium-webassembly-linux-arm64 main.go
- name: Build MacOS
if: matrix.os == 'macos-latest'
run: |
go build -ldflags "-X 'github.com/klippa-app/pdfium-cli/version.VERSION=${{ github.event.release.name }}'" -o artifacts/pdfium-mac-x64 main.go
GOARCH=amd64 go build -ldflags "-X 'github.com/klippa-app/pdfium-cli/version.VERSION=${{ github.event.release.name }}'" -o artifacts/pdfium-webassembly-mac-amd64 main.go
GOARCH=arm64 go build -ldflags "-X 'github.com/klippa-app/pdfium-cli/version.VERSION=${{ github.event.release.name }}'" -o artifacts/pdfium-webassembly-mac-arm64 main.go
- name: Build Windows
if: matrix.os == 'windows-latest'
run: |
go build -ldflags "-X 'github.com/klippa-app/pdfium-cli/version.VERSION=${{ github.event.release.name }}'" -o artifacts/pdfium-windows-x64 main.go
GOARCH=amd64 go build -ldflags "-X 'github.com/klippa-app/pdfium-cli/version.VERSION=${{ github.event.release.name }}'" -o artifacts/pdfium-webassembly-windows-amd64 main.go
- uses: actions/upload-artifact@v3
with:
name: builds
path: artifacts
- uses: AButler/upload-release-assets@v2.0
with:
files: 'artifacts/*'
repo-token: ${{ secrets.GITHUB_TOKEN }}

release-cgo-linux:
env:
CGO_ENABLED: 1
LD_LIBRARY_PATH: "/opt/pdfium/lib"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Set up PDFium library libjpeg-turbo
run: |
sudo curl -L https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F${{ env.PDFIUM_VERSION }}/pdfium-linux-x64.tgz -o pdfium-linux-x64.tgz && sudo mkdir /opt/pdfium && sudo tar -C /opt/pdfium -xvf pdfium-linux-x64.tgz
sudo rm pdfium-linux-x64.tgz
sudo cp ./.github/workflows/pdfium.pc /usr/lib/pkgconfig/pdfium.pc
sudo apt-get update -y
sudo apt-get install -y libturbojpeg libturbojpeg-dev
- name: Build
run: |
go build -tags pdfium_experimental,pdfium_cli_use_cgo,pdfium_use_turbojpeg -ldflags "-X 'github.com/klippa-app/pdfium-cli/version.VERSION=${{ github.event.release.name }}'" -o artifacts/pdfium-native-linux-amd64 main.go
- uses: actions/upload-artifact@v3
with:
name: builds
path: artifacts

- uses: AButler/upload-release-assets@v2.0
with:
files: 'artifacts/*'
repo-token: ${{ secrets.GITHUB_TOKEN }}

release-cgo-linux-musl:
env:
CGO_ENABLED: 1
CC: "musl-gcc"
LD_LIBRARY_PATH: "/opt/pdfium/lib:/opt/libjpegturbo/libjpeg-turbo-3.0.0/build"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Set up PDFium library, musl and libjpeg-turbo
run: |
sudo curl -L https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F${{ env.PDFIUM_VERSION }}/pdfium-linux-musl-x64.tgz -o pdfium-linux-musl-x64.tgz && sudo mkdir /opt/pdfium && sudo tar -C /opt/pdfium -xvf pdfium-linux-musl-x64.tgz
sudo rm pdfium-linux-musl-x64.tgz
sudo cp ./.github/workflows/pdfium.pc /usr/lib/pkgconfig/pdfium.pc
sudo cp ./.github/workflows/libturbojpeg.pc /usr/lib/pkgconfig/libturbojpeg.pc
sudo apt-get update -y
sudo apt-get install -y musl-dev musl-tools
sudo curl -L https://master.dl.sourceforge.net/project/libjpeg-turbo/3.0.0/libjpeg-turbo-3.0.0.tar.gz -o libjpeg-turbo-3.0.0.tar.gz && sudo mkdir /opt/libjpegturbo && sudo tar -C /opt/libjpegturbo -xvf libjpeg-turbo-3.0.0.tar.gz
cd /opt/libjpegturbo/libjpeg-turbo-3.0.0 && sudo mkdir build && cd build
sudo cmake -G"Unix Makefiles" -DCMAKE_C_COMPILER=musl-gcc -DWITH_JPEG8=1 -DCMAKE_BUILD_TYPE=None ../
sudo make turbojpeg
- name: Build
run: |
go build --ldflags '-linkmode external -extldflags "-fno-PIC -L/opt/libjpegturbo/libjpeg-turbo-3.0.0/build"' -tags pdfium_experimental,pdfium_cli_use_cgo,pdfium_use_turbojpeg -ldflags "-X 'github.com/klippa-app/pdfium-cli/version.VERSION=${{ github.event.release.name }}'" -o artifacts/pdfium-native-linux-musl-amd64 main.go
- uses: actions/upload-artifact@v3
with:
name: builds
path: artifacts

- uses: AButler/upload-release-assets@v2.0
with:
files: 'artifacts/*'
repo-token: ${{ secrets.GITHUB_TOKEN }}


release-cgo-macos:
env:
CGO_ENABLED: 1
runs-on: macos-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Set up PDFium library and libjpeg-turbo
run: |
sudo curl -L https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F${{ env.PDFIUM_VERSION }}/pdfium-mac-x64.tgz -o pdfium-mac-x64.tgz && sudo mkdir /opt/pdfium && sudo tar -C /opt/pdfium -xvf pdfium-mac-x64.tgz
sudo rm pdfium-mac-x64.tgz
sudo cp ./.github/workflows/pdfium.pc /usr/local/lib/pkgconfig/pdfium.pc
brew install jpeg-turbo
- name: Build
run: |
export LD_LIBRARY_PATH="/opt/pdfium/lib"
go build -tags pdfium_experimental,pdfium_cli_use_cgo,pdfium_use_turbojpeg -ldflags "-X 'github.com/klippa-app/pdfium-cli/version.VERSION=${{ github.event.release.name }}'" -o artifacts/pdfium-native-mac-amd64 main.go
- uses: actions/upload-artifact@v3
with:
name: builds
path: artifacts

- uses: AButler/upload-release-assets@v2.0
with:
files: 'artifacts/*'
repo-token: ${{ secrets.GITHUB_TOKEN }}

release-cgo-windows:
env:
CGO_ENABLED: 1
runs-on: windows-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Set up PDFium library and libjpeg-turbo
run: |
curl -L https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F${{ env.PDFIUM_VERSION }}/pdfium-win-x64.tgz -o pdfium-win-x64.tgz
mkdir -p D:\opt\pdfium
tar -C D:\opt\pdfium -xvf pdfium-win-x64.tgz
rm pdfium-win-x64.tgz
mkdir D:\opt\pkgconfig
cp ./.github/workflows/pdfium-windows.pc D:\opt\pkgconfig\pdfium.pc
curl -L https://master.dl.sourceforge.net/project/libjpeg-turbo/3.0.0/libjpeg-turbo-3.0.0-gcc64.exe -o libjpeg-turbo-3.0.0-gcc64.exe
./libjpeg-turbo-3.0.0-gcc64.exe /S
$Folder = 'C:\libjpeg-turbo-gcc64\lib\pkgconfig'
while (!(Test-Path -Path $Folder)) {
"libjpeg-turbo does not exist yet!"
Start-Sleep -s 5
}
- name: Build
run: |
$env:PKG_CONFIG_PATH = 'D:\opt\pkgconfig;C:\libjpeg-turbo-gcc64\lib\pkgconfig'
$env:Path += ";D:\opt\pdfium\bin;C:\libjpeg-turbo-gcc64\bin"
go build -tags pdfium_experimental,pdfium_cli_use_cgo,pdfium_use_turbojpeg -ldflags "-X 'github.com/klippa-app/pdfium-cli/version.VERSION=${{ github.event.release.name }}'" -o artifacts/pdfium-native-windows-amd64 main.go
- uses: actions/upload-artifact@v3
with:
name: builds
path: artifacts

- uses: AButler/upload-release-assets@v2.0
with:
files: 'artifacts/*'
Expand Down
Loading

0 comments on commit 1f70fec

Please sign in to comment.