Skip to content

Commit

Permalink
Optimize CI (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm authored Aug 25, 2023
1 parent 9574724 commit cde1235
Show file tree
Hide file tree
Showing 54 changed files with 407 additions and 200 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI
on:
push:
paths-ignore: ['**/*.md']
pull_request:
branches: [main]
paths-ignore: ['**/*.md']

jobs:
windows:
uses: ./.github/workflows/windows.yml
permissions:
contents: write

macos:
uses: ./.github/workflows/macos.yml
permissions:
contents: write

linux:
uses: ./.github/workflows/linux.yml
permissions:
contents: write
62 changes: 62 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Linux
on:
workflow_call:

jobs:
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Bundle WebUI Bridge
run: |
npm i -g esbuild
bridge/build.sh
- uses: actions/cache@v3
with:
path: bridge/webui_bridge.h
key: ${{ runner.os }}-${{ github.sha }}-bridge

build-release:
needs: setup
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
matrix:
compiler: [GCC, Clang]
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/cache/restore@v3
with:
path: bridge/webui_bridge.h
key: ${{ runner.os }}-${{ github.sha }}-bridge
fail-on-cache-miss: true
- name: Build
run: |
if [ "${{ matrix.compiler }}" == "Clang" ]; then
sudo ln -s llvm-ar-13 /usr/bin/llvm-ar
sudo ln -s llvm-ranlib-13 /usr/bin/llvm-ranlib
fi
compiler=${{ matrix.compiler }}
make COMPILER=${compiler,,}
- name: Prepare Artifact
run: |
cp -r include dist
artifact=webui-${{ runner.os }}-${{ matrix.compiler }}-x64
# Convert to lowercase (`,,` ^= lowercase shell param)
artifact=${artifact,,}
# Add the ARTIFACT name as GitHub environment variable.
echo "ARTIFACT=$artifact" >> $GITHUB_ENV
mv dist/ $artifact
tar -czvf $artifact.tar.gz $artifact
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT }}
path: ${{ env.ARTIFACT }}
- name: Release Artifact
if: github.ref_type == 'tag'
uses: softprops/action-gh-release@v1
with:
files: ${{ env.ARTIFACT }}.tar.gz
59 changes: 59 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: macOS
on:
workflow_call:

jobs:
setup:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Bundle WebUI Bridge
run: |
npm i -g esbuild
bridge/build.sh
- uses: actions/cache@v3
with:
path: bridge/webui_bridge.h
key: ${{ runner.os }}-${{ github.sha }}-bridge

build-release:
needs: setup
runs-on: macos-latest
permissions:
contents: write
strategy:
matrix:
compiler: [Clang]
arch: [x64, arm64]
steps:
- uses: actions/checkout@v3
- uses: actions/cache/restore@v3
with:
path: bridge/webui_bridge.h
key: ${{ runner.os }}-${{ github.sha }}-bridge
fail-on-cache-miss: true
- name: Build
run: |
if [ "${{ matrix.arch }}" == "arm64" ]; then
make ARCH_TARGET="-target arm64-apple-darwin"
else
make
fi
- name: Prepare Artifacts
run: |
cp -r include dist
# Add the ARTIFACT name(lowercased) as GitHub environment variable.
artifact=$(echo ${{ runner.os }}-${{ matrix.compiler }}-${{ matrix.arch }} | tr '[:upper:]' '[:lower:]')
echo "ARTIFACT=$artifact" >> $GITHUB_ENV
mv dist/ $artifact
tar -czvf $artifact.tar.gz $artifact
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT }}
path: ${{ env.ARTIFACT }}
- name: Release Artifact
if: github.ref_type == 'tag'
uses: softprops/action-gh-release@v1
with:
files: ${{ env.ARTIFACT }}.tar.gz
63 changes: 63 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Windows
on:
workflow_call:

jobs:
setup:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Bundle WebUI Bridge
run: bridge/build.ps1
- uses: actions/cache@v3
with:
path: bridge/webui_bridge.h
key: ${{ runner.os }}-${{ github.sha }}-bridge

