Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions .github/workflows/build-windows-x64-vs2019.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Build x64 Static (Release)

on: [push, pull_request]

jobs:
build-x64-static:
# if windows-latest, might not find VS 2019
runs-on: windows-2019


env:
# Windows SDK 8.1 URL
sdk-url: https://go.microsoft.com/fwlink/p/?LinkId=323507
# place it's saved to, used for cache as well
sdk-dlexe: sdksetup8.1.exe
mozjpeg-lib: deps/mozjpeg/build/*.lib
mozjpeg-h: deps/mozjpeg/build/*.h
mozjpeg-dll: deps/mozjpeg/build/*.dll
cache-name: cache-deps


steps:
- name: Checkout code with submodules
uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup msbuild
# https://github.com/marketplace/actions/setup-msbuild
uses: microsoft/[email protected]
with:
# Fixed on Visual Studio 2019 -- https://docs.microsoft.com/en-us/visualstudio/releases/2019/history
vs-version: '[16.0,17.0)'
msbuild-architecture: x64

- name: Setup NASM
# https://github.com/marketplace/actions/set-up-nasm
uses: ilammy/setup-nasm@v1


- name: Cache SDK and deps
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows
uses: actions/cache@v3
env:
cache-name: ${{ env.cache-name }}
with:
# change the cache whenever gitmodules gets updated (all deps invalidated)
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('.gitmodules') }}
path: |
# path where we would save the SDK
${{ env.sdk-dlexe }}
# path where the mozjpeg lib is, this shouldn't change between runs, but clear the cache in GH if the submodule gets updated
${{ env.mozjpeg-lib }}
# need header files also
${{ env.mozjpeg-h }}
# need dll files to run jpeg-*.exe
${{ env.mozjpeg-dll }}


# https://github.com/actions/runner-images/issues/842#issuecomment-643382166
# required to build iqa
- name: Install Windows 8.1 SDK
shell: powershell
run: |
if ( Test-Path -Path "${{ env.sdk-dlexe }}" ) {
echo "Cache found, not re-downloading sdk"
} else {
echo "Downloading Windows 8.1 SDK"
Invoke-WebRequest -Method Get -Uri "${{ env.sdk-url }}" -OutFile "${{ env.sdk-dlexe }}" -UseBasicParsing
}

echo "Installing Windows 8.1 SDK"
Start-Process -Wait "${{ env.sdk-dlexe }}" -ArgumentList "/q", "/norestart", "/features", "OptionId.WindowsDesktopSoftwareDevelopmentKit", "OptionId.NetFxSoftwareDevelopmentKit"


- name: Print environment
run: |
Get-Command nasm.exe | Format-List
Get-Command msbuild.exe | Format-List
#Get-ChildItem "C:\Program Files (x86)"
#Get-ChildItem "C:\Program Files"

# powershell is so slow on the runner, it works but slow
#Get-ChildItem -Path "C:\Program Files (x86)\Microsoft Visual Studio\2019" -Filter "vcvars64.bat" -Recurse -ErrorAction SilentlyContinue -Force #| Foreach {&$_.FullName}
Get-ChildItem -Path "C:\Program Files (x86)\Microsoft Visual Studio\2019" -Filter "vcvars64.bat" -Recurse -ErrorAction SilentlyContinue -Force | Foreach {echo "vcvars_bat=$($_.FullName)" >> $env:GITHUB_ENV}

#Get-Command cl.exe | Format-List


- name: Build jpeg-archive
shell: cmd
run: |
REM run the vcvars.bat first
call "%vcvars_bat%"

REM this also works but possible errors running (batch limitation):
REM FOR /F "usebackq tokens=*" %%I IN (`dir /b /s "C:\Program Files (x86)\Microsoft Visual Studio\2019\vcvars64.bat"`) DO (echo %%I && call "%%I")

where cl.exe

echo Run compile batchfile ...
compile-on-windows.cmd static


- name: Upload Binaries
uses: actions/upload-artifact@v3
with:
name: release-x64-static
# Static build doesn't need jpeg*.dll
#jpeg*.dll
path: |
jpeg*.exe
jpeg*.lib
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "deps/mozjpeg"]
path = deps/mozjpeg
url = [email protected]:mozilla/mozjpeg.git
29 changes: 29 additions & 0 deletions Makefile.win64-dynamic
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Win32 Makefile created by Zoltan Frombach <[email protected]>
# sylikc modified to use mozjpeg from the deps directory instead of external to the project

CC = cl
CFLAGS = -I. -I./src -I./deps/mozjpeg -I./deps/mozjpeg/build -DHAVE_CONFIG_H -D_CONSOLE /W2 /O2 /DNDEBUG /nologo
LDLIBS = /DEBUG:NONE /NODEFAULTLIB:MSVCRT
LIBJPEG = ./deps/mozjpeg/build/jpeg.lib
LIBIQA = src/iqa/build/release/iqa.lib

all: jpeg-recompress jpeg-compare jpeg-hash

jpeg-recompress: jpeg-recompress.obj src/util.obj src/edit.obj src/smallfry.obj $(LIBIQA)
$(CC) $(CFLAGS) /Fejpeg-recompress.exe jpeg-recompress.obj util.obj edit.obj smallfry.obj $(LIBIQA) $(LIBJPEG) $(LDFLAGS) /link /LTCG $(LDLIBS)

jpeg-compare: jpeg-compare.obj src/util.obj src/hash.obj src/edit.obj src/smallfry.obj $(LIBIQA)
$(CC) $(CFLAGS) /Fejpeg-compare.exe jpeg-compare.obj util.obj hash.obj edit.obj smallfry.obj $(LIBIQA) $(LIBJPEG) $(LDFLAGS) /link /LTCG $(LDLIBS)

jpeg-hash: jpeg-hash.obj src/util.obj src/hash.obj
$(CC) $(CFLAGS) /Fejpeg-hash.exe jpeg-hash.obj util.obj hash.obj $(LIBJPEG) $(LDFLAGS) /link $(LDLIBS)

%.obj: %.c %.h
$(CC) $(CFLAGS) /c $<

test: test/test.obj src/util.obj src/edit.obj src/hash.obj
$(CC) $(CFLAGS) /Fetest/test.exe test.obj util.obj edit.obj hash.obj $(LIBJPEG) $(LDFLAGS) /link $(LDLIBS)
./test.exe

clean:
del *.obj src/*.obj *.exe
29 changes: 29 additions & 0 deletions Makefile.win64-static
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Win32 Makefile created by Zoltan Frombach <[email protected]>
# sylikc modified to use mozjpeg from the deps directory instead of external to the project

CC = cl
CFLAGS = -I. -I./src -I./deps/mozjpeg -I./deps/mozjpeg/build -DHAVE_CONFIG_H -D_CONSOLE /W2 /O2 /DNDEBUG /nologo
LDLIBS = /DEBUG:NONE /NODEFAULTLIB:MSVCRT
LIBJPEG = ./deps/mozjpeg/build/jpeg-static.lib
LIBIQA = src/iqa/build/release/iqa.lib

all: jpeg-recompress jpeg-compare jpeg-hash

jpeg-recompress: jpeg-recompress.obj src/util.obj src/edit.obj src/smallfry.obj $(LIBIQA)
$(CC) $(CFLAGS) /Fejpeg-recompress.exe jpeg-recompress.obj util.obj edit.obj smallfry.obj $(LIBIQA) $(LIBJPEG) $(LDFLAGS) /link /LTCG $(LDLIBS)

jpeg-compare: jpeg-compare.obj src/util.obj src/hash.obj src/edit.obj src/smallfry.obj $(LIBIQA)
$(CC) $(CFLAGS) /Fejpeg-compare.exe jpeg-compare.obj util.obj hash.obj edit.obj smallfry.obj $(LIBIQA) $(LIBJPEG) $(LDFLAGS) /link /LTCG $(LDLIBS)

jpeg-hash: jpeg-hash.obj src/util.obj src/hash.obj
$(CC) $(CFLAGS) /Fejpeg-hash.exe jpeg-hash.obj util.obj hash.obj $(LIBJPEG) $(LDFLAGS) /link $(LDLIBS)

%.obj: %.c %.h
$(CC) $(CFLAGS) /c $<

test: test/test.obj src/util.obj src/edit.obj src/hash.obj
$(CC) $(CFLAGS) /Fetest/test.exe test.obj util.obj edit.obj hash.obj $(LIBJPEG) $(LDFLAGS) /link $(LDLIBS)
./test.exe

clean:
del *.obj src/*.obj *.exe
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Run Github for windows. In the settings, set **Git Bash** as the shell. Open Git

```bash
# Update PATH to include MinGW/NASM bin folder, location on your system may vary
export PATH=/c/mingw/mingw32/bin:/c/Program\ Files \(x68\)/nasm:$PATH
export PATH=/c/mingw/mingw32/bin:/c/Program\ Files \(x86\)/nasm:$PATH

# Build mozjpeg or download https://www.dropbox.com/s/98jppfgds2xjblu/libjpeg.a
git clone https://github.com/mozilla/mozjpeg.git
Expand Down Expand Up @@ -230,3 +230,22 @@ License
All are released under an MIT license.

http://dgt.mit-license.org/


#### Windows with VS2017

Initialize submodules to include mozjpeg from deps folder

Open command prompt

```cmd
REM initialize your C++ Environment, if necessary
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"

REM Update PATH to include NASM bin folder, location on your system may vary
SET PATH=C:\Program Files (x86)\nasm;%PATH%

REM run the compile script for x64 VS2017 build
compile-on-windows.cmd

```
89 changes: 89 additions & 0 deletions compile-on-windows.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
@ECHO OFF

setlocal

REM make clean by deleting
REM deps\mozjpeg\build
REM src\iqa\build

REM if static or not
REM should really use CMake, but doing it the quick and dirty way to get it working
SET JPA_MAKEFILE=
IF /I "%~1" EQU "static" (
echo Static build requested
SET JPA_MAKEFILE=Makefile.win64-static
) ELSE (
echo Dynamically linked build requested
SET JPA_MAKEFILE=Makefile.win64-dynamic
)

REM this is currently for x64 build, but should be easily adaptable to 32-bit build

echo == Checking Environment ==

where.exe msbuild.exe
IF ERRORLEVEL 1 (
echo MSBUILD environment not yet intialized, please run the vcvars##.bat to initialize the environment
exit /b 1
)

where.exe cl.exe
IF ERRORLEVEL 1 (
echo CL is required to build, please run the vcvars##.bat to initialize the environment
exit /b 1
)

where.exe nasm.exe
IF ERRORLEVEL 1 (
echo NASM needs to be available on PATH
exit /b 1
)



REM build mozjpegturbo libs
echo == Build deps\mozjpeg ==
pushd deps\mozjpeg
mkdir build
cd build
IF EXIST "jpeg.lib" (
REM use any cached version if exists
echo JPEG.LIB already exists, not rebuilding mozjpeg
GOTO SKIP_MOZJPEG
)
cmake.exe -G"NMake Makefiles" -DPNG_SUPPORTED=0 -DCMAKE_BUILD_TYPE=Release ..
IF ERRORLEVEL 1 (
echo mozjpeg CMAKE failed
exit /b 1
)
nmake.exe
IF ERRORLEVEL 1 (
echo mozjpeg NMAKE failed
exit /b 1
)
:SKIP_MOZJPEG
REM copy the required linked DLL file from mozjpeg\build
echo Copying jpeg62.dll to base directory...
copy jpeg62.dll ..\..\..\
popd



echo == Build src\iqa ==
pushd src\iqa
MsBuild.exe iqa.sln /t:Build /p:Configuration=Release /p:Platform=x64 /p:DebugSymbols=false /p:DebugType=None
IF ERRORLEVEL 1 (
echo iqa msbuild failed
exit /b 1
)
popd


echo == Build jpeg-archive ==
nmake.exe /NOLOGO /F %JPA_MAKEFILE%
IF ERRORLEVEL 1 (
echo jpeg-archive nmake failed
exit /b 1
)

echo Success! Find built files in %CD%
1 change: 1 addition & 0 deletions deps/mozjpeg
Submodule mozjpeg added at fd5692
Loading