From 365c5a502a91c7656e6d8b2e1b5e8615f478e261 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Fri, 15 Nov 2024 15:50:39 +0100 Subject: [PATCH] add config for local Microsoft cl compiling --- .gitignore | 70 ++++++++ Makefile | 14 +- README.md | 11 +- integrations-win.sln | 31 ++++ integrations-win.vcxproj | 165 ++++++++++++++++++ ...dows_keychain_WinDataProtection_Native.cpp | 1 + ...ndows_uiappearnce_WinAppearance_Native.cpp | 10 +- 7 files changed, 292 insertions(+), 10 deletions(-) create mode 100644 integrations-win.sln create mode 100644 integrations-win.vcxproj diff --git a/.gitignore b/.gitignore index f74150f..359ee37 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,73 @@ pom.xml.versionsBackup .idea/compiler.xml .idea/jarRepositories.xml *.iml + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +# but not Directory.Build.rsp, as it configures directory-level build defaults +!Directory.Build.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# exclude compile outputs not used by projects +*.exp +*.lib \ No newline at end of file diff --git a/Makefile b/Makefile index 09525fb..e94d9fe 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,10 @@ -HEADERS := -I"src/main/headers" -I"${JAVA_HOME}\include" -I"${JAVA_HOME}\include\win32" +WIN_SDK_VERSION ?= 10.0.22621.0 +MSVC_VERSION ?= 14.41.34120 +HEADERS := /I"src/main/headers" \ + /I"${JAVA_HOME}\include" \ + /I"${JAVA_HOME}\include\win32" \ + /I"C:\Program Files (x86)\Windows Kits\10\Include\$(WIN_SDK_VERSION)\cppwinrt" \ + /I"C:\Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/$(MSVC_VERSION)/include" SOURCES := $(wildcard src/main/native/*.cpp) ######## @@ -6,4 +12,8 @@ SOURCES := $(wildcard src/main/native/*.cpp) all: install install: - g++ -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at $(HEADERS) -shared -osrc/main/resources/integrations.dll $(SOURCES) -lcrypt32 -lshell32 -lole32 -luuid \ No newline at end of file + cl /EHsc /std:c++17 /LD /W4 /guard:cf \ + /Fe:src/main/resources/integrations.dll \ + $(HEADERS) $(SOURCES) \ + /link /NXCOMPAT /DYNAMICBASE \ + crypt32.lib shell32.lib ole32.lib uuid.lib user32.lib windowsapp.lib \ No newline at end of file diff --git a/README.md b/README.md index 5bd462d..f7eed0e 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,14 @@ This project uses the following JVM properties: ## Building -This project uses JNI, hence you'll nedd Java as well as GCC build tools: +### Requirements * JDK 22 * Maven -* MinGW GCC compiler (`choco install mingw --version=10.2.0`) -* Make (`choco install make`) \ No newline at end of file +* MSVC 2022 toolchain (Visual Studio 2022, Workset "Desktop development with C++") + +### Build +Start the _Developer PowerShell for Visual Studio 2022_ and run the following commands: +```pwsh +mvn clean verify +``` \ No newline at end of file diff --git a/integrations-win.sln b/integrations-win.sln new file mode 100644 index 0000000..2e4e468 --- /dev/null +++ b/integrations-win.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35327.3 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "integrations-win", "integrations-win.vcxproj", "{CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Debug|x64.ActiveCfg = Debug|x64 + {CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Debug|x64.Build.0 = Debug|x64 + {CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Debug|x86.ActiveCfg = Debug|Win32 + {CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Debug|x86.Build.0 = Debug|Win32 + {CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Release|x64.ActiveCfg = Release|x64 + {CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Release|x64.Build.0 = Release|x64 + {CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Release|x86.ActiveCfg = Release|Win32 + {CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DCEB853F-9857-4F7D-A508-A7390F37BC50} + EndGlobalSection +EndGlobal diff --git a/integrations-win.vcxproj b/integrations-win.vcxproj new file mode 100644 index 0000000..6314732 --- /dev/null +++ b/integrations-win.vcxproj @@ -0,0 +1,165 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {cf96ace0-9471-4bd6-ad0e-be32af14c358} + integrationswin + 10.0.22621.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(ProjectDir)src\main\headers;$(JAVA_HOME)include;$(JAVA_HOME)include\win32;$(IncludePath) + $(SolutionDir)target\native\$(Platform)\$(Configuration)\ + integrations + + + + Level3 + true + WIN32;_DEBUG;INTEGRATIONSWIN_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + + + + + Level3 + true + true + true + WIN32;NDEBUG;INTEGRATIONSWIN_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + + + + + Level3 + true + _DEBUG;INTEGRATIONSWIN_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + NotUsing + + + stdcpp17 + + + Windows + true + false + %(ForceSymbolReferences) + crypt32.lib;shell32.lib;ole32.lib;uuid.lib;user32.lib;windowsapp.lib + + + + + Level3 + true + true + true + NDEBUG;INTEGRATIONSWIN_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/native/org_cryptomator_windows_keychain_WinDataProtection_Native.cpp b/src/main/native/org_cryptomator_windows_keychain_WinDataProtection_Native.cpp index 51d4966..2f5256b 100644 --- a/src/main/native/org_cryptomator_windows_keychain_WinDataProtection_Native.cpp +++ b/src/main/native/org_cryptomator_windows_keychain_WinDataProtection_Native.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "org_cryptomator_windows_keychain_WinDataProtection_Native.h" JNIEXPORT jbyteArray JNICALL Java_org_cryptomator_windows_keychain_WinDataProtection_00024Native_protect(JNIEnv *env, jobject thisObj, jbyteArray cleartext, jbyteArray salt) { diff --git a/src/main/native/org_cryptomator_windows_uiappearnce_WinAppearance_Native.cpp b/src/main/native/org_cryptomator_windows_uiappearnce_WinAppearance_Native.cpp index 9ae99ba..ae7d9b5 100644 --- a/src/main/native/org_cryptomator_windows_uiappearnce_WinAppearance_Native.cpp +++ b/src/main/native/org_cryptomator_windows_uiappearnce_WinAppearance_Native.cpp @@ -17,10 +17,10 @@ void throwIllegalStateException(JNIEnv *env, const char* message) { JNIEXPORT jint JNICALL Java_org_cryptomator_windows_uiappearance_WinAppearance_00024Native_getCurrentTheme (JNIEnv *env, jobject thisObject){ DWORD data{}; DWORD dataSize = sizeof(data); - LSTATUS status = RegGetValue(HKEY_CURRENT_USER, R"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)", "AppsUseLightTheme", RRF_RT_DWORD, NULL, &data, &dataSize); + LSTATUS status = RegGetValueW(HKEY_CURRENT_USER, L"(Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize)", L"AppsUseLightTheme", RRF_RT_DWORD, NULL, &data, &dataSize); if(status != ERROR_SUCCESS){ char msg[50]; - sprintf(msg, "Failed to read registry value (status %d)", (int) status); + sprintf_s(msg, 50, "Failed to read registry value (status %d)", (int) status); throwIllegalStateException(env, msg); } return data ? 1 : 0; @@ -28,16 +28,16 @@ JNIEXPORT jint JNICALL Java_org_cryptomator_windows_uiappearance_WinAppearance_0 JNIEXPORT void JNICALL Java_org_cryptomator_windows_uiappearance_WinAppearance_00024Native_waitForNextThemeChange(JNIEnv *env, jobject thisObj){ HKEY key; - LSTATUS status = RegOpenKeyEx(HKEY_CURRENT_USER, R"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)", 0, KEY_READ, &key); + LSTATUS status = RegOpenKeyExW(HKEY_CURRENT_USER, L"(Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize)", 0, KEY_READ, &key); if (status != ERROR_SUCCESS) { char msg[50]; - sprintf(msg, "Failed to open registry key (status %d)", (int) status); + sprintf_s(msg, 50,"Failed to open registry key (status %d)", (int) status); throwIllegalStateException(env, msg); } status = RegNotifyChangeKeyValue(key, TRUE, REG_NOTIFY_CHANGE_LAST_SET, NULL, FALSE); if (status != ERROR_SUCCESS) { char msg[50]; - sprintf(msg, "Failed to observe registry key (status %d)", (int) status); + sprintf_s(msg, 50, "Failed to observe registry key (status %d)", (int) status); throwIllegalStateException(env, msg); } RegCloseKey(key);