diff --git a/.github/workflows/verify-build.yml b/.github/workflows/verify-build.yml index e4842605..7a42e5bf 100644 --- a/.github/workflows/verify-build.yml +++ b/.github/workflows/verify-build.yml @@ -20,6 +20,9 @@ jobs: BUILD_TYPE: ${{ matrix.build-type }} CC: ${{ matrix.c-compiler }} CXX: ${{ matrix.cc-compiler }} + defaults: + run: + shell: ${{ matrix.shell }} strategy: fail-fast: false matrix: @@ -33,6 +36,7 @@ jobs: coverage: [coverage, nocoverage] linking: [dynamic, static] build-type: [classic] + shell: [bash] exclude: - os: ubuntu-latest os-type: mac @@ -62,6 +66,7 @@ jobs: cc-compiler: clang++-18 debug: debug coverage: nocoverage + shell: bash # This test gives false positives on newer versions of clang # and ubuntu-18.04 is not supported anymore on github #- test-group: extra @@ -82,6 +87,7 @@ jobs: cc-compiler: clang++-18 debug: debug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -91,6 +97,7 @@ jobs: cc-compiler: clang++-18 debug: debug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -100,6 +107,7 @@ jobs: cc-compiler: clang++-18 debug: debug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -109,6 +117,7 @@ jobs: cc-compiler: g++-9 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -118,6 +127,7 @@ jobs: cc-compiler: g++-10 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -127,6 +137,7 @@ jobs: cc-compiler: g++-11 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -136,6 +147,7 @@ jobs: cc-compiler: g++-12 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -145,6 +157,7 @@ jobs: cc-compiler: g++-13 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -154,6 +167,7 @@ jobs: cc-compiler: g++-14 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-22.04 os-type: ubuntu @@ -163,6 +177,7 @@ jobs: cc-compiler: clang++-11 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-22.04 os-type: ubuntu @@ -172,6 +187,7 @@ jobs: cc-compiler: clang++-12 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-22.04 os-type: ubuntu @@ -181,6 +197,7 @@ jobs: cc-compiler: clang++-13 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -190,6 +207,7 @@ jobs: cc-compiler: clang++-14 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -199,6 +217,7 @@ jobs: cc-compiler: clang++-15 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -208,6 +227,7 @@ jobs: cc-compiler: clang++-16 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -217,6 +237,7 @@ jobs: cc-compiler: clang++-17 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -226,6 +247,7 @@ jobs: cc-compiler: g++-14 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -235,6 +257,7 @@ jobs: cc-compiler: clang++-18 debug: nodebug coverage: nocoverage + shell: bash - test-group: performance os: ubuntu-latest os-type: ubuntu @@ -244,6 +267,7 @@ jobs: cc-compiler: g++-10 debug: nodebug coverage: nocoverage + shell: bash - test-group: performance os: ubuntu-latest os-type: ubuntu @@ -253,6 +277,7 @@ jobs: cc-compiler: g++-10 debug: nodebug coverage: nocoverage + shell: bash - test-group: performance os: ubuntu-latest os-type: ubuntu @@ -262,6 +287,7 @@ jobs: cc-compiler: g++-10 debug: nodebug coverage: nocoverage + shell: bash - test-group: extra os: ubuntu-latest os-type: ubuntu @@ -271,6 +297,31 @@ jobs: cc-compiler: g++-10 debug: debug coverage: nocoverage + shell: bash + - test-group: basic + os: windows-latest + os-type: windows + msys-env: MINGW64 + shell: 'msys2 {0}' + build-type: classic + compiler-family: none + c-compiler: gcc + cc-compiler: g++ + debug: nodebug + coverage: nocoverage + linking: dynamic + - test-group: basic + os: windows-latest + os-type: windows + msys-env: MSYS + shell: 'msys2 {0}' + build-type: classic + compiler-family: none + c-compiler: gcc + cc-compiler: g++ + debug: nodebug + coverage: nocoverage + linking: dynamic steps: - name: Checkout repository uses: actions/checkout@v4 @@ -282,8 +333,29 @@ jobs: # If this run was triggered by a pull request event, then checkout # the head of the pull request instead of the merge commit. - run: git checkout HEAD^2 + shell: bash if: ${{ github.event_name == 'pull_request' }} - + + - name: Setup MSYS2 + if: ${{ matrix.os-type == 'windows' }} + uses: msys2/setup-msys2@v2 + with: + msystem: ${{ matrix.msys-env }} + update: true + install: >- + autotools + base-devel + + - name: Install MinGW64 packages + if: ${{ matrix.os-type == 'windows' && matrix.msys-env == 'MINGW64' }} + run: | + pacman --noconfirm -S --needed mingw-w64-x86_64-{toolchain,libtool,make,pkg-config,libsystre,doxygen,gnutls,graphviz,curl} + + - name: Install MSYS packages + if: ${{ matrix.os-type == 'windows' && matrix.msys-env == 'MSYS' }} + run: | + pacman --noconfirm -S --needed msys2-devel gcc make libcurl-devel libgnutls-devel + - name: Install Ubuntu test sources run: | sudo add-apt-repository ppa:ubuntu-toolchain-r/test ; @@ -395,6 +467,7 @@ jobs: with: path: libmicrohttpd-0.9.77 key: ${{ matrix.os }}-${{ matrix.c-compiler }}-libmicrohttpd-0.9.77-pre-built + if: ${{ matrix.os-type != 'windows' }} - name: Build libmicrohttpd dependency (if not cached) run: | @@ -403,10 +476,21 @@ jobs: cd libmicrohttpd-0.9.77 ; ./configure --disable-examples ; make ; - if: steps.cache-libmicrohttpd.outputs.cache-hit != 'true' + if: ${{ matrix.os-type != 'windows' && steps.cache-libmicrohttpd.outputs.cache-hit != 'true' }} - name: Install libmicrohttpd run: cd libmicrohttpd-0.9.77 ; sudo make install ; + if: ${{ matrix.os-type != 'windows' }} + + - name: Build and install libmicrohttpd (Windows) + if: ${{ matrix.os-type == 'windows' }} + run: | + curl https://s3.amazonaws.com/libhttpserver/libmicrohttpd_releases/libmicrohttpd-0.9.77.tar.gz -o libmicrohttpd-0.9.77.tar.gz + tar -xzf libmicrohttpd-0.9.77.tar.gz + cd libmicrohttpd-0.9.77 + ./configure --disable-examples --enable-poll=no + make + make install - name: Refresh links to shared libs run: sudo ldconfig ; @@ -449,6 +533,7 @@ jobs: fi - name: Print config.log + shell: bash run: | cd build ; cat config.log ; @@ -486,6 +571,7 @@ jobs: if: ${{ matrix.build-type != 'iwyu' }} - name: Print tests results + shell: bash run: | cd build ; cat test/test-suite.log ; diff --git a/README.md b/README.md index 83f0b5b6..b00d7be4 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ Copyright (C) 2011-2019 Sebastiano Merlino. # The libhttpserver reference manual ![GA: Build Status](https://github.com/etr/libhttpserver/actions/workflows/verify-build.yml/badge.svg) -[![Build status](https://ci.appveyor.com/api/projects/status/ktoy6ewkrf0q1hw6/branch/master?svg=true)](https://ci.appveyor.com/project/etr/libhttpserver/branch/master) [![codecov](https://codecov.io/gh/etr/libhttpserver/branch/master/graph/badge.svg)](https://codecov.io/gh/etr/libhttpserver) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/1bd1e8c21f66400fb70e5a5ce357b525)](https://www.codacy.com/gh/etr/libhttpserver/dashboard?utm_source=github.com&utm_medium=referral&utm_content=etr/libhttpserver&utm_campaign=Badge_Grade) [![Gitter chat](https://badges.gitter.im/etr/libhttpserver.png)](https://gitter.im/libhttpserver/community) @@ -119,6 +118,53 @@ Here are listed the libhttpserver specific options (the canonical configure opti [Back to TOC](#table-of-contents) +### Building on Windows (MSYS2) + +MSYS2 provides multiple shell environments with different purposes. Understanding which shell to use is important: + +| Shell | Host Triplet | Runtime Dependency | Use Case | +|-------|--------------|-------------------|----------| +| **MinGW64** | `x86_64-w64-mingw32` | Native Windows | **Recommended** for native Windows apps | +| **MSYS** | `x86_64-pc-msys` | msys-2.0.dll | POSIX-style apps, build tools | + +**Recommended: Use the MinGW64 shell** for building libhttpserver to produce native Windows binaries without additional runtime dependencies. + +#### Step-by-step build instructions + +1. Install [MSYS2](https://www.msys2.org/) + +2. Open the **MINGW64** shell (not the MSYS shell) from the Start Menu + +3. Install dependencies: +```bash +pacman -S --needed mingw-w64-x86_64-{gcc,libtool,make,pkg-config,doxygen,gnutls,curl} autotools +``` + +4. Build and install [libmicrohttpd](https://www.gnu.org/software/libmicrohttpd/) (>= 0.9.64) + +5. Build libhttpserver: +```bash +./bootstrap +mkdir build && cd build +../configure --disable-fastopen +make +make check # run tests +``` + +**Important:** The `--disable-fastopen` flag is required on Windows as TCP_FASTOPEN is not supported. + +#### If you use the MSYS shell + +Building from the MSYS shell also works but the resulting binaries will depend on `msys-2.0.dll`. The configure script will display a warning when building in this environment. If you see: + +``` +configure: WARNING: Building from MSYS environment. Binaries will depend on msys-2.0.dll. +``` + +Consider switching to the MinGW64 shell for native Windows binaries. + +[Back to TOC](#table-of-contents) + ## Getting Started The most basic example of creating a server and handling a requests for the path `/hello`: ```cpp diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index bc2fb9e7..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,27 +0,0 @@ -platform: x64 - -environment: - matrix: - - compiler: msys2 - MINGW_CHOST: x86_64-w64-mingw32 - MSYS2_ARCH: x86_64 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 -init: - - 'echo Building libhttpserver %version% for Windows' - - 'echo System architecture: %PLATFORM%' - - 'echo Repo build branch is: %APPVEYOR_REPO_BRANCH%' - - 'echo Build folder is: %APPVEYOR_BUILD_FOLDER%' - - 'echo Repo build commit is: %APPVEYOR_REPO_COMMIT%' - - 'echo Cygwin root is: %CYG_ROOT%' - - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) -install: - - 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -msys2 -c "pacman --noconfirm -S --needed mingw-w64-$MSYS2_ARCH-{libtool,make,pkg-config,libsystre,doxygen,gnutls,graphviz,curl}"' - - 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -msys2 -c "pacman --noconfirm -S --needed autotools"' - - 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER && curl https://s3.amazonaws.com/libhttpserver/libmicrohttpd_releases/libmicrohttpd-0.9.64.tar.gz -o libmicrohttpd-0.9.64.tar.gz"' - - 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER && tar -xzf libmicrohttpd-0.9.64.tar.gz"' - - 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER/libmicrohttpd-0.9.64 && ./configure --disable-examples --enable-poll=no --prefix /C/msys64 && make && make install"' - - 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER && ./bootstrap"' - - 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER && mkdir build && cd build && MANIFEST_TOOL=no; ../configure --disable-fastopen --prefix /C/msys64 CXXFLAGS=-I/C/msys64/include LDFLAGS=-L/C/msys64/lib; make"' -build_script: - - 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER/build && make check"' - - 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER/build && cat test/test-suite.log"' diff --git a/configure.ac b/configure.ac index 70caca8a..2ddc13b6 100644 --- a/configure.ac +++ b/configure.ac @@ -71,6 +71,16 @@ case "$host" in NETWORK_LIBS="-lws2_32" native_srcdir=$(cd $srcdir; pwd -W) ;; + *-msys*) + AC_MSG_WARN([ +Building from MSYS environment. Binaries will depend on msys-2.0.dll. +For native Windows binaries, use the MinGW64 shell instead. +]) + NETWORK_HEADER="winsock2.h" + ADDITIONAL_LIBS="-lpthread -no-undefined" + NETWORK_LIBS="-lws2_32" + native_srcdir=$(cd $srcdir; pwd -W) + ;; *-cygwin*) NETWORK_HEADER="arpa/inet.h" ADDITIONAL_LIBS="-lpthread -no-undefined" @@ -294,11 +304,13 @@ AC_OUTPUT( AC_MSG_NOTICE([Configuration Summary: Operating System: ${host_os} + Host triplet : ${host} Target directory: ${prefix} License : LGPL only Debug : ${debugit} TLS Enabled : ${have_gnutls} TCP_FASTOPEN : ${is_fastopen_supported} Static : ${static} + Windows build : ${is_windows} Build examples : ${enable_examples} ])