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 #107

Open
zhaixiaojuan opened this issue Oct 16, 2024 · 7 comments
Open

Add loongarch64 support #107

zhaixiaojuan opened this issue Oct 16, 2024 · 7 comments
Assignees

Comments

@zhaixiaojuan
Copy link

LoongArch64 is a RISC style architecture that, like riscv64, is supported by many upstream sources such as kernel, gcc, golang, openjdk, rust, etc. Both Debian and Alpine support LoongArch 64.
Bazel is an open-source software with a wide range of applications. Bazel currently supports many architectures, and I have found that
In 2021, Bazel integrated the MiPS architecture, and in 2023, it integrated the RISC-V architecture. This indicates that Bazel is an open and user-friendly ecosystem software, which deeply moved me.
We sincerely hope that the Loongarch64 architecture can also be integrated into Bazel, but we are currently unsure of the specific conditions that need to be met. We look forward to your guidance and response.

@zunley
Copy link
Contributor

zunley commented Oct 16, 2024

Yes, I encountered this problem on alpine, I believe debian will also encounter this problem, bazel support is very important.
Debian Ports/loong64
Alpine Ports/loongarch64

#106
bazelbuild/bazel#23965

@katre katre self-assigned this Oct 16, 2024
@katre
Copy link
Member

katre commented Oct 16, 2024

Please clarify the problems you are having: what projects are you building, and what is not working on loongarch64.

Specifically (and as stated in bazelbuild/bazel#23965 (comment) and #106 (comment)), what builds are failing, and why is it not sufficient to add the new constraint_value and cc_toolchain to your own project?

@zunley
Copy link
Contributor

zunley commented Oct 16, 2024

@katre You are right. I encountered a series of problems when building envoy on loongarch64, but I solved them one by one through local modifications, it is a bit complicated.

For exemple, when I built envoy-1.26.8,I first built a bazel-6.3.2 because I originally only had a 4.3.2 version, which was too old.
(1) I first added loongarch64 support to bazel, the content is the same as bazelbuild/bazel#23965
(2) Then I changed the download location of platforms because upstream platforms does not support loongarch64.

      "platforms": {
          "archive": "platforms-0.0.5.tar.gz",
 -        "sha256": "379113459b0feaf6bfbb584a91874c065078aa673222846ac765f86661c27407",
 +        "sha256": "cc18d9ae5f2190f5288c37d6a4689b79ccb071efa93b56abc2d7904fbe156f2b",
          "urls": [
 -            "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz",
 -            "https://github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz",
 +           "https://github.com/Loongson-Cloud-Community/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz",
          ],

(3) Finally, I added support for loongarch64 to the bazel jdk toolchain, which I noticed was removed in the latest version.

diff --git a/tools/jdk/BUILD.tools b/tools/jdk/BUILD.tools
index 92b83e5..857ef6a 100755
--- a/tools/jdk/BUILD.tools
+++ b/tools/jdk/BUILD.tools
@@ -95,6 +95,7 @@ cc_library(
         "//src/conditions:linux_mips64": [":jni_md_header-linux"],
         "//src/conditions:linux_riscv64": [":jni_md_header-linux"],
         "//src/conditions:linux_x86_64": [":jni_md_header-linux"],
+        "//src/conditions:linux_loongarch64": [":jni_md_header-linux"],
         "//src/conditions:darwin": [":jni_md_header-darwin"],
         "//src/conditions:freebsd": [":jni_md_header-freebsd"],
         "//src/conditions:openbsd": [":jni_md_header-openbsd"],
@@ -108,6 +109,7 @@ cc_library(
         "//src/conditions:linux_mips64": ["include/linux"],
         "//src/conditions:linux_riscv64": ["include/linux"],
         "//src/conditions:linux_x86_64": ["include/linux"],
+        "//src/conditions:linux_loongarch64": ["include/linux"],
         "//src/conditions:darwin": ["include/darwin"],
         "//src/conditions:freebsd": ["include/freebsd"],
         "//src/conditions:openbsd": ["include/openbsd"],

So far I have successfully built bazel 6.3.2 that can run on loongarch64. Next, build envoy.

(4) As you said, I need to add loongarch64 support in envoy-1.26.8

diff --git a/bazel/BUILD b/bazel/BUILD
index 6883d5d..e8b21b9 100644
--- a/bazel/BUILD
+++ b/bazel/BUILD
@@ -552,6 +552,11 @@ config_setting(
     values = {"cpu": "s390x"},
 )

+config_setting(
+    name = "linux_loongarch64",
+    values = {"cpu": "loongarch64"},
+)
+
 config_setting(
     name = "linux_mips64",
     values = {"cpu": "mips64"},
@@ -722,6 +727,7 @@ selects.config_setting_group(
         ":linux_ppc",
         ":linux_s390x",
         ":linux_x86_64",
+        ":linux_loongarch64",
     ],
 )

@@ -749,6 +755,7 @@ selects.config_setting_group(
         ":linux_mips64",
         ":linux_ppc",
         ":linux_s390x",
+        ":linux_loongarch64",
     ],
 )

(5) Since envoy is a golang project, I also need to add loongarch64 support to rules_go. I manually replaced the rules_go in the bazel cache, the content same as bazel-contrib/rules_go#4142

Then successfully built envoy-1.26.5.

I would like to say that similar projects include tensorflow, kubevirt, etc., which will bring difficulties to users who use bazel on loongarch64. I am looking forward to bazel upstream adding support for loongarch64. This will be a very exciting thing, which will play a decisive role in the upstream support of rules_go, envoy, tensflow, etc.

@zhaixiaojuan
Copy link
Author

@katre
Hi katre, if you have any questions, please feel free to contact us. We are very much looking forward to your guidance and support.

@katre
Copy link
Member

katre commented Oct 18, 2024

The Configurability team is currently traveling back from BazelCon, so we'll discuss this next week. Thanks!

@zhaixiaojuan
Copy link
Author

On debian upstream we are also promoting bazel's support for loongarch64 architecture.
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1057456

@zhaixiaojuan
Copy link
Author

@katre
Hi katre, is there any latest progress on this PR?

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

No branches or pull requests

3 participants