Skip to content

Commit a1f005c

Browse files
authored
windows support (#8)
1 parent 8fb4105 commit a1f005c

File tree

10 files changed

+154
-30
lines changed

10 files changed

+154
-30
lines changed

.github/workflows/xtracfg.yml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ jobs:
1111
- runner: ubuntu-24.04
1212
type: linux
1313
platform: linux-amd64
14-
- runner: ubuntu-24.04-arm #buildjet-2vcpu-ubuntu-2204-arm
14+
- runner: ubuntu-24.04-arm
1515
type: linux
1616
platform: linux-arm64
1717
- runner: macos-14
1818
type: macos
1919
platform: darwin-arm64
20-
#- runner: windows-2022
21-
# type: windows
22-
# platform: windows-amd64
20+
- runner: windows-2022
21+
type: windows
22+
platform: windows-amd64
2323
steps:
2424
- uses: actions/checkout@v4
2525
- uses: actions/setup-node@v4
@@ -38,6 +38,10 @@ jobs:
3838
#cache-dependency-path: |
3939
# xtracfg/*.gradle*
4040
# xtracfg/**/gradle-wrapper.properties
41+
- uses: egor-tensin/vs-shell@v2
42+
if: ${{ matrix.os.type == 'windows' }}
43+
with:
44+
arch: x64
4145
- name: zlib
4246
if: ${{ matrix.os.type == 'linux' }}
4347
working-directory: /tmp
@@ -54,15 +58,24 @@ jobs:
5458
working-directory: ./libxtracfg/java
5559
run: |
5660
./gradlew nativeCompile -PLIB=true
61+
- name: log0
62+
run: |
63+
cat ./libxtracfg/java/build/native/nativeCompile/logs/compiler_commands.txt
5764
- name: log1
5865
run: |
5966
ls -l ./libxtracfg/c/build
60-
# TODO: windows
6167
- name: c
68+
if: ${{ matrix.os.type != 'windows' }}
6269
working-directory: ./libxtracfg/c
6370
run: |
6471
./build.sh
6572
./test.sh
73+
- name: c
74+
if: ${{ matrix.os.type == 'windows' }}
75+
working-directory: ./libxtracfg/c
76+
run: |
77+
./build.bat
78+
./test.bat
6679
- name: log2
6780
run: |
6881
ls -l ./libxtracfg/c/build
@@ -74,13 +87,22 @@ jobs:
7487
npm --loglevel verbose run test
7588
- name: log3
7689
run: |
77-
ls -lR ./libxtracfg/js/xtracfg-native-binding/prebuilds
90+
ls -R ./libxtracfg/js/xtracfg-native-binding/prebuilds
7891
# TODO: run tests for java, c, go
7992
- uses: actions/upload-artifact@v4
93+
if: ${{ matrix.os.type != 'windows' }}
8094
with:
8195
name: libxtracfg-c-${{ matrix.os.platform }}
8296
path: ./libxtracfg/c/build/libxtracfg.a
8397
retention-days: 1
98+
- uses: actions/upload-artifact@v4
99+
if: ${{ matrix.os.type == 'windows' }}
100+
with:
101+
name: libxtracfg-c-${{ matrix.os.platform }}
102+
path: |
103+
./libxtracfg/c/build/libxtracfg.lib
104+
./libxtracfg/c/build/libxtracfgjni_static_ext.lib
105+
retention-days: 1
84106
- uses: actions/upload-artifact@v4
85107
with:
86108
name: libxtracfg-c-hash-${{ matrix.os.platform }}
@@ -101,7 +123,7 @@ jobs:
101123
- runner: ubuntu-24.04
102124
type: linux
103125
platform: linux-amd64
104-
- runner: ubuntu-24.04-arm #buildjet-2vcpu-ubuntu-2204-arm
126+
- runner: ubuntu-24.04-arm
105127
type: linux
106128
platform: linux-arm64
107129
- runner: macos-14
@@ -113,6 +135,7 @@ jobs:
113135
defaults:
114136
run:
115137
working-directory: ./xtracfg
138+
shell: bash
116139
steps:
117140
- uses: actions/checkout@v4
118141
- uses: actions/setup-go@v5
@@ -137,7 +160,7 @@ jobs:
137160
CMD_GIT_BRANCH: github.com/interactive-instruments/xtraplatform-cli/xtracfg/cmd.gitBranch=${{ github.ref_name }}
138161
CMD_GIT_SHA: github.com/interactive-instruments/xtraplatform-cli/xtracfg/cmd.gitSha=${{ steps.short-sha.outputs.substring }}
139162
CMD_GIT_TAG: github.com/interactive-instruments/xtraplatform-cli/xtracfg/cmd.gitTag=${{ github.ref_type == 'tag' && github.ref_name || '' }}
140-
EXT_LDFLAGS: ${{ matrix.os.type == 'macos' && '-framework CoreServices -framework Foundation' || '-z noexecstack' }}
163+
EXT_LDFLAGS: ${{ (matrix.os.type == 'macos' && '-framework CoreServices -framework Foundation') || (matrix.os.type == 'linux' && '-z noexecstack') || '' }}
141164
run: |
142165
go build -o build/xtracfg -ldflags="-s -w -X ${CMD_GIT_TAG} -X ${CMD_GIT_SHA} -X ${CMD_GIT_BRANCH} '-extldflags=${EXT_LDFLAGS}'"
143166
- name: log1

libxtracfg/c/build.bat

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@echo off
2+
REM Windows batch file conversion of build.sh
3+
4+
SET OUT_DIR=build
5+
SET PLATFORM=win32
6+
SET EXT=lib
7+
8+
if not exist %OUT_DIR% mkdir %OUT_DIR%
9+
10+
cd %OUT_DIR%
11+
12+
echo lib
13+
14+
REM static
15+
cl.exe /c /MD /W4 /I./ /I%JAVA_HOME%/include /I%JAVA_HOME%/include/%PLATFORM% /Folibxtracfg.obj ../wrapper/libxtracfg.c
16+
lib.exe /OUT:libxtracfg.lib /VERBOSE libxtracfg.obj libxtracfgjni_static.lib
17+
18+
certutil -hashfile libxtracfg.lib SHA1 > libxtracfg.sha1sum.tmp
19+
REM Extract just the hash from certutil output (it includes headers/footers)
20+
findstr /v "SHA1 CertUtil" libxtracfg.sha1sum.tmp > libxtracfg.sha1sum
21+
del libxtracfg.sha1sum.tmp
22+
copy libxtracfg.sha1sum ..\..\go\xtracfg\
23+
24+
echo test
25+
ls -l
26+
27+
REM static
28+
cl.exe /MD /I./ /Fetest.exe ^
29+
../test/main.c ^
30+
libxtracfg.lib ^
31+
libxtracfgjni_static_ext.lib ^
32+
/link ^
33+
/NODEFAULTLIB:LIBCMT ^
34+
/FILEALIGN:4096 ^
35+
/LIBPATH:./ ^
36+
/WHOLEARCHIVE:libxtracfg.lib
37+
38+
ls -l
39+
40+
cd ..

libxtracfg/c/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ echo "lib"
2121
clang -c -Wall -fPIC -I./ -I$JAVA_HOME/include -I$JAVA_HOME/include/${PLATFORM} -o libxtracfg.o ../wrapper/libxtracfg.c
2222
cp libxtracfgjni.a libxtracfg.a
2323
ar -rv libxtracfg.a libxtracfg.o
24+
2425
if [ "$PLATFORM" = "darwin" ]; then
2526
shasum libxtracfg.a > libxtracfg.sha1sum
2627
else

libxtracfg/c/native-image/static-compiler-windows.bat

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ REM in a local temp directory and does not specify the output path anywhere. Tes
88
REM GraalVM jdk21.+35.1 on Windows 10 and may need to be modified for other versions.
99
REM
1010
REM Use with --native-compiler-path=${pathToThisScript}.bat
11-
set OUTPUT_PATH=%~dp0\..\..\target\image
11+
set OUTPUT_PATH=%~dp0\..\..\java\build\native\nativeCompile
1212

1313
REM Determine the library name based on the .dll argument. ~nP returns the filename
1414
REM without quotes, i.e., "path\myLibrary.dll" returns myLibrary
@@ -20,36 +20,62 @@ for %%P in (%*) do (
2020
)
2121
)
2222

23-
REM Do a simple forward for any calls that are used to compile individual C files
24-
IF "%LIB_NAME%"=="" (
25-
cmd /c cl %*
26-
exit /b
27-
)
28-
2923
REM Setup log path and log file
3024
set LOG_PATH=%OUTPUT_PATH%\logs
3125
set LOG_FILE=%LOG_PATH%\compiler_commands.txt
3226
if not exist %LOG_PATH% mkdir %LOG_PATH%
3327

34-
echo Working directory: %CD% > %LOG_FILE%
28+
REM Do a simple forward for any calls that are used to compile individual C files
29+
IF "%LIB_NAME%"=="" (
30+
echo Forwarding to cl.exe for compiling C file: %* >> %LOG_FILE%
31+
cmd /c cl.exe %*
32+
exit /b
33+
)
34+
35+
echo Working directory: %CD% >> %LOG_FILE%
3536
echo Output path: %OUTPUT_PATH% >> %LOG_FILE%
3637
echo Library name: %LIB_NAME% >> %LOG_FILE%
38+
echo Java home: %JAVA_HOME% >> %LOG_FILE%
3739

3840
echo ===================================================== >> %LOG_FILE%
3941
echo SHARED LIBRARY >> %LOG_FILE%
4042
echo ===================================================== >> %LOG_FILE%
4143
REM Modify the arguments if needed
4244
set CL_ARGS=%*
45+
REM set "CL_ARGS=%CL_ARGS:/MD /LD=/MT%"
46+
REM set "CL_ARGS=%CL_ARGS:/NODEFAULTLIB:LIBCMT=%"
4347
echo cl.exe %CL_ARGS% >> %LOG_FILE%
4448
cmd /c cl.exe %CL_ARGS%
4549

