Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loongarch64 support for Linux/*BSD #97822

Merged
merged 2 commits into from
Dec 5, 2024
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
3 changes: 3 additions & 0 deletions core/config/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ String Engine::get_architecture_name() const {
return "ppc";
#endif

#elif defined(__loongarch64)
return "loongarch64";
Copy link
Member

Choose a reason for hiding this comment

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

https://loongson.github.io/LoongArch-Documentation/LoongArch-toolchain-conventions-EN.html

According to this page, __loongarch64 is a more specific check than __loongarch__, which we can check for to return "loongarch64", and otherwise fall back to a more generic bitless name (like the rv64 code above), ensuring that in case somebody tries to compile on an 32-bit or 128-bit version of the architecture then Godot doesn't still claim to be the 64-bit version (or it can just not compile in those cases).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decide only do more specific check without fallback to generic name. there is no 32-bit LoongArch desktop CPU yet. I think it's better to notify future developers we didn't actually test it by explicitly only support 64-bit LoongArch CPU.


#elif defined(__wasm__)
#if defined(__wasm64__)
return "wasm64";
Expand Down
4 changes: 4 additions & 0 deletions core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ bool OS::has_feature(const String &p_feature) {
if (p_feature == "wasm") {
return true;
}
#elif defined(__loongarch64)
if (p_feature == "loongarch64") {
return true;
}
#endif

#if defined(IOS_SIMULATOR)
Expand Down
1 change: 1 addition & 0 deletions editor/editor_property_name_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
capitalize_string_remaps["linuxbsd"] = "Linux/*BSD";
capitalize_string_remaps["lod"] = "LOD";
capitalize_string_remaps["lods"] = "LODs";
capitalize_string_remaps["loongarch64"] = "loongarch64";
akien-mga marked this conversation as resolved.
Show resolved Hide resolved
capitalize_string_remaps["lowpass"] = "Low-pass";
capitalize_string_remaps["macos"] = "macOS";
capitalize_string_remaps["mb"] = "(MB)"; // Unit.
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/gdextension_export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void GDExtensionExportPlugin::_export_file(const String &p_path, const String &p
all_archs.insert("ppc32");
all_archs.insert("ppc64");
all_archs.insert("wasm32");
all_archs.insert("loongarch64");
all_archs.insert("universal");

HashSet<String> archs;
Expand Down
2 changes: 1 addition & 1 deletion platform/linuxbsd/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_flags():

def configure(env: "SConsEnvironment"):
# Validate arch.
supported_arches = ["x86_32", "x86_64", "arm32", "arm64", "rv64", "ppc32", "ppc64"]
supported_arches = ["x86_32", "x86_64", "arm32", "arm64", "rv64", "ppc32", "ppc64", "loongarch64"]
validate_arch(env["arch"], get_name(), supported_arches)

## Build type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<members>
<member name="binary_format/architecture" type="String" setter="" getter="">
Application executable architecture.
Supported architectures: [code]x86_32[/code], [code]x86_64[/code], [code]arm64[/code], [code]arm32[/code], [code]rv64[/code], [code]ppc64[/code], and [code]ppc32[/code].
Supported architectures: [code]x86_32[/code], [code]x86_64[/code], [code]arm64[/code], [code]arm32[/code], [code]rv64[/code], [code]ppc64[/code], [code]ppc32[/code], and [code]loongarch64[/code].
Official export templates include [code]x86_32[/code] and [code]x86_64[/code] binaries only.
</member>
<member name="binary_format/embed_pck" type="bool" setter="" getter="">
Expand Down
4 changes: 3 additions & 1 deletion platform/linuxbsd/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ bool EditorExportPlatformLinuxBSD::get_export_option_visibility(const EditorExpo
void EditorExportPlatformLinuxBSD::get_export_options(List<ExportOption> *r_options) const {
EditorExportPlatformPC::get_export_options(r_options);

r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "binary_format/architecture", PROPERTY_HINT_ENUM, "x86_64,x86_32,arm64,arm32,rv64,ppc64,ppc32"), "x86_64"));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "binary_format/architecture", PROPERTY_HINT_ENUM, "x86_64,x86_32,arm64,arm32,rv64,ppc64,ppc32,loongarch64"), "x86_64"));

String run_script = "#!/usr/bin/env bash\n"
"export DISPLAY=:0\n"
Expand Down Expand Up @@ -282,6 +282,8 @@ String EditorExportPlatformLinuxBSD::_get_exe_arch(const String &p_path) const {
return "arm64";
case 0x00f3:
return "rv64";
case 0x0102:
return "loongarch64";
default:
return "unknown";
}
Expand Down
2 changes: 1 addition & 1 deletion platform/linuxbsd/os_linuxbsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ String OS_LinuxBSD::get_processor_name() const {

while (!f->eof_reached()) {
const String line = f->get_line();
if (line.contains("model name")) {
if (line.to_lower().contains("model name")) {
return line.split(":")[1].strip_edges();
}
}
Expand Down
3 changes: 2 additions & 1 deletion platform_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

# CPU architecture options.
architectures = ["x86_32", "x86_64", "arm32", "arm64", "rv64", "ppc32", "ppc64", "wasm32"]
architectures = ["x86_32", "x86_64", "arm32", "arm64", "rv64", "ppc32", "ppc64", "wasm32", "loongarch64"]
architecture_aliases = {
"x86": "x86_32",
"x64": "x86_64",
Expand All @@ -31,6 +31,7 @@
"ppcle": "ppc32",
"ppc": "ppc32",
"ppc64le": "ppc64",
"loong64": "loongarch64",
}


Expand Down