Skip to content

Enhance cross-compilation support for FastFinder; add ARM64 and i386 … #89

Enhance cross-compilation support for FastFinder; add ARM64 and i386 …

Enhance cross-compilation support for FastFinder; add ARM64 and i386 … #89

name: fastfinder_build_windows
on: [push, pull_request]
jobs:
windows_standard-build:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- name: Install MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
path-type: inherit
update: true
install: >-
mingw-w64-x86_64-gcc
mingw-w64-x86_64-toolchain
mingw-w64-x86_64-pkg-config
mingw-w64-x86_64-openssl
mingw-w64-i686-gcc
mingw-w64-i686-toolchain
mingw-w64-i686-pkg-config
mingw-w64-i686-openssl
base-devel
autoconf
automake
libtool
make
unzip
wget
- name: Install YARA v4.5.5
run: |
wget -c https://github.com/VirusTotal/yara/archive/refs/tags/v4.5.5.zip -O /tmp/yara.zip
cd /tmp && unzip yara.zip
cd /tmp/yara-4.5.5
./bootstrap.sh
./configure --prefix=/mingw64
make -j$(nproc)
make install
# Verify yara.pc installation
ls -la /mingw64/lib/pkgconfig/yara.pc
pkg-config --modversion yara
- name: Install YARA v4.5.5 (i386)
run: |
cd /tmp/yara-4.5.5
make clean
./bootstrap.sh
./configure --prefix=/mingw32 --host=i686-w64-mingw32
make -j$(nproc)
make install
- name: Install LLVM-MinGW (for ARM64)
run: |
wget -q https://github.com/mstorsjo/llvm-mingw/releases/download/20231128/llvm-mingw-20231128-ucrt-x86_64.zip -O /tmp/llvm-mingw.zip
unzip -q /tmp/llvm-mingw.zip -d /c/
mv /c/llvm-mingw-20231128-ucrt-x86_64 /c/llvm-mingw
ls /c/llvm-mingw/bin
- name: Build YARA for ARM64
run: |
cd /tmp/yara-4.5.5
make clean
export PATH="/c/llvm-mingw/bin:$PATH"
./configure --host=aarch64-w64-mingw32 --prefix=/c/llvm-mingw/aarch64-w64-mingw32 --disable-shared --disable-openssl --enable-static
make -j$(nproc)
make install
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.24
- uses: actions/checkout@v2
- name: Run Unit Tests (AMD64)
run: |
export PKG_CONFIG_PATH="/mingw64/lib/pkgconfig:$PKG_CONFIG_PATH"
export CGO_CFLAGS="-I/mingw64/include"
export CGO_LDFLAGS="-L/mingw64/lib -lyara -lssl -lcrypto"
go test ./... -v
- name: Build FastFinder (AMD64)
run: |
export PKG_CONFIG_PATH="/mingw64/lib/pkgconfig:$PKG_CONFIG_PATH"
export CGO_CFLAGS="-I/mingw64/include"
# Build AMD64
go build -v -ldflags "-s -w" -tags yara_static -o fastfinder.exe .
./fastfinder.exe -h
- name: Build FastFinder (ARM64)
run: |
export PATH="/c/llvm-mingw/bin:$PATH"
export CGO_ENABLED=1
export GOOS=windows
export GOARCH=arm64
export CC=aarch64-w64-mingw32-gcc
export CXX=aarch64-w64-mingw32-g++
export CGO_CFLAGS="-I/c/llvm-mingw/aarch64-w64-mingw32/include"
export CGO_LDFLAGS="-L/c/llvm-mingw/aarch64-w64-mingw32/lib -lyara -lws2_32 -static"
go build -v -ldflags "-s -w" -tags yara_static -o fastfinder-arm64.exe .
ls -l fastfinder-arm64.exe
# Cannot run ARM64 binary on x64 host easily without emulation setup
- name: Build FastFinder (i386)
run: |
# Use MinGW 32-bit environment
export PATH="/mingw32/bin:$PATH"
export PKG_CONFIG_PATH="/mingw32/lib/pkgconfig"
export CGO_CFLAGS="-I/mingw32/include"
# Default MinGW64 YARA build includes OpenSSL, so we link it
# But for i386 we just built YARA above with defaults, checking if it included openssl?
# Msys2 pkg-config should handle flags if we use it.
# Manually:
export CGO_ENABLED=1
export GOOS=windows
export GOARCH=386
export CGO_LDFLAGS="-L/mingw32/lib -lyara -lssl -lcrypto -lws2_32 -static"
# Wait, we need to check if we installed openssl for i386?
# We installed mingw-w64-i686-toolchain but maybe not openssl?
# The package list had mingw-w64-x86_64-openssl. We need mingw-w64-i686-openssl.
# Or we can build YARA without openssl for i386 like we did for ARM64.
go build -v -ldflags "-s -w" -tags yara_static -o fastfinder-386.exe .
ls -l fastfinder-386.exe
./fastfinder-386.exe -h