diff --git a/.github/workflows/xtracfg.yml b/.github/workflows/xtracfg.yml index 6e112a6..6a11866 100644 --- a/.github/workflows/xtracfg.yml +++ b/.github/workflows/xtracfg.yml @@ -11,15 +11,15 @@ jobs: - runner: ubuntu-24.04 type: linux platform: linux-amd64 - - runner: ubuntu-24.04-arm #buildjet-2vcpu-ubuntu-2204-arm + - runner: ubuntu-24.04-arm type: linux platform: linux-arm64 - runner: macos-14 type: macos platform: darwin-arm64 - #- runner: windows-2022 - # type: windows - # platform: windows-amd64 + - runner: windows-2022 + type: windows + platform: windows-amd64 steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -38,6 +38,10 @@ jobs: #cache-dependency-path: | # xtracfg/*.gradle* # xtracfg/**/gradle-wrapper.properties + - uses: egor-tensin/vs-shell@v2 + if: ${{ matrix.os.type == 'windows' }} + with: + arch: x64 - name: zlib if: ${{ matrix.os.type == 'linux' }} working-directory: /tmp @@ -54,15 +58,24 @@ jobs: working-directory: ./libxtracfg/java run: | ./gradlew nativeCompile -PLIB=true + - name: log0 + run: | + cat ./libxtracfg/java/build/native/nativeCompile/logs/compiler_commands.txt - name: log1 run: | ls -l ./libxtracfg/c/build - # TODO: windows - name: c + if: ${{ matrix.os.type != 'windows' }} working-directory: ./libxtracfg/c run: | ./build.sh ./test.sh + - name: c + if: ${{ matrix.os.type == 'windows' }} + working-directory: ./libxtracfg/c + run: | + ./build.bat + ./test.bat - name: log2 run: | ls -l ./libxtracfg/c/build @@ -74,13 +87,22 @@ jobs: npm --loglevel verbose run test - name: log3 run: | - ls -lR ./libxtracfg/js/xtracfg-native-binding/prebuilds + ls -R ./libxtracfg/js/xtracfg-native-binding/prebuilds # TODO: run tests for java, c, go - uses: actions/upload-artifact@v4 + if: ${{ matrix.os.type != 'windows' }} with: name: libxtracfg-c-${{ matrix.os.platform }} path: ./libxtracfg/c/build/libxtracfg.a retention-days: 1 + - uses: actions/upload-artifact@v4 + if: ${{ matrix.os.type == 'windows' }} + with: + name: libxtracfg-c-${{ matrix.os.platform }} + path: | + ./libxtracfg/c/build/libxtracfg.lib + ./libxtracfg/c/build/libxtracfgjni_static_ext.lib + retention-days: 1 - uses: actions/upload-artifact@v4 with: name: libxtracfg-c-hash-${{ matrix.os.platform }} @@ -101,7 +123,7 @@ jobs: - runner: ubuntu-24.04 type: linux platform: linux-amd64 - - runner: ubuntu-24.04-arm #buildjet-2vcpu-ubuntu-2204-arm + - runner: ubuntu-24.04-arm type: linux platform: linux-arm64 - runner: macos-14 @@ -113,6 +135,7 @@ jobs: defaults: run: working-directory: ./xtracfg + shell: bash steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 @@ -137,7 +160,7 @@ jobs: CMD_GIT_BRANCH: github.com/interactive-instruments/xtraplatform-cli/xtracfg/cmd.gitBranch=${{ github.ref_name }} CMD_GIT_SHA: github.com/interactive-instruments/xtraplatform-cli/xtracfg/cmd.gitSha=${{ steps.short-sha.outputs.substring }} CMD_GIT_TAG: github.com/interactive-instruments/xtraplatform-cli/xtracfg/cmd.gitTag=${{ github.ref_type == 'tag' && github.ref_name || '' }} - EXT_LDFLAGS: ${{ matrix.os.type == 'macos' && '-framework CoreServices -framework Foundation' || '-z noexecstack' }} + EXT_LDFLAGS: ${{ (matrix.os.type == 'macos' && '-framework CoreServices -framework Foundation') || (matrix.os.type == 'linux' && '-z noexecstack') || '' }} run: | go build -o build/xtracfg -ldflags="-s -w -X ${CMD_GIT_TAG} -X ${CMD_GIT_SHA} -X ${CMD_GIT_BRANCH} '-extldflags=${EXT_LDFLAGS}'" - name: log1 diff --git a/libxtracfg/c/build.bat b/libxtracfg/c/build.bat new file mode 100644 index 0000000..548abb1 --- /dev/null +++ b/libxtracfg/c/build.bat @@ -0,0 +1,40 @@ +@echo off +REM Windows batch file conversion of build.sh + +SET OUT_DIR=build +SET PLATFORM=win32 +SET EXT=lib + +if not exist %OUT_DIR% mkdir %OUT_DIR% + +cd %OUT_DIR% + +echo lib + +REM static +cl.exe /c /MD /W4 /I./ /I%JAVA_HOME%/include /I%JAVA_HOME%/include/%PLATFORM% /Folibxtracfg.obj ../wrapper/libxtracfg.c +lib.exe /OUT:libxtracfg.lib /VERBOSE libxtracfg.obj libxtracfgjni_static.lib + +certutil -hashfile libxtracfg.lib SHA1 > libxtracfg.sha1sum.tmp +REM Extract just the hash from certutil output (it includes headers/footers) +findstr /v "SHA1 CertUtil" libxtracfg.sha1sum.tmp > libxtracfg.sha1sum +del libxtracfg.sha1sum.tmp +copy libxtracfg.sha1sum ..\..\go\xtracfg\ + +echo test +ls -l + +REM static +cl.exe /MD /I./ /Fetest.exe ^ + ../test/main.c ^ + libxtracfg.lib ^ + libxtracfgjni_static_ext.lib ^ + /link ^ + /NODEFAULTLIB:LIBCMT ^ + /FILEALIGN:4096 ^ + /LIBPATH:./ ^ + /WHOLEARCHIVE:libxtracfg.lib + +ls -l + +cd .. diff --git a/libxtracfg/c/build.sh b/libxtracfg/c/build.sh index a568cf5..3e4d41e 100755 --- a/libxtracfg/c/build.sh +++ b/libxtracfg/c/build.sh @@ -21,6 +21,7 @@ echo "lib" clang -c -Wall -fPIC -I./ -I$JAVA_HOME/include -I$JAVA_HOME/include/${PLATFORM} -o libxtracfg.o ../wrapper/libxtracfg.c cp libxtracfgjni.a libxtracfg.a ar -rv libxtracfg.a libxtracfg.o + if [ "$PLATFORM" = "darwin" ]; then shasum libxtracfg.a > libxtracfg.sha1sum else diff --git a/libxtracfg/c/native-image/static-compiler-windows.bat b/libxtracfg/c/native-image/static-compiler-windows.bat index f434a3c..c78c074 100755 --- a/libxtracfg/c/native-image/static-compiler-windows.bat +++ b/libxtracfg/c/native-image/static-compiler-windows.bat @@ -8,7 +8,7 @@ REM in a local temp directory and does not specify the output path anywhere. Tes REM GraalVM jdk21.+35.1 on Windows 10 and may need to be modified for other versions. REM REM Use with --native-compiler-path=${pathToThisScript}.bat -set OUTPUT_PATH=%~dp0\..\..\target\image +set OUTPUT_PATH=%~dp0\..\..\java\build\native\nativeCompile REM Determine the library name based on the .dll argument. ~nP returns the filename REM without quotes, i.e., "path\myLibrary.dll" returns myLibrary @@ -20,29 +20,52 @@ for %%P in (%*) do ( ) ) -REM Do a simple forward for any calls that are used to compile individual C files -IF "%LIB_NAME%"=="" ( - cmd /c cl %* - exit /b -) - REM Setup log path and log file set LOG_PATH=%OUTPUT_PATH%\logs set LOG_FILE=%LOG_PATH%\compiler_commands.txt if not exist %LOG_PATH% mkdir %LOG_PATH% -echo Working directory: %CD% > %LOG_FILE% +REM Do a simple forward for any calls that are used to compile individual C files +IF "%LIB_NAME%"=="" ( + echo Forwarding to cl.exe for compiling C file: %* >> %LOG_FILE% + cmd /c cl.exe %* + exit /b +) + +echo Working directory: %CD% >> %LOG_FILE% echo Output path: %OUTPUT_PATH% >> %LOG_FILE% echo Library name: %LIB_NAME% >> %LOG_FILE% +echo Java home: %JAVA_HOME% >> %LOG_FILE% echo ===================================================== >> %LOG_FILE% echo SHARED LIBRARY >> %LOG_FILE% echo ===================================================== >> %LOG_FILE% REM Modify the arguments if needed set CL_ARGS=%* +REM set "CL_ARGS=%CL_ARGS:/MD /LD=/MT%" +REM set "CL_ARGS=%CL_ARGS:/NODEFAULTLIB:LIBCMT=%" echo cl.exe %CL_ARGS% >> %LOG_FILE% cmd /c cl.exe %CL_ARGS% +echo ===================================================== >> %LOG_FILE% +echo STATIC EXTERNAL >> %LOG_FILE% +echo ===================================================== >> %LOG_FILE% +set LIBS_EXT= +for %%P in (%*) do ( + echo %%P >> %LOG_FILE% + echo %%P | findstr /R /C:"^[^/].*\.lib" 1>nul + if !errorlevel!==0 ( + echo *** >> %LOG_FILE% + echo !LIBS_EXT! | findstr /C:"%%P" >nul + if !errorlevel!==1 ( + set "LIBS_EXT=!LIBS_EXT! %%P" + ) + ) + +) +REM set "LIBS_EXT=!LIBS_EXT:svm\clibraries\windows-amd64\jvm.lib=jvm.lib!" +echo !LIBS_EXT! >> %LOG_FILE% + echo ===================================================== >> %LOG_FILE% echo STATIC LIBRARY >> %LOG_FILE% echo ===================================================== >> %LOG_FILE% @@ -50,6 +73,9 @@ REM To create a static library on Windows we need to call lib.exe input.obj /OUT REM We don't want to overwrite the .lib needed to compile against the .dll, so REM we append "_s" to indicate that it is a static library. if not exist %OUTPUT_PATH% mkdir %OUTPUT_PATH% -set LIB_ARGS=%LIB_NAME%.obj /OUT:%OUTPUT_PATH%\%LIB_NAME%_s.lib +set LIB_ARGS=%LIB_NAME%.obj /OUT:%OUTPUT_PATH%\%LIB_NAME%_static.lib +echo lib.exe %LIB_ARGS% >> %LOG_FILE% +cmd /c lib.exe %LIB_ARGS% +set LIB_ARGS=!LIBS_EXT! /OUT:%OUTPUT_PATH%\%LIB_NAME%_static_ext.lib echo lib.exe %LIB_ARGS% >> %LOG_FILE% cmd /c lib.exe %LIB_ARGS% diff --git a/libxtracfg/c/test.bat b/libxtracfg/c/test.bat new file mode 100644 index 0000000..f9e3474 --- /dev/null +++ b/libxtracfg/c/test.bat @@ -0,0 +1,11 @@ +REM @echo off + +set DIR=%~dp0 +set DIR=%DIR:~0,-1% +set DIR=D:\\a\\xtraplatform-cli\\xtraplatform-cli\\libxtracfg\\c + +cd build + +cmd.exe /c test.exe "{\"command\": \"info\", \"source\": \"%DIR%\", \"debug\": \"true\", \"verbose\": \"true\"}" + +ldd test.exe diff --git a/libxtracfg/c/test.sh b/libxtracfg/c/test.sh index 2f0a63b..00f6113 100755 --- a/libxtracfg/c/test.sh +++ b/libxtracfg/c/test.sh @@ -2,4 +2,7 @@ DIR=$(dirname "$(readlink -f "$0")") +ls -l ./build +ldd ./build/test + ./build/test "{\"command\": \"info\", \"source\": \"$DIR\", \"debug\": \"true\", \"verbose\": \"true\"}" diff --git a/libxtracfg/c/wrapper/libxtracfg.c b/libxtracfg/c/wrapper/libxtracfg.c index 13329d3..d8dc980 100644 --- a/libxtracfg/c/wrapper/libxtracfg.c +++ b/libxtracfg/c/wrapper/libxtracfg.c @@ -20,7 +20,7 @@ JNIEXPORT void JNICALL Java_de_ii_xtraplatform_cli_Cli_00024NativeProgress_updat int xtracfg_init() { JavaVMInitArgs vm_args; - JavaVMOption options[0]; + JavaVMOption options[1]; vm_args.version = JNI_VERSION_10; vm_args.nOptions = 0; vm_args.options = options; diff --git a/libxtracfg/go/xtracfg/client.go b/libxtracfg/go/xtracfg/client.go index 0bf27ed..0fde199 100644 --- a/libxtracfg/go/xtracfg/client.go +++ b/libxtracfg/go/xtracfg/client.go @@ -3,6 +3,7 @@ package xtracfg /* #cgo CFLAGS: -I ../../c/include #cgo LDFLAGS: -L../../c/build -lxtracfg +#cgo windows LDFLAGS: -lxtracfgjni_static_ext #include #include "libxtracfg.h" @@ -129,17 +130,15 @@ func (store Store) Handle(parameters map[string]interface{}, command string, sub return nil, fmt.Errorf("Error: %s", *response.Error) } - if response.Results == nil { return []Result{}, nil } - for i := range *response.Results { - (*response.Results)[i].Details = response.Details - } + (*response.Results)[i].Details = response.Details + } - return *response.Results, nil + return *response.Results, nil } 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 parameters["subcommand"] = subcommands[0] } - request, err := json.Marshal(parameters) - if err != nil { return nil, fmt.Errorf("Error: Failed to marshal the request body. %s", err) } diff --git a/libxtracfg/js/xtracfg-native-binding/binding.gyp b/libxtracfg/js/xtracfg-native-binding/binding.gyp index 6041b03..b202856 100644 --- a/libxtracfg/js/xtracfg-native-binding/binding.gyp +++ b/libxtracfg/js/xtracfg-native-binding/binding.gyp @@ -3,7 +3,6 @@ { 'target_name': 'xtracfg-native', 'sources': [ 'src/xtracfg_lib.cc' ], - 'libraries': [ '<(local_prefix)/../c/build/libxtracfg.a' ], 'include_dirs': ["