Skip to content

Commit

Permalink
Merge branch 'main' of github.com:estkme/lpac into main
Browse files Browse the repository at this point in the history
  • Loading branch information
estkme committed Feb 21, 2024
2 parents 14441b1 + 7e47d21 commit 52e4ab6
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 32 deletions.
44 changes: 27 additions & 17 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
build:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-14]
os: [ubuntu-latest, macos-14]

runs-on: ${{ matrix.os }}
steps:
Expand All @@ -24,19 +24,9 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y libpcsclite-dev libcurl4-openssl-dev gcc make cmake gcc-mingw-w64 g++-mingw-w64 unzip ninja-build
sudo snap install zig --classic --beta
- name: Setup toolchain for Windows(Cygwin)
if: runner.os == 'Windows'
uses: egor-tensin/setup-cygwin@v4
with:
packages: cmake gcc-g++ make zip wget ninja

- name: Build for Windows(Cygwin)
if: runner.os == 'Windows'
run: |
mkdir build-cygwin && cd build-cygwin && cmake .. -GNinja -DCPACK_GENERATOR=CygwinBinary && ninja package
- name: Build for Linux
- name: Build for Linux(X86_64)
if: runner.os == 'Linux'
shell: bash
run: |
Expand All @@ -50,14 +40,32 @@ jobs:
run: |
mkdir build-deb && cd build-deb && cmake .. -GNinja -DCPACK_GENERATOR=DEB && ninja package
- name: Build for Windows(MinGW)
- name: Build for Windows(X86_64 MinGW)
if: runner.os == 'Linux'
shell: bash
run: |
mkdir build-mingw && cd build-mingw && cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw64.cmake .. && ninja
wget https://curl.se/windows/dl-8.5.0_3/curl-8.5.0_3-win64-mingw.zip -O curl.zip && unzip curl.zip && mv curl-8.5.0_3-win64-mingw/bin/libcurl-x64.dll output/libcurl.dll
wget --no-verbose https://curl.se/windows/dl-8.6.0_1/curl-8.6.0_1-win64-mingw.zip -O curl.zip && unzip curl.zip && mv curl-8.6.0_1-win64-mingw/bin/libcurl-x64.dll output/libcurl.dll
zip -r -j lpac-windows-x86_64-mingw.zip output/*
- name: Build for WoA(GNU Toolchain)
if: runner.os == 'Linux'
shell: bash
run: |
mkdir woa-gnu-cross-toolchain && cd woa-gnu-cross-toolchain
wget --no-verbose https://github.com/Windows-on-ARM-Experiments/mingw-woarm64-build/releases/download/2024-02-08/aarch64-w64-mingw32-msvcrt-toolchain.tar.gz && tar xf aarch64-w64-mingw32-msvcrt-toolchain.tar.gz
cd ../ && mkdir build-woa-mingw && cd build-woa-mingw && cmake .. -GNinja -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw64-woa.cmake -DTOOLCHAIN_BIN_PATH=$GITHUB_WORKSPACE/woa-gnu-cross-toolchain/bin && ninja
wget https://curl.se/windows/dl-8.6.0_1/curl-8.6.0_1-win64a-mingw.zip -O curl.zip && unzip curl.zip && mv curl-8.6.0_1-win64a-mingw/bin/libcurl-arm64.dll output/libcurl.dll
zip -r -j lpac-windows-arm64-mingw.zip output/*
- name: Build for WoA(zig)
if: runner.os == 'Linux'
shell: bash
run: |
mkdir build-woa-zig && cd build-woa-zig && cmake .. -GNinja -DCMAKE_TOOLCHAIN_FILE=./cmake/aarch64-windows-zig.cmake && ninja
wget --no-verbose https://curl.se/windows/dl-8.6.0_1/curl-8.6.0_1-win64a-mingw.zip -O curl.zip && unzip curl.zip && mv curl-8.6.0_1-win64a-mingw/bin/libcurl-arm64.dll output/libcurl.dll
zip -r -j lpac-windows-arm64-zig.zip output/*
- name: Build for macOS
if: runner.os == 'macOS'
run: |
Expand All @@ -72,7 +80,8 @@ jobs:
name: artifact-${{ matrix.os }}
path: |
build-mingw/lpac-windows-x86_64-mingw.zip
build-cygwin/lpac-*.tar.bz2
build-woa-mingw/lpac-windows-arm64-mingw.zip
build-woa-zig/lpac-windows-arm64-zig.zip
build-deb/lpac-*.deb
build/lpac-linux-x86_64.zip
build/lpac-macos-universal.zip
Expand All @@ -83,7 +92,8 @@ jobs:
with:
files: |
build-mingw/lpac-windows-x86_64-mingw.zip
build-cygwin/lpac-*.tar.bz2
build-woa-mingw/lpac-windows-arm64-mingw.zip
build-woa-zig/lpac-windows-arm64-zig.zip
build-deb/lpac-*.deb
build/lpac-linux-x86_64.zip
build/lpac-macos-universal.zip
61 changes: 47 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,32 @@ make
</details>

<details>
<summary>Windows</summary>

Due to a [bug in asn1c](https://github.com/vlm/asn1c/issues/196), the MinGW version of lpac cannot send notification successfully. Building with Cygwin seems to avoid it.
<summary>Windows(x86_64)</summary>

Windows need prebuilt libcurl.dll, you can replace the download link to newest curl version.

- Build on Linux(MINGW)

```bash
sudo apt install build-essential cmake git g++ libpcsclite-dev libcurl4-openssl-dev gcc-mingw-w64 g++-mingw-w64
git clone --depth=1 https://github.com/estkme-group/lpac
cd lpac && mkdir build && cd build
cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw64.cmake .. && make
# Download libcurl
wget https://curl.se/windows/dl-8.4.0_6/curl-8.4.0_6-win64-mingw.zip -O curl.zip && unzip curl.zip && mv curl-8.4.0_6-win64-mingw/bin/libcurl-x64.dll output/libcurl.dll
```

- Build on Windows(MSYS2)

```bash
pacman -S mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja mingw-w64-x86_64-gcc
git clone --depth=1 https://github.com/estkme-group/lpac
cd lpac && mkdir build && cd build
cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw64.cmake .. && ninja
# Download libcurl
wget https://curl.se/windows/dl-8.4.0_6/curl-8.4.0_6-win64-mingw.zip -O curl.zip && unzip curl.zip && mv curl-8.4.0_6-win64-mingw/bin/libcurl-x64.dll output/libcurl.dll
```

- Build on Windows(Cygwin)

With `gcc-core` `gcc-g++` `make` `cmake` `unzip` `wget` installed
Expand All @@ -75,27 +95,40 @@ wget https://curl.se/windows/dl-8.4.0_6/curl-8.4.0_6-win64-mingw.zip -O curl.zip
To run it outside Cygwin shell, you need copy `cygwin1.dll` to the program folder to distribute.
`cygwin1.dll` is located in `C:\cygwin64\bin\cygwin1.dll` (Default Cygwin installation location)

- Build on Linux(MINGW)
</details>

<details>
<summary>Windows on ARM</summary>

- Cross compile on Windows/Linux host(arm64,x86_64 and more architecture) with zig

Install [zig](https://ziglang.org/download/)

```bash
sudo apt install build-essential cmake git g++ libpcsclite-dev libcurl4-openssl-dev gcc-mingw-w64 g++-mingw-w64
git clone --depth=1 https://github.com/estkme-group/lpac
cd lpac && mkdir build && cd build
cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw64.cmake .. && make
cd lpac && mkdir build-woa-zig && cd build-woa-zig && cmake .. -GNinja -DCMAKE_TOOLCHAIN_FILE=./cmake/aarch64-windows-zig.cmake && ninja
# Download libcurl
wget https://curl.se/windows/dl-8.4.0_6/curl-8.4.0_6-win64-mingw.zip -O curl.zip && unzip curl.zip && mv curl-8.4.0_6-win64-mingw/bin/libcurl-x64.dll output/libcurl.dll
wget https://curl.se/windows/dl-8.6.0_1/curl-8.6.0_1-win64a-mingw.zip -O curl.zip && unzip curl.zip && mv curl-8.6.0_1-win64a-mingw/bin/libcurl-arm64.dll output/libcurl.dll
```

- Build on Windows(MSYS2)
- Cross compile on Linux x86_64 host(GNU toolchain)

```bash
pacman -S mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja mingw-w64-x86_64-gcc
git clone --depth=1 https://github.com/estkme-group/lpac
cd lpac && mkdir build && cd build
cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw64.cmake .. && ninja
# Download libcurl
wget https://curl.se/windows/dl-8.4.0_6/curl-8.4.0_6-win64-mingw.zip -O curl.zip && unzip curl.zip && mv curl-8.4.0_6-win64-mingw/bin/libcurl-x64.dll output/libcurl.dll
cd lpac && mkdir woa-gnu-cross-toolchain && cd woa-gnu-cross-toolchain
wget https://github.com/Windows-on-ARM-Experiments/mingw-woarm64-build/releases/download/2024-02-08/aarch64-w64-mingw32-msvcrt-toolchain.tar.gz && tar xf aarch64-w64-mingw32-msvcrt-toolchain.tar.gz
cd ../ && mkdir build-woa-mingw && cd build-woa-mingw && cmake .. -GNinja -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw64-woa.cmake -DTOOLCHAIN_BIN_PATH=<path-to-cross-toolchain-bin> && ninja
wget https://curl.se/windows/dl-8.6.0_1/curl-8.6.0_1-win64a-mingw.zip -O curl.zip && unzip curl.zip && mv curl-8.6.0_1-win64a-mingw/bin/libcurl-arm64.dll output/libcurl.dll
```

- Build on Windows(MSYS2)

It is possible to build on **WoA devices** with [MSYS2 ARM64 Support](https://www.msys2.org/wiki/arm64/)

You may need to install `mingw-w64-clang-aarch64-cmake`, `mingw-w64-clang-aarch64-ninja`,`mingw-w64-clang-aarch64-clang` and modify `cmake/linux-mingw64.cmake`(replace toolchain).

Download prebuilt curl dll is also needed. Refer to the previous compilation steps.

</details>

# Usage
Expand Down
15 changes: 15 additions & 0 deletions cmake/aarch64-windows-zig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
set(CMAKE_C_COMPILER "zig" cc -target aarch64-windows-gnu)
set(CMAKE_CXX_COMPILER "zig" c++ -target aarch64-windows-gnu)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -s")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -s")

if(WIN32)
set(SCRIPT_SUFFIX ".cmd")
else()
set(SCRIPT_SUFFIX ".sh")
endif()

set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar${SCRIPT_SUFFIX}")
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib${SCRIPT_SUFFIX}")
13 changes: 13 additions & 0 deletions cmake/linux-mingw64-woa.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(CMAKE_SYSTEM_NAME Windows)

set(TOOLCHAIN_PREFIX ${TOOLCHAIN_BIN_PATH}/aarch64-w64-mingw32)

set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

2 changes: 2 additions & 0 deletions cmake/zig-ar.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
zig ar %*
2 changes: 2 additions & 0 deletions cmake/zig-ar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
zig ar "$@"
2 changes: 2 additions & 0 deletions cmake/zig-ranlib.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
zig ranlib %*
2 changes: 2 additions & 0 deletions cmake/zig-ranlib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
zig ranlib "$@"
2 changes: 1 addition & 1 deletion dlfcn-win32/dlfcn.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ void *dlopen( const char *file, int mode )
* Behavior and doesn't provide expected search paths.
* See also: https://github.com/dlfcn-win32/dlfcn-win32/issues/104
*/
hModule = LoadLibraryExA( lpFileName, NULL, NULL );
hModule = LoadLibraryExA( lpFileName, NULL, 0 );

if( !hModule )
{
Expand Down

0 comments on commit 52e4ab6

Please sign in to comment.