Skip to content

修复了macos arm64版本可能导致的lwjgl natives匹配错误#5990

Open
yaalyy wants to merge 4 commits intoHMCL-dev:mainfrom
yaalyy:main
Open

修复了macos arm64版本可能导致的lwjgl natives匹配错误#5990
yaalyy wants to merge 4 commits intoHMCL-dev:mainfrom
yaalyy:main

Conversation

@yaalyy
Copy link
Copy Markdown

@yaalyy yaalyy commented Apr 23, 2026

问题描述:

在macos arm64版本下,导入整合包时,某些Forge/MultiMC导出的manifests会使用LWJGL natives的已经legacy的classifier,如natives-macos。而由于HMCL会将1.19+版本的arm64自动跳过patch, 所以该classifier会继续保持,从而导致下载的LWJGL与系统版本不匹配并路径错误导致找不到。

修复方式

对于legacy的classifier做了检测,已经legacy的classifier会做patch

@yaalyy yaalyy marked this pull request as ready for review April 23, 2026 02:28
@Glavo
Copy link
Copy Markdown
Member

Glavo commented Apr 23, 2026

/gemini reivew

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the native library patching mechanism to support ARM64 architectures on macOS and Windows, particularly for legacy LWJGL versions. It introduces a hasLegacyLwjglNatives check and a fallback replacement strategy using library classifiers. Additionally, several LWJGL 3.3.1 native mappings for macOS ARM64 were added to the configuration. Feedback was provided regarding redundant logging in the library replacement logic that could lead to duplicate output.

Comment thread HMCL/src/main/java/org/jackhuang/hmcl/util/NativePatcher.java
@burningtnt
Copy link
Copy Markdown
Member

把 LWJGL 直接提升到这么高的版本真的能保持兼容性吗?

@yaalyy
Copy link
Copy Markdown
Author

yaalyy commented Apr 23, 2026

把 LWJGL 直接提升到这么高的版本真的能保持兼容性吗?

native.json 新增的LWJGL映射是从文件本身已有的映射复制而来,3.3.1. 并没有拉高版本

本次修改并没有对当前版本的native patcher触发做过大修改,因为在arm64环境下,遇到没有系统架构标识的legacy classifier, 原逻辑会默认当做x86处理,所以这次修改仅为arm64环境下新增了legacy classifier的检测,且只对macos arm64做了特别处理。在classifier不是legacy的情况下, 1.19+版本仍会按照原逻辑执行。

@Glavo
Copy link
Copy Markdown
Member

Glavo commented Apr 23, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19b341eeba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

for (Library lib : version.getLibraries()) {
if (!lib.appliesToCurrentEnvironment()) continue;
if (!"org.lwjgl".equals(lib.getGroupId())) continue;
if (!lib.isNative()) continue;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Treat classifier-only LWJGL entries as legacy natives

hasLegacyLwjglNatives filters with lib.isNative(), but Library.isNative() only returns true when natives or downloads.classifiers is present; a MultiMC/Forge-style library declared as "name": "org.lwjgl:...:natives-macos" (classifier in coordinate only) is treated as non-native and skipped here. In that case this method returns false, the early return at patchNative stays active for macOS/Windows ARM64 1.19+, and the legacy natives-macos mapping you added is never applied.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

通过multiMC程序打包的整合包, 在经过HMCL导入后,目前可见的legacy classifier仅遇到过downloads.classifiers的形式,未遇见过"name": "org.lwjgl:...:natives-macos"的形式,因此该特例认为可以暂时忽略

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

示例json:
{ "name": "org.lwjgl:lwjgl-glfw:3.3.1", "downloads": { "artifact": { "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl-glfw/3.3.1/lwjgl-glfw-3.3.1.jar", "sha1": "cbac1b8d30cb4795149c1ef540f912671a8616d0", "size": 128801 }, "classifiers": { "natives-linux": { "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl-glfw/3.3.1/lwjgl-glfw-3.3.1-natives-linux.jar", "sha1": "81716978214ecbda15050ca394b06ef61501a49e", "size": 119817 }, "natives-macos": { "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl-glfw/3.3.1/lwjgl-glfw-3.3.1-natives-macos.jar", "sha1": "9ec4ce1fc8c85fdef03ef4ff2aace6f5775fb280", "size": 131655 }, "natives-windows": { "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl-glfw/3.3.1/lwjgl-glfw-3.3.1-natives-windows.jar", "sha1": "ed892f945cf7e79c8756796f32d00fa4ceaf573b", "size": 145512 } } }, "natives": { "linux": "natives-linux", "osx": "natives-macos", "windows": "natives-windows" } },

@burningtnt
Copy link
Copy Markdown
Member

burningtnt commented Apr 24, 2026

部分 MMC 整合包中用的 LWJGL 很老,这个 PR 不解决问题。

例如,https://github.com/search?q=repo%3AMultiMC%2Fmeta-multimc%20-nightly&type=code 这里能看到一些 Minecraft 1.6~1.18.2 版本正在使用 2.9.4-nightly-20150209 版本的 LWJGL。这些版本不能被正确替换本地库,但 HMCL 声称兼容这些版本。

image

@yaalyy
Copy link
Copy Markdown
Author

yaalyy commented Apr 24, 2026

部分 MMC 整合包中用的 LWJGL 很老,这个 PR 不解决问题。

例如,https://github.com/search?q=repo%3AMultiMC%2Fmeta-multimc%20-nightly&type=code 这里能看到一些 Minecraft 1.6~1.18.2 版本正在使用 2.9.4-nightly-20150209 版本的 LWJGL。这些版本不能被正确替换本地库,但 HMCL 声称兼容这些版本。

image

你提到的老LWJGL替换问题确实存在,但这个PR的目标不是修复该问题。
该PR没有修改1.19版本以下的LWJGL库替换逻辑。1.19版本以下不会走我的代码

不好意思,可能没有表达清楚,这个PR针对修复的是,1.19版本以上的macos arm64环境,导入multiMC打包的整合包时可能会遇到的LWGJL替换bug。

举个例子,导入multiMC打的整合包后,可能会使用legacy classifier, natives-macos,这个classifier是没有标识arm64的,而当前HMCL的处理逻辑是,对于1.19版本以上直接跳过LWGJL patch,而因为这种旧classifier 没有标识架构版本,所以HMCL会默认去下载x86的LWGJL, 所下载的架构版本是错误的。

因此这个PR主要是增加了1.19版本以上,对于arm64环境下 这类legacy classifier的额外检测,并将错误的x86源替换为arm64源。当运行环境是arm64, 又检测到了legacy classifier, 会主动去patch 成arm64版本

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants