Skip to content

Commit

Permalink
Improve Windows build support (#760)
Browse files Browse the repository at this point in the history
* Improve Windows build support

Added vcpkg.json as package manifest for dependencies.
Changed the build options in CMakeLists.txt by specifying the output
directories to make sure DLLs are copied next to executables for
Windows debugging in an IDE (e.g. Visual Studio or CLion)
Disabled the build of NATS streaming since protobuf-c dependency
doesn't seem to be working properly, and it's deprecated anyway.
Further, updated .gitignore to exclude Visual Studio related files and
the 'out' directory which VS seems to use by default for build output.

* Fix ci

* Windows build workflow

* refer to nonats from the new location

* Revert NATS_BUILD_STREAMING back to ON

* Revert NATS_BUILD_STREAMING back to ON

* Fixed warnings in micro examples

* Moved the Windows job under on-pr-...

* job names that make more sense

* refactoring, may break again

* Revert "refactoring, may break again"

This reverts commit d40de83.

* more names

* Warnings as errors

* Warnings

* removed default run in case it affects the windows build

* turn warnings off for test

---------

Co-authored-by: Lev Brouk <[email protected]>
  • Loading branch information
mtmk and levb authored Jun 21, 2024
1 parent f70adfb commit 1553d4a
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defaults:
jobs:
do:
runs-on: ubuntu-${{ inputs.ubuntu_version }}
name: "ubuntu:${{ inputs.ubuntu_version }} ${{ inputs.compiler }} nats:${{ inputs.server_version }}"
name: "${{ inputs.ubuntu_version }} - nats:${{ inputs.server_version }}"
steps:
- name: Checkout nats.c
uses: actions/checkout@v4
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
- name: "Rebuild the list of tests to match the compile flags"
working-directory: ./build
run: |
./test/testsuite
./bin/testsuite
if [[ $(diff list.txt ../test/list.txt; echo $?) != 0 ]]; then
mv list.txt ../test/list.txt
make rebuild_cache
Expand Down
34 changes: 28 additions & 6 deletions .github/workflows/on-pr-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ on:
permissions:
contents: write # so it can comment

defaults:
run:
shell: bash --noprofile --norc -x -eo pipefail {0}

jobs:
default:
name: "DefaultD"
Ubuntu:
name: "Ubuntu"
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -62,3 +58,29 @@ jobs:
with:
sanitize: thread
server_version: main

Windows:
name: "Windows"
runs-on: windows-latest
steps:
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Checkout nats.c
uses: actions/checkout@v4

- name: Build
env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
run: |
cmake -B build -S . -DCMAKE_C_FLAGS=/W4 -DNATS_BUILD_STREAMING=OFF
cmake --build build --config Debug
- name: Test
run: |
cd build
./bin/Debug/testsuite
2 changes: 1 addition & 1 deletion .github/workflows/on-push-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defaults:

jobs:
quick:
name: "DefaultR"
name: "Ubuntu"
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ test/conf_*

.vscode/
.idea/
.vs/
out/

# Mac
.DS_Store
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ include(FindPackageHandleStandardArgs)
# Uncomment to have the build process verbose
# set(CMAKE_VERBOSE_MAKEFILE TRUE)

# Uncomment to have the executable moved to 'build' instead of their respective 'build/xxx' directories
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
# Set output directories for libraries and executables.
# This is important for Windows builds to have the DLLs in the same directory as the executables.
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# Set a default build type if none was specified
set(default_build_type "Release")
Expand Down
2 changes: 1 addition & 1 deletion buildOnTravis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ if [ $res -ne 0 ]; then
fi

echo "Test app using dynamic library does not crash if no NATS call is made"
test/dylib/nonats
bin/nonats
res=$?
if [ $res -ne 0 ]; then
exit $res
Expand Down
2 changes: 1 addition & 1 deletion examples/micro-arithmetics.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ handle_arithmetics_op(microRequest *req, arithmeticsOP op)
{
microError *err = NULL;
microArgs *args = NULL;
long double a1, a2, result;
long double a1 = 0, a2 = 0, result = 0;
char buf[1024];
int len = 0;

Expand Down
2 changes: 1 addition & 1 deletion examples/micro-func.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ handle_function_op(microRequest *req, functionHandler op)
{
microError *err = NULL;
microArgs *args = NULL;
int n;
int n = 0;
long double result;
char buf[1024];
int len = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/micro-sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static microError *handle_sequence(microRequest *req)
microArgs *args = NULL;
int n = 0;
int i;
const char *function;
const char *function = NULL;
long double initialValue = 1.0;
long double value = 1.0;
long double denominator = 0;
Expand Down
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ if(NOT NATS_BUILD_LIB_STATIC)
return()
endif()

if(MSVC)
set_source_files_properties(test.c PROPERTIES COMPILE_FLAGS "/w")
endif()

# We need this to build the test program
include_directories(${PROJECT_SOURCE_DIR}/src)
if(NATS_BUILD_WITH_TLS)
Expand Down
11 changes: 11 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "nats-c",
"version-string": "1.0.0",
"builtin-baseline": "326d8b43e365352ba3ccadf388d989082fe0f2a6",
"dependencies": [
{
"name": "openssl",
"version>=": "3.3.0"
}
]
}

0 comments on commit 1553d4a

Please sign in to comment.