Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
# Note: make apparently thinks, that options specified with "/" are absolute paths and resolves them. see also https://stackoverflow.com/questions/17012419/d9024-make-unrecognized-source-file-type
ARCH ?= x64
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"
SOURCES := $(wildcard src/main/native/*.cpp)
OUT_DIR := target/$(ARCH)
OUT_DLL := src/main/resources/integrations-$(ARCH).dll
OUT_LIB := $(OUT_DIR)/integrations.lib

########

all: install

install:
ifeq "$(wildcard $(OUT_DIR))" ""
mkdir "$(OUT_DIR)"
endif
cl -EHsc -std:c++17 -LD -W4 -guard:cf \
-Fe"src/main/resources/integrations.dll" \
-Fo"target/" \
-Fe"$(OUT_DLL)" \
-Fo"$(OUT_DIR)/" \
$(HEADERS) $(SOURCES) \
-link -NXCOMPAT -DYNAMICBASE \
-implib:target/integrations.lib \
-implib:$(OUT_LIB) \
crypt32.lib shell32.lib ole32.lib uuid.lib user32.lib Advapi32.lib windowsapp.lib
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This project uses the following JVM properties:

* JDK 22
* Maven
* MSVC 2022 toolset (e.g. by installing Visual Studio 2022, Workset "Desktop development with C++")
* MSVC 2022 toolset (e.g. by installing Visual Studio 2022, Workset "Desktop development with C++" and component "MSVC v143 VS 2022 C++ ARM64/ARM64EC-Buildtools")
* Make (`choco install make`)

### Build
Expand Down
33 changes: 28 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@
<include>*.h</include>
</includes>
</fileset>
<fileset>
<directory>${project.basedir}/src/main/resources</directory>
<followSymlinks>false</followSymlinks>
<includes>
<include>*.dll</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
Expand Down Expand Up @@ -336,24 +343,40 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<executable>cmd</executable>
<workingDirectory>${project.basedir}</workingDirectory>
<environmentVariables>
<JAVA_HOME>${java.home}</JAVA_HOME>
</environmentVariables>
</configuration>
<executions>
<execution>
<id>compile-x64</id>
<goals>
<goal>exec</goal>
</goals>
<phase>compile</phase>
<configuration>
<executable>cmd</executable>
<workingDirectory>${project.basedir}</workingDirectory>
<environmentVariables>
<JAVA_HOME>${java.home}</JAVA_HOME>
</environmentVariables>
<arguments>
<argument>/c</argument>
<argument>"${devCommandFileDir}\vcvars64.bat" &amp;&amp; make install</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>compile-arm64</id>
<goals>
<goal>exec</goal>
</goals>
<phase>compile</phase>
<configuration>
<arguments>
<argument>/c</argument>
<argument>"${devCommandFileDir}\vcvarsamd64_arm64.bat" &amp;&amp; make install ARCH=arm64</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/org/cryptomator/windows/common/NativeLibLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,42 @@
public class NativeLibLoader {

private static final Logger LOG = LoggerFactory.getLogger(NativeLibLoader.class);
private static final String LIB = "/integrations.dll";
private static final String X64_LIB = "/integrations-x64.dll";
private static final String ARM64_LIB = "/integrations-arm64.dll";
private static volatile boolean loaded = false;

/**
* Attempts to load the .dll file required for native calls.
*
* @throws UnsatisfiedLinkError If loading the library failed.
*/
public static synchronized void loadLib() {
if (!loaded) {
try (var dll = NativeLibLoader.class.getResourceAsStream(LIB)) {
var arch = System.getProperty("os.arch");
final String LIBNAME;
if (arch.contains("amd64")) {
LOG.debug("Loading library for x86_64 architecture");
LIBNAME = X64_LIB;
} else if (arch.contains("aarch64")) {
LOG.debug("Loading library for aarch64 architecture");
LIBNAME = ARM64_LIB;
} else {
LOG.warn("Unrecognized architecture: {}. Defaulting to x86_64 architecture", arch);
LIBNAME = X64_LIB;
}

try (var dll = NativeLibLoader.class.getResourceAsStream(LIBNAME)) {
Objects.requireNonNull(dll);
Path tmpPath = Files.createTempFile("lib", ".dll");
Files.copy(dll, tmpPath, StandardCopyOption.REPLACE_EXISTING);
System.load(tmpPath.toString());
loaded = true;
} catch (NullPointerException e) {
LOG.error("Did not find resource " + LIB, e);
LOG.error("Did not find resource " + LIBNAME, e);
} catch (IOException e) {
LOG.error("Failed to copy " + LIB + " to temp dir.", e);
LOG.error("Failed to copy " + LIBNAME + " to temp dir.", e);
} catch (UnsatisfiedLinkError e) {
LOG.error("Failed to load lib from " + LIB, e);
LOG.error("Failed to load lib from " + LIBNAME, e);
}
}
}
Expand Down