50+
echo ===================================================== >> %LOG_FILE%
51+
echo STATIC EXTERNAL >> %LOG_FILE%
52+
echo ===================================================== >> %LOG_FILE%
53+
set LIBS_EXT=
54+
for %%P in (%*) do (
55+
echo %%P >> %LOG_FILE%
56+
echo %%P | findstr /R /C:"^[^/].*\.lib" 1>nul
57+
if !errorlevel!==0 (
58+
echo *** >> %LOG_FILE%
59+
echo !LIBS_EXT! | findstr /C:"%%P" >nul
60+
if !errorlevel!==1 (
61+
set "LIBS_EXT=!LIBS_EXT! %%P"
62+
)
63+
)
64+
65+
)
66+
REM set "LIBS_EXT=!LIBS_EXT:svm\clibraries\windows-amd64\jvm.lib=jvm.lib!"
67+
echo !LIBS_EXT! >> %LOG_FILE%
68+
4669
echo ===================================================== >> %LOG_FILE%
4770
echo STATIC LIBRARY >> %LOG_FILE%
4871
echo ===================================================== >> %LOG_FILE%
4972
REM To create a static library on Windows we need to call lib.exe input.obj /OUT:output.lib
5073
REM We don't want to overwrite the .lib needed to compile against the .dll, so
5174
REM we append "_s" to indicate that it is a static library.
5275
if not exist %OUTPUT_PATH% mkdir %OUTPUT_PATH%
53-
set LIB_ARGS=%LIB_NAME%.obj /OUT:%OUTPUT_PATH%\%LIB_NAME%_s.lib
76+
set LIB_ARGS=%LIB_NAME%.obj /OUT:%OUTPUT_PATH%\%LIB_NAME%_static.lib
77+
echo lib.exe %LIB_ARGS% >> %LOG_FILE%
78+
cmd /c lib.exe %LIB_ARGS%
79+
set LIB_ARGS=!LIBS_EXT! /OUT:%OUTPUT_PATH%\%LIB_NAME%_static_ext.lib
5480
echo lib.exe %LIB_ARGS% >> %LOG_FILE%
5581
cmd /c lib.exe %LIB_ARGS%

libxtracfg/c/test.bat

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
REM @echo off
2+
3+
set DIR=%~dp0
4+
set DIR=%DIR:~0,-1%
5+
set DIR=D:\\a\\xtraplatform-cli\\xtraplatform-cli\\libxtracfg\\c
6+
7+
cd build
8+
9+
cmd.exe /c test.exe "{\"command\": \"info\", \"source\": \"%DIR%\", \"debug\": \"true\", \"verbose\": \"true\"}"
10+
11+
ldd test.exe

libxtracfg/c/test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33
DIR=$(dirname "$(readlink -f "$0")")
44

