Skip to content

Commit

Permalink
Add initial risc-v support (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw authored Feb 13, 2023
1 parent f1042b9 commit cc79e09
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/vcpkg/base/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ namespace vcpkg
ForceSystemBinariesOnWeirdPlatforms,
(),
"",
"Environment variable VCPKG_FORCE_SYSTEM_BINARIES must be set on arm, s390x, and ppc64le platforms.");
"Environment variable VCPKG_FORCE_SYSTEM_BINARIES must be set on arm, s390x, ppc64le and riscv platforms.");
DECLARE_MESSAGE(FormattedParseMessageExpression,
(msg::value),
"Example of {value} is 'x64 & windows'",
Expand Down
2 changes: 2 additions & 0 deletions include/vcpkg/base/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace vcpkg
ARM64EC,
S390X,
PPC64LE,
RISCV32,
RISCV64,
};

Optional<CPUArchitecture> to_cpu_architecture(StringView arch);
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ int main(const int argc, const char* const* const argv)

register_console_ctrl_handler();

#if (defined(__aarch64__) || defined(__arm__) || defined(__s390x__) || \
#if (defined(__aarch64__) || defined(__arm__) || defined(__s390x__) || defined(__riscv) || \
((defined(__ppc64__) || defined(__PPC64__) || defined(__ppc64le__) || defined(__PPC64LE__)) && \
defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || \
defined(_M_ARM) || defined(_M_ARM64)) && \
Expand Down
9 changes: 9 additions & 0 deletions src/vcpkg/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ namespace vcpkg
if (Strings::case_insensitive_ascii_equals(arch, "arm64ec")) return CPUArchitecture::ARM64EC;
if (Strings::case_insensitive_ascii_equals(arch, "s390x")) return CPUArchitecture::S390X;
if (Strings::case_insensitive_ascii_equals(arch, "ppc64le")) return CPUArchitecture::PPC64LE;
if (Strings::case_insensitive_ascii_equals(arch, "riscv32")) return CPUArchitecture::RISCV32;
if (Strings::case_insensitive_ascii_equals(arch, "riscv64")) return CPUArchitecture::RISCV64;

return nullopt;
}

Expand All @@ -56,6 +59,8 @@ namespace vcpkg
case CPUArchitecture::ARM64EC: return "arm64ec";
case CPUArchitecture::S390X: return "s390x";
case CPUArchitecture::PPC64LE: return "ppc64le";
case CPUArchitecture::RISCV32: return "riscv32";
case CPUArchitecture::RISCV64: return "riscv64";
default: Checks::exit_with_message(VCPKG_LINE_INFO, "unexpected vcpkg::CPUArchitecture");
}
}
Expand Down Expand Up @@ -149,6 +154,10 @@ namespace vcpkg
#elif (defined(__ppc64__) || defined(__PPC64__) || defined(__ppc64le__) || defined(__PPC64LE__)) && \
defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
return CPUArchitecture::PPC64LE;
#elif defined(__riscv) && defined(__riscv_xlen) && (__riscv_xlen == 32)
return CPUArchitecture::RISCV32;
#elif defined(__riscv) && defined(__riscv_xlen) && (__riscv_xlen == 64)
return CPUArchitecture::RISCV64;
#else // choose architecture
#error "Unknown host architecture"
#endif // choose architecture
Expand Down
8 changes: 8 additions & 0 deletions src/vcpkg/triplet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ namespace vcpkg
{
return CPUArchitecture::PPC64LE;
}
if (Strings::starts_with(this->canonical_name(), "riscv32-"))
{
return CPUArchitecture::RISCV32;
}
if (Strings::starts_with(this->canonical_name(), "riscv64-"))
{
return CPUArchitecture::RISCV64;
}

return nullopt;
}
Expand Down

0 comments on commit cc79e09

Please sign in to comment.