Skip to content

Commit 1553d4a

Browse files
mtmklevb
andauthored
Improve Windows build support (nats-io#760)
* 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]>
1 parent f70adfb commit 1553d4a

11 files changed

+57
-15
lines changed

.github/workflows/build-test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ defaults:
5454
jobs:
5555
do:
5656
runs-on: ubuntu-${{ inputs.ubuntu_version }}
57-
name: "ubuntu:${{ inputs.ubuntu_version }} ${{ inputs.compiler }} nats:${{ inputs.server_version }}"
57+
name: "${{ inputs.ubuntu_version }} - nats:${{ inputs.server_version }}"
5858
steps:
5959
- name: Checkout nats.c
6060
uses: actions/checkout@v4
@@ -117,7 +117,7 @@ jobs:
117117
- name: "Rebuild the list of tests to match the compile flags"
118118
working-directory: ./build
119119
run: |
120-
./test/testsuite
120+
./bin/testsuite
121121
if [[ $(diff list.txt ../test/list.txt; echo $?) != 0 ]]; then
122122
mv list.txt ../test/list.txt
123123
make rebuild_cache

.github/workflows/on-pr-debug.yml

+28-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ on:
55
permissions:
66
contents: write # so it can comment
77

8-
defaults:
9-
run:
10-
shell: bash --noprofile --norc -x -eo pipefail {0}
11-
128
jobs:
13-
default:
14-
name: "DefaultD"
9+
Ubuntu:
10+
name: "Ubuntu"
1511
strategy:
1612
fail-fast: false
1713
matrix:
@@ -62,3 +58,29 @@ jobs:
6258
with:
6359
sanitize: thread
6460
server_version: main
61+
62+
Windows:
63+
name: "Windows"
64+
runs-on: windows-latest
65+
steps:
66+
- name: Export GitHub Actions cache environment variables
67+
uses: actions/github-script@v7
68+
with:
69+
script: |
70+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
71+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
72+
73+
- name: Checkout nats.c
74+
uses: actions/checkout@v4
75+
76+
- name: Build
77+
env:
78+
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
79+
run: |
80+
cmake -B build -S . -DCMAKE_C_FLAGS=/W4 -DNATS_BUILD_STREAMING=OFF
81+
cmake --build build --config Debug
82+
83+
- name: Test
84+
run: |
85+
cd build
86+
./bin/Debug/testsuite

.github/workflows/on-push-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defaults:
1111

1212
jobs:
1313
quick:
14-
name: "DefaultR"
14+
name: "Ubuntu"
1515
strategy:
1616
fail-fast: false
1717
matrix:

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ test/conf_*
2626

2727
.vscode/
2828
.idea/
29+
.vs/
30+
out/
2931

3032
# Mac
3133
.DS_Store

CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ include(FindPackageHandleStandardArgs)
77
# Uncomment to have the build process verbose
88
# set(CMAKE_VERBOSE_MAKEFILE TRUE)
99

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

1316
# Set a default build type if none was specified
1417
set(default_build_type "Release")

buildOnTravis.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ if [ $res -ne 0 ]; then
6767
fi
6868

6969
echo "Test app using dynamic library does not crash if no NATS call is made"
70-
test/dylib/nonats
70+
bin/nonats
7171
res=$?
7272
if [ $res -ne 0 ]; then
7373
exit $res

examples/micro-arithmetics.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ handle_arithmetics_op(microRequest *req, arithmeticsOP op)
3333
{
3434
microError *err = NULL;
3535
microArgs *args = NULL;
36-
long double a1, a2, result;
36+
long double a1 = 0, a2 = 0, result = 0;
3737
char buf[1024];
3838
int len = 0;
3939

examples/micro-func.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ handle_function_op(microRequest *req, functionHandler op)
131131
{
132132
microError *err = NULL;
133133
microArgs *args = NULL;
134-
int n;
134+
int n = 0;
135135
long double result;
136136
char buf[1024];
137137
int len = 0;

examples/micro-sequence.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static microError *handle_sequence(microRequest *req)
9494
microArgs *args = NULL;
9595
int n = 0;
9696
int i;
97-
const char *function;
97+
const char *function = NULL;
9898
long double initialValue = 1.0;
9999
long double value = 1.0;
100100
long double denominator = 0;

test/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ if(NOT NATS_BUILD_LIB_STATIC)
77
return()
88
endif()
99

10+
if(MSVC)
11+
set_source_files_properties(test.c PROPERTIES COMPILE_FLAGS "/w")
12+
endif()
13+
1014
# We need this to build the test program
1115
include_directories(${PROJECT_SOURCE_DIR}/src)
1216
if(NATS_BUILD_WITH_TLS)

vcpkg.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "nats-c",
3+
"version-string": "1.0.0",
4+
"builtin-baseline": "326d8b43e365352ba3ccadf388d989082fe0f2a6",
5+
"dependencies": [
6+
{
7+
"name": "openssl",
8+
"version>=": "3.3.0"
9+
}
10+
]
11+
}

0 commit comments

Comments
 (0)