build-release:
needs: setup
runs-on: windows-latest
permissions:
contents: write
strategy:
matrix:
compiler: [GCC, MSVC]
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/cache/restore@v3
with:
path: bridge/webui_bridge.h
key: ${{ runner.os }}-${{ github.sha }}-bridge
fail-on-cache-miss: true
- uses: microsoft/[email protected]
- if: ${{ matrix.compiler == 'MSVC' }}
uses: ilammy/msvc-dev-cmd@v1
- name: Build
run: |
if ('${{ matrix.compiler }}' -eq 'MSVC') {
nmake -f ./Makefile.nmake
} else {
mingw32-make
}
- name: Prepare Artifact
shell: bash
run: |
cp -r include dist
artifact=webui-${{ runner.os }}-${{ matrix.compiler }}-x64
# Convert to lowercase (`,,` ^= lowercase shell param)
artifact=${artifact,,}
# Add the ARTIFACT name as GitHub environment variable.
echo "ARTIFACT=$artifact" >> $GITHUB_ENV
mv dist/ $artifact
7z a -tzip $artifact.zip $artifact
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT }}
path: ${{ env.ARTIFACT }}
- name: Release Artifact
if: github.ref_type == 'tag'
uses: softprops/action-gh-release@v1
with:
files: ${{ env.ARTIFACT }}.zip
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ WEBUI_BUILD_FLAGS := -m64 -o webui.o -I "$(MAKEFILE_DIR)/include/" -c "$(MAKEFIL
# Output files
# The static output is the same for all platforms
# The dynamic output is platform dependent
LIB_STATIC_OUT := libwebui-2-static-x64.a
LIB_STATIC_OUT := libwebui-2-static.a

# Platform defaults and dynamic library outputs
ifeq ($(OS),Windows_NT)
# Windows
PLATFORM := windows
VALID_COMPILERS := gcc tcc
LIB_DYN_OUT := webui-2-x64.dll
LIB_DYN_OUT := webui-2.dll
LWS2_OPT := -lws2_32
ifeq ($(COMPILER),tcc)
BUILD_TARGET := --tcc
Expand All @@ -41,15 +41,15 @@ else
# MacOS
PLATFORM := macos
VALID_COMPILERS := clang
LIB_DYN_OUT := webui-2-x64.dylib
LIB_DYN_OUT := webui-2.dylib
ifeq ($(COMPILER),)
COMPILER = clang
endif
else
# Linux
PLATFORM := linux
VALID_COMPILERS := gcc clang
LIB_DYN_OUT := webui-2-x64.so
LIB_DYN_OUT := webui-2.so
ifeq ($(COMPILER),)
COMPILER = gcc
else ifeq ($(COMPILER),clang)
Expand Down Expand Up @@ -84,11 +84,11 @@ ifneq ($(filter $(COMPILER),$(VALID_COMPILERS)),$(COMPILER))
endif
# Arch target is for CI cross-compilation
ifneq ($(ARCH_TARGET),)
ifneq ($(PLATFORM),macos)
$(error ARCH_TARGET is only available on macOS)
else ifeq ($(ARCH_TARGET),arm64-apple-darwin)
ARCH_TARGET := -target $(ARCH_TARGET)
endif
ifneq ($(PLATFORM),macos)
$(error ARCH_TARGET is only available on macOS)
endif
# WARN: Wrong input is not covered yet due to difficulties with differing behavior on Mac
# ARCH_TARGET is intented for CI use. Valid input is `ARCH_TARGET="-target arm64-apple-darwin"`.
endif

# == 2.1.1 GCC / CLANG ========================================================
Expand Down
4 changes: 2 additions & 2 deletions Makefile.nmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ CIVETWEB_DEFINE_FLAGS = -DNDEBUG -DNO_CACHING -DNO_CGI -DNO_SSL -DUSE_WEBSOCKET
WEBUI_BUILD_FLAGS = /Fo$(BUILD_DIR)webui.obj /c /EHsc "$(MAKEFILE_DIR)/src/webui.c" /I "$(MAKEFILE_DIR)include"

# Output Commands
LIB_STATIC_OUT = /OUT:$(BUILD_DIR)webui-2-static-x64.lib $(BUILD_DIR)webui.obj $(BUILD_DIR)civetweb.obj
LIB_DYN_OUT = /DLL /OUT:$(BUILD_DIR)webui-2-x64.dll $(BUILD_DIR)webui.obj $(BUILD_DIR)civetweb.obj user32.lib Advapi32.lib
LIB_STATIC_OUT = /OUT:$(BUILD_DIR)webui-2-static.lib $(BUILD_DIR)webui.obj $(BUILD_DIR)civetweb.obj
LIB_DYN_OUT = /DLL /OUT:$(BUILD_DIR)webui-2.dll $(BUILD_DIR)webui.obj $(BUILD_DIR)civetweb.obj user32.lib Advapi32.lib

