DEV Community

Dhiki Indryanto
Dhiki Indryanto

Posted on

Trying Carbon Language on an AArch64 Device

Image Logo on Carbon's GitHub organization

Introduction

I was curious about Carbon Language, an experimental programming language positioned as a potential successor to C++. However, at the time of writing, Carbon only provides nightly releases for x86_64 architecture.

As a user of an AArch64 (ARMv8-A) device, I wanted to try running Carbon on my system. Unfortunately, the default minimum build target for AArch64 is ARMv8.2-A, while my device is still running ARMv8-A. Because of this, I decided to build Carbon Language myself and run it in my environment.

To automate this process, I created a dedicated GitHub repository to provide Carbon Language ARMv8-A builds. You can check it out here:

➡️ gebleksengek/carbon-lang-armv8a-builder

Build Automation Process

To build Carbon Language for AArch64, I created a GitHub Actions workflow similar to the official Carbon build process.

Key points of this automation:

  • Build Schedule: I chose to trigger the build 3 hours after the official nightly release.
    • On average, Carbon Language takes around 2 hours to build on GitHub Actions without caching.
    • This delay ensures that the latest nightly release is available before starting the AArch64 build.
  • Using an ARM-Based Runner:
    • I opted for a native ARM runner to avoid the complexity of cross-compiling from x86_64 to AArch64.

You can find the complete scripts and automation setup in my GitHub repository:

➡️ gebleksengek/carbon-lang-armv8a-builder

Challenges Faced

Building Carbon on an ARMv8-A device was not without challenges. Here are some key issues I encountered:

  1. tcmalloc Compatibility Issues

    • Carbon uses tcmalloc by default when building with "-c opt" (optimized build).
    • My device was not compatible with tcmalloc, so I replaced it with the default malloc from Bazel’s C++ toolchain or the system’s default malloc (CMIIW – Correct Me If I'm Wrong).
  2. Lowering the Minimum ARM Version

    • The default minimum ARM version for Carbon on AArch64 is ARMv8.2-A, while my device only supports ARMv8-A.
    • I modified the build configuration to allow execution on ARMv8-A.

Testing the Built Carbon Toolchain

After successfully building Carbon Language for ARMv8-A, I tested the toolchain by compiling and running Carbon code.

Testing Environment

This is the environment I used to run the Carbon toolchain:

  • Operating System: Android 9 (rooted)
  • CPU Architecture: ARMv8-A
  • Execution Environment: Arch Linux ARM via chroot and termux

The following process is nearly identical to the official Carbon Language GitHub documentation, except that the toolchain download link is adjusted to my ARMv8-A build from gebleksengek/carbon-lang-armv8a-builder.

  • Determine the latest nightly version (from yesterday):
   VERSION="$(date -d yesterday +0.0.0-0.nightly.%Y.%m.%d)"
Enter fullscreen mode Exit fullscreen mode
  • Download the Carbon Language build for ARMv8-A:
   wget https://github.com/gebleksengek/carbon-lang-armv8a-builder/releases/download/v${VERSION}/carbon_toolchain-${VERSION}.tar.gz
Enter fullscreen mode Exit fullscreen mode
  • Extract the toolchain:
   tar -xvf carbon_toolchain-${VERSION}.tar.gz
Enter fullscreen mode Exit fullscreen mode
  • Create a simple Carbon source file:
   echo "import Core library \"io\"; fn Run() { Core.Print(42); }" > forty_two.carbon
Enter fullscreen mode Exit fullscreen mode
  • Compile the Carbon file to an object file:
   ./carbon_toolchain-${VERSION}/bin/carbon compile \
     --output=forty_two.o forty_two.carbon
Enter fullscreen mode Exit fullscreen mode
  • Install minimal system dependencies required for linking:
   # Usually already installed if using GCC or G++
Enter fullscreen mode Exit fullscreen mode
  • Link the object file to create an executable:
   ./carbon_toolchain-${VERSION}/bin/carbon link \
     --output=forty_two forty_two.o
Enter fullscreen mode Exit fullscreen mode
  • Run the compiled program:
   ./forty_two
Enter fullscreen mode Exit fullscreen mode

If successful, the program should output 42.

Results and Takeaways

With this build, I was able to compile and link Carbon Language code directly on my ARMv8-A device. This demonstrates that, while not officially supported, Carbon can run on ARMv8-A with a few adjustments.

Next Steps

Regarding this project, I plan to discontinue it once Carbon Language provides an official nightly release for AArch64. However, if the official release only supports AArch64 ARMv8.2-A and above, leaving ARMv8-A unsupported, then I will continue maintaining this project.

If you’d like to try it yourself or support this effort, please consider starring ⭐ the GitHub repository:

➡️ gebleksengek/carbon-lang-armv8a-builder


Conclusion

This experiment proves that, with some modifications, Carbon Language can run on ARMv8-A devices, even though it is not officially supported. If you're interested in trying something similar, ensure your device and execution environment are compatible with Carbon’s requirements.

I hope that in the near future, Carbon Language will officially support AArch64, eliminating the need for manual builds. Until then, this project will continue bridging the gap.

Don’t forget to check out my GitHub repository and support it with a ⭐ star if you find this project useful:

➡️ gebleksengek/carbon-lang-armv8a-builder

Top comments (0)