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 support for the RISC-V architecture #53508

Merged
merged 1 commit into from
Oct 22, 2021
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
9 changes: 9 additions & 0 deletions core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,15 @@ bool OS::has_feature(const String &p_feature) {
if (p_feature == "arm") {
return true;
}
#elif defined(__riscv)
#if __riscv_xlen == 8
if (p_feature == "rv64") {
return true;
}
#endif
if (p_feature == "riscv") {
return true;
}
#endif

if (_check_internal_feature_support(p_feature)) {
Expand Down
5 changes: 3 additions & 2 deletions modules/denoise/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
def can_build(env, platform):
# Thirdparty dependency OpenImage Denoise includes oneDNN library
# which only supports 64-bit architectures.
# and the version we use only supports x86_64.
# It's also only relevant for tools build and desktop platforms,
# as doing lightmap generation and denoising on Android or HTML5
# would be a bit far-fetched.
desktop_platforms = ["linuxbsd", "osx", "windows"]
return env["tools"] and platform in desktop_platforms and env["bits"] == "64" and env["arch"] != "arm64"
supported_arch = env["bits"] == "64" and env["arch"] != "arm64" and not env["arch"].startswith("rv")
Copy link
Contributor

@AaronRecord AaronRecord Oct 7, 2021

Choose a reason for hiding this comment

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

Why isn't this

Suggested change
supported_arch = env["bits"] == "64" and env["arch"] != "arm64" and not env["arch"].startswith("rv")
supported_arch = env["bits"] == "64" and env["arch"] != "arm64" and env["arch"] != "rv64"

?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the future we might want to allow specifying a custom -march string, like "rv64gcv". There's not a lot of use for this at the moment so I didn't bother supporting it in the SConstruct file, but the startswith check is a simple improvement over checking string inequality that will work for that case. Plus it's possible that someone would want to make a 32-bit or 128-bit version, and startswith also works for that case with no downsides.

return env["tools"] and platform in desktop_platforms and supported_arch


def configure(env):
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def can_build(env, platform):
return True
return not env["arch"].startswith("rv")


def configure(env):
Expand Down
2 changes: 2 additions & 0 deletions modules/raycast/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
def can_build(env, platform):
# Depends on Embree library, which only supports x86_64 and aarch64.
if env["arch"].startswith("rv"):
return False

if platform == "android":
return env["android_arch"] in ["arm64v8", "x86_64"]
Expand Down
2 changes: 1 addition & 1 deletion modules/regex/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def can_build(env, platform):
return True
return not env["arch"].startswith("rv")


def configure(env):
Expand Down
2 changes: 2 additions & 0 deletions modules/theora/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
def can_build(env, platform):
if env["arch"].startswith("rv"):
return False
return env.module_check_dependencies("theora", ["ogg", "vorbis"])


Expand Down
7 changes: 7 additions & 0 deletions platform/linuxbsd/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ def configure(env):
if env["bits"] == "default":
env["bits"] = "64" if is64 else "32"

if env["arch"] == "" and platform.machine() == "riscv64":
env["arch"] = "rv64"

if env["arch"] == "rv64":
# G = General-purpose extensions, C = Compression extension (very common).
env.Append(CCFLAGS=["-march=rv64gc"])

## Compiler configuration

if "CXX" in env and "clang" in os.path.basename(env["CXX"]):
Expand Down