5+
ls -l ./build
6+
ldd ./build/test
7+
58
./build/test "{\"command\": \"info\", \"source\": \"$DIR\", \"debug\": \"true\", \"verbose\": \"true\"}"

libxtracfg/c/wrapper/libxtracfg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ JNIEXPORT void JNICALL Java_de_ii_xtraplatform_cli_Cli_00024NativeProgress_updat
2020

2121
int xtracfg_init() {
2222
JavaVMInitArgs vm_args;
23-
JavaVMOption options[0];
23+
JavaVMOption options[1];
2424
vm_args.version = JNI_VERSION_10;
2525
vm_args.nOptions = 0;
2626
vm_args.options = options;

libxtracfg/go/xtracfg/client.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package xtracfg
33
/*
44
#cgo CFLAGS: -I ../../c/include
55
#cgo LDFLAGS: -L../../c/build -lxtracfg
6+
#cgo windows LDFLAGS: -lxtracfgjni_static_ext
67
78
#include <stdlib.h>
89
#include "libxtracfg.h"
@@ -129,17 +130,15 @@ func (store Store) Handle(parameters map[string]interface{}, command string, sub
129130
return nil, fmt.Errorf("Error: %s", *response.Error)
130131
}
131132

132-
133133
if response.Results == nil {
134134
return []Result{}, nil
135135
}
136136

137-
138137
for i := range *response.Results {
139-
(*response.Results)[i].Details = response.Details
140-
}
138+
(*response.Results)[i].Details = response.Details
139+
}
141140

142-
return *response.Results, nil
141+
return *response.Results, nil
143142
}
144143

145144
func (store Store) request(parameters map[string]interface{}, command string, subcommands ...string) (response *Response, err error) {
@@ -149,10 +148,8 @@ func (store Store) request(parameters map[string]interface{}, command string, su
149148
parameters["subcommand"] = subcommands[0]
150149
}
151150

152-
153151
request, err := json.Marshal(parameters)
154152

155-
156153
if err != nil {
157154
return nil, fmt.Errorf("Error: Failed to marshal the request body. %s", err)
158155
}

libxtracfg/js/xtracfg-native-binding/binding.gyp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{
44
'target_name': 'xtracfg-native',
55
'sources': [ 'src/xtracfg_lib.cc' ],
6-
'libraries': [ '<(local_prefix)/../c/build/libxtracfg.a' ],
76
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")", "<(local_prefix)/../c/include"],
87
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
98
'cflags': ['-fPIC'],
@@ -17,8 +16,28 @@
1716
"OTHER_CFLAGS": [ "-fPIC"]
1817
},
1918
'msvs_settings': {
20-
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
21-
}
19+
'VCCLCompilerTool': {
20+
'RuntimeLibrary': 2, # /MD
21+
'ExceptionHandling': 1,
22+
'AdditionalOptions': [
23+
'/MD',
24+
'/EHsc',
25+
],
26+
},
27+
'VCLinkerTool': {
28+
'IgnoreDefaultLibraryNames': [ 'LIBCMT' ],
29+
'AdditionalOptions': [
30+
'/WHOLEARCHIVE:<(local_prefix)/../c/build/libxtracfg.lib',
31+
],
32+
},
33+
},
34+
'conditions': [
35+
['OS=="win"', {
36+
'libraries': [ '<(local_prefix)/../c/build/libxtracfg.lib', '<(local_prefix)/../c/build/libxtracfgjni_static_ext.lib' ]
37+
}, { # OS != "win"
38+
'libraries': [ '<(local_prefix)/../c/build/libxtracfg.a' ]
39+
}],
40+
]
2241
}
2342
]
2443
}

libxtracfg/js/xtracfg-native-binding/test/test_binding.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
const xtracfgLib = require("../index.js");
2+
const currentDir = __dirname;
23

34
function testBasic() {
4-
const command =
5-
'{"command": "info", "source": "/Users/az/development/configs-ldproxy/demogh", "verbose": "true", "debug": "true"}';
5+
console.log("Testing basic execute...", currentDir);
6+
const command = `{"command": "info", "source": "${currentDir.replaceAll(
7+
"\\",
8+
"/"
9+
)}", "verbose": "true", "debug": "true"}`;
610

711
const result = xtracfgLib.execute(command);
812

0 commit comments

Comments
 (0)