diff --git a/build.gradle b/build.gradle index 9a0736cc2..22c83bf13 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,9 @@ import org.apache.tools.zip.ZipEntry import javax.annotation.Nonnull import org.apache.tools.zip.ZipOutputStream +import java.util.function.Function +import java.util.function.Predicate + plugins { id "java" @@ -73,12 +76,23 @@ writeBuildGradlePredefine(rootProject.mcVers, rootProject.mcIndex) rootProject.versionStr = rootProject.mod_version + "-" + rootProject.minecraft_version // + "-" + new Date().format("yyyy_MM_dd_HH_mm") class NativeTransformer implements Transformer { + private Predicate fileMatcher + private Function filePathMapper + private final HashMap replacements = new HashMap() private final HashMap rewrittenFiles = new HashMap() private var nativeRelocator public File rootDir + void matchFiles(Predicate matcher) { + fileMatcher = matcher + } + + void mapPaths(Function mapper) { + filePathMapper = mapper + } + void relocateNative(String target, String replacement) { if (replacement.length() > target.length()) { throw new GradleException("Length of value \"${replacement}\" exceeds the length of \"${target}\": ${replacement.length()} > ${target.length()}") @@ -89,9 +103,7 @@ class NativeTransformer implements Transformer { @Override boolean canTransformResource(@Nonnull FileTreeElement element) { - return replacements.keySet().stream().anyMatch { - element.name.startsWith(it as String) - } + return fileMatcher.test(element.name) } @Override @@ -103,11 +115,9 @@ class NativeTransformer implements Transformer { } try { - Map.Entry pathReplacement = replacements.entrySet().stream().filter { - context.path.startsWith(it.key as String) - }.findFirst().orElseThrow() - - String path = context.path.replace(pathReplacement.key as String, pathReplacement.value as String) + String path = filePathMapper != null + ? filePathMapper.apply(context.path) + : context.path content = nativeRelocator.processBinary(path, content, replacements) rewrittenFiles.put(path, content) @@ -351,9 +361,33 @@ subprojects { p -> transform(NativeTransformer) { rootDir = project.rootDir + + matchFiles { it.startsWith("org/sqlite") } + mapPaths { it.replace("org/sqlite", "dh_sqlite") } + relocateNative "org/sqlite", "dh_sqlite" relocateNative "org_sqlite", "dh_1sqlite" } + + // ZStd + // librariesLocation isn't used because it's too long for replacing paths in native libraries + // Allowing strings larger than the original string would require shifting the entire binary's contents + relocate "com.github.luben", "dhcomgithubluben", { + exclude "aix.ppc64/**" + exclude "darwin/**" + exclude "freebsd/**" + exclude "linux/**" + exclude "win/**" + } + + transform(NativeTransformer) { + rootDir = project.rootDir + + matchFiles { it.contains("libzstd-jni") && !it.contains("ppc64") } + + relocateNative "com/github/luben", "dhcomgithubluben" + relocateNative "com_github_luben", "dhcomgithubluben" + } // JOML diff --git a/relocate_natives/cache/darwin/aarch64/libzstd-jni-1.5.7-6.dylib b/relocate_natives/cache/darwin/aarch64/libzstd-jni-1.5.7-6.dylib new file mode 100644 index 000000000..3b2c7943a Binary files /dev/null and b/relocate_natives/cache/darwin/aarch64/libzstd-jni-1.5.7-6.dylib differ diff --git a/relocate_natives/cache/darwin/x86_64/libzstd-jni-1.5.7-6.dylib b/relocate_natives/cache/darwin/x86_64/libzstd-jni-1.5.7-6.dylib new file mode 100644 index 000000000..0e69fbbd0 Binary files /dev/null and b/relocate_natives/cache/darwin/x86_64/libzstd-jni-1.5.7-6.dylib differ diff --git a/relocate_natives/cache/freebsd/amd64/libzstd-jni-1.5.7-6.so b/relocate_natives/cache/freebsd/amd64/libzstd-jni-1.5.7-6.so new file mode 100644 index 000000000..f0771bfec Binary files /dev/null and b/relocate_natives/cache/freebsd/amd64/libzstd-jni-1.5.7-6.so differ diff --git a/relocate_natives/cache/freebsd/i386/libzstd-jni-1.5.7-6.so b/relocate_natives/cache/freebsd/i386/libzstd-jni-1.5.7-6.so new file mode 100644 index 000000000..1d8979276 Binary files /dev/null and b/relocate_natives/cache/freebsd/i386/libzstd-jni-1.5.7-6.so differ diff --git a/relocate_natives/cache/linux/aarch64/libzstd-jni-1.5.7-6.so b/relocate_natives/cache/linux/aarch64/libzstd-jni-1.5.7-6.so new file mode 100644 index 000000000..9bcdb7047 Binary files /dev/null and b/relocate_natives/cache/linux/aarch64/libzstd-jni-1.5.7-6.so differ diff --git a/relocate_natives/cache/linux/amd64/libzstd-jni-1.5.7-6.so b/relocate_natives/cache/linux/amd64/libzstd-jni-1.5.7-6.so new file mode 100644 index 000000000..60b9917f1 Binary files /dev/null and b/relocate_natives/cache/linux/amd64/libzstd-jni-1.5.7-6.so differ diff --git a/relocate_natives/cache/linux/arm/libzstd-jni-1.5.7-6.so b/relocate_natives/cache/linux/arm/libzstd-jni-1.5.7-6.so new file mode 100644 index 000000000..535fe4e65 Binary files /dev/null and b/relocate_natives/cache/linux/arm/libzstd-jni-1.5.7-6.so differ diff --git a/relocate_natives/cache/linux/i386/libzstd-jni-1.5.7-6.so b/relocate_natives/cache/linux/i386/libzstd-jni-1.5.7-6.so new file mode 100644 index 000000000..1f5862559 Binary files /dev/null and b/relocate_natives/cache/linux/i386/libzstd-jni-1.5.7-6.so differ diff --git a/relocate_natives/cache/linux/loongarch64/libzstd-jni-1.5.7-6.so b/relocate_natives/cache/linux/loongarch64/libzstd-jni-1.5.7-6.so new file mode 100644 index 000000000..adf8ba177 Binary files /dev/null and b/relocate_natives/cache/linux/loongarch64/libzstd-jni-1.5.7-6.so differ diff --git a/relocate_natives/cache/linux/mips64/libzstd-jni-1.5.7-6.so b/relocate_natives/cache/linux/mips64/libzstd-jni-1.5.7-6.so new file mode 100644 index 000000000..8b210d96b Binary files /dev/null and b/relocate_natives/cache/linux/mips64/libzstd-jni-1.5.7-6.so differ diff --git a/relocate_natives/cache/linux/ppc64/libzstd-jni-1.5.7-6.so b/relocate_natives/cache/linux/ppc64/libzstd-jni-1.5.7-6.so new file mode 100644 index 000000000..edd6ce8e6 Binary files /dev/null and b/relocate_natives/cache/linux/ppc64/libzstd-jni-1.5.7-6.so differ diff --git a/relocate_natives/cache/linux/ppc64le/libzstd-jni-1.5.7-6.so b/relocate_natives/cache/linux/ppc64le/libzstd-jni-1.5.7-6.so new file mode 100644 index 000000000..dcc312ae2 Binary files /dev/null and b/relocate_natives/cache/linux/ppc64le/libzstd-jni-1.5.7-6.so differ diff --git a/relocate_natives/cache/linux/riscv64/libzstd-jni-1.5.7-6.so b/relocate_natives/cache/linux/riscv64/libzstd-jni-1.5.7-6.so new file mode 100644 index 000000000..4813ddaf5 Binary files /dev/null and b/relocate_natives/cache/linux/riscv64/libzstd-jni-1.5.7-6.so differ diff --git a/relocate_natives/cache/linux/s390x/libzstd-jni-1.5.7-6.so b/relocate_natives/cache/linux/s390x/libzstd-jni-1.5.7-6.so new file mode 100644 index 000000000..d8f58c100 Binary files /dev/null and b/relocate_natives/cache/linux/s390x/libzstd-jni-1.5.7-6.so differ diff --git a/relocate_natives/cache/win/aarch64/libzstd-jni-1.5.7-6.dll b/relocate_natives/cache/win/aarch64/libzstd-jni-1.5.7-6.dll new file mode 100644 index 000000000..f2b896e66 Binary files /dev/null and b/relocate_natives/cache/win/aarch64/libzstd-jni-1.5.7-6.dll differ diff --git a/relocate_natives/cache/win/amd64/libzstd-jni-1.5.7-6.dll b/relocate_natives/cache/win/amd64/libzstd-jni-1.5.7-6.dll new file mode 100644 index 000000000..d1a6d90dc Binary files /dev/null and b/relocate_natives/cache/win/amd64/libzstd-jni-1.5.7-6.dll differ diff --git a/relocate_natives/cache/win/x86/libzstd-jni-1.5.7-6.dll b/relocate_natives/cache/win/x86/libzstd-jni-1.5.7-6.dll new file mode 100644 index 000000000..ad672577d Binary files /dev/null and b/relocate_natives/cache/win/x86/libzstd-jni-1.5.7-6.dll differ