# == 2.TARGETS ================================================================

Expand Down
8 changes: 4 additions & 4 deletions examples/C++/call_cpp_from_js/Linux/Clang/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ all: release
debug:
# Static with Debug info
@echo "Build C++ Example (Static Debug)..."
@clang -std=c++17 -lstdc++ -g -m64 -o main "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" -lwebui-2-static-x64 -lpthread -lm
@clang -std=c++17 -lstdc++ -g -m64 -o main "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" -lwebui-2-static -lpthread -lm
# Dynamic with Debug info
@echo "Build C++ Example (Dynamic Debug)..."
@clang -std=c++17 -lstdc++ -g -m64 -o main-dyn "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" "$(LIB)/webui-2-x64.so" -lpthread -lm
@clang -std=c++17 -lstdc++ -g -m64 -o main-dyn "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" "$(LIB)/webui-2.so" -lpthread -lm
# Clean
@- rm -f *.o
@echo "Done."

release:
# Static Release
@echo "Build C++ Example (Static Release)..."
@clang -std=c++17 -lstdc++ -Os -m64 -o main "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" -lwebui-2-static-x64 -lpthread -lm
@clang -std=c++17 -lstdc++ -Os -m64 -o main "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" -lwebui-2-static -lpthread -lm
@llvm-strip --strip-all main
# Dynamic Release
@echo "Build C++ Example (Dynamic Release)..."
@clang -std=c++17 -lstdc++ -m64 -o main-dyn "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" "$(LIB)/webui-2-x64.so" -lpthread -lm
@clang -std=c++17 -lstdc++ -m64 -o main-dyn "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" "$(LIB)/webui-2.so" -lpthread -lm
@llvm-strip --strip-all main-dyn
# Clean
@- rm -f *.o
Expand Down
8 changes: 4 additions & 4 deletions examples/C++/call_cpp_from_js/Linux/GCC/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ all: release
debug:
# Static with Debug info
@echo "Build C++ Example (Static Debug)..."
@g++ -std=c++17 -g -m64 -o main "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" -lwebui-2-static-x64 -lpthread -lm
@g++ -std=c++17 -g -m64 -o main "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" -lwebui-2-static -lpthread -lm
# Dynamic with Debug info
@echo "Build C++ Example (Dynamic Debug)..."
@g++ -std=c++17 -g -m64 -o main-dyn "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" "$(LIB)/webui-2-x64.so" -lpthread -lm
@g++ -std=c++17 -g -m64 -o main-dyn "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" "$(LIB)/webui-2.so" -lpthread -lm
# Clean
@- rm -f *.o
@echo "Done."

release:
# Static Release
@echo "Build C++ Example (Static Release)..."
@g++ -std=c++17 -Os -m64 -o main "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" -lwebui-2-static-x64 -lpthread -lm
@g++ -std=c++17 -Os -m64 -o main "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" -lwebui-2-static -lpthread -lm
@strip --strip-all main
# Dynamic Release
@echo "Build C++ Example (Dynamic Release)..."
@g++ -std=c++17 -m64 -o main-dyn "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" "$(LIB)/webui-2-x64.so" -lpthread -lm
@g++ -std=c++17 -m64 -o main-dyn "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" "$(LIB)/webui-2.so" -lpthread -lm
@strip --strip-all main-dyn
# Clean
@- rm -f *.o
Expand Down
8 changes: 4 additions & 4 deletions examples/C++/call_cpp_from_js/Windows/GCC/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ debug:
# Static with Debug info
@echo Build C++ Example (Debug Static)...
@windres win.rc -O coff -o win.res
@g++ -std=c++17 -g -static -m64 -o main.exe "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" win.res -lwebui-2-static-x64 -lws2_32 -Wall -Wl,-subsystem=console -luser32
@g++ -std=c++17 -g -static -m64 -o main.exe "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" win.res -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32
# Dynamic with Debug info
@echo Build C++ Example (Debug Dynamic)...
@windres win.rc -O coff -o win.res
@g++ -std=c++17 -g -m64 -o main-dyn.exe "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" win.res "$(LIB)/webui-2-x64.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32
@g++ -std=c++17 -g -m64 -o main-dyn.exe "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" win.res "$(LIB)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32
# Clean
@- del *.o >nul 2>&1
@- del *.res >nul 2>&1
Expand All @@ -27,12 +27,12 @@ release:
# Static Release
@echo Build C++ Example (Release Static)...
@windres win.rc -O coff -o win.res
@g++ -std=c++17 -static -Os -m64 -o main.exe "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" win.res -lwebui-2-static-x64 -lws2_32 -Wall -Wl,-subsystem=windows -luser32
@g++ -std=c++17 -static -Os -m64 -o main.exe "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" win.res -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=windows -luser32
@strip --strip-all main.exe
# Dynamic Release
@echo Build C++ Example (Release Dynamic)...
@windres win.rc -O coff -o win.res
@g++ -std=c++17 -m64 -o main-dyn.exe "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" win.res "$(LIB)/webui-2-x64.dll" -lws2_32 -Wall -Wl,-subsystem=windows -luser32
@g++ -std=c++17 -m64 -o main-dyn.exe "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" win.res "$(LIB)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=windows -luser32
@strip --strip-all main-dyn.exe
# Clean
@- del *.o >nul 2>&1
Expand Down
8 changes: 4 additions & 4 deletions examples/C++/call_cpp_from_js/Windows/MSVC/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ debug:
# Static with Debug info
@echo Build C++ Example (Debug Static)...
@rc win.rc 1>NUL 2>&1
@cl /Zi /EHsc /std:c++17 "$(_SOURCE)/main.cpp" /I "$(_INCLUDE)" /link /LIBPATH:"$(_LIB)" /MACHINE:X64 /SUBSYSTEM:CONSOLE win.res webui-2-static-x64.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1
@cl /Zi /EHsc /std:c++17 "$(_SOURCE)/main.cpp" /I "$(_INCLUDE)" /link /LIBPATH:"$(_LIB)" /MACHINE:X64 /SUBSYSTEM:CONSOLE win.res webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1
# Dynamic with Debug info
@echo Build C++ Example (Debug Dynamic)...
@rc win.rc 1>NUL 2>&1
@cl /Zi /EHsc /std:c++17 "$(_SOURCE)/main.cpp" /I "$(_INCLUDE)" /link /LIBPATH:"$(_LIB)" /MACHINE:X64 /SUBSYSTEM:CONSOLE win.res webui-2-x64.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1
@cl /Zi /EHsc /std:c++17 "$(_SOURCE)/main.cpp" /I "$(_INCLUDE)" /link /LIBPATH:"$(_LIB)" /MACHINE:X64 /SUBSYSTEM:CONSOLE win.res webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1

release:
# Build Lib
@cd "$(_LIB)" && $(MAKE)
# Static Release
@echo Build C++ Example (Release Static)...
@rc win.rc 1>NUL 2>&1
@cl /EHsc /std:c++17 "$(_SOURCE)/main.cpp" /I "$(_INCLUDE)" /link /LIBPATH:"$(_LIB)" /MACHINE:X64 /SUBSYSTEM:WINDOWS win.res webui-2-static-x64.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1
@cl /EHsc /std:c++17 "$(_SOURCE)/main.cpp" /I "$(_INCLUDE)" /link /LIBPATH:"$(_LIB)" /MACHINE:X64 /SUBSYSTEM:WINDOWS win.res webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1
# Dynamic Release
@echo Build C++ Example (Release Dynamic)...
@rc win.rc 1>NUL 2>&1
@cl /EHsc /std:c++17 "$(_SOURCE)/main.cpp" /I "$(_INCLUDE)" /link /LIBPATH:"$(_LIB)" /MACHINE:X64 /SUBSYSTEM:WINDOWS win.res webui-2-x64.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1
@cl /EHsc /std:c++17 "$(_SOURCE)/main.cpp" /I "$(_INCLUDE)" /link /LIBPATH:"$(_LIB)" /MACHINE:X64 /SUBSYSTEM:WINDOWS win.res webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1
# Clean
@- del *.res >nul 2>&1
@- del *.obj >nul 2>&1
Expand Down
Loading

0 comments on commit cde1235

Please sign in to comment.