<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dhiki Indryanto</title>
    <description>The latest articles on DEV Community by Dhiki Indryanto (@gebleksengek).</description>
    <link>https://dev.to/gebleksengek</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F505006%2F5f593ac2-d296-4f30-adf3-a717e2cc0098.jpg</url>
      <title>DEV Community: Dhiki Indryanto</title>
      <link>https://dev.to/gebleksengek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gebleksengek"/>
    <language>en</language>
    <item>
      <title>Trying Carbon Language on an AArch64 Device</title>
      <dc:creator>Dhiki Indryanto</dc:creator>
      <pubDate>Wed, 05 Mar 2025 16:34:16 +0000</pubDate>
      <link>https://dev.to/gebleksengek/trying-carbon-language-on-an-aarch64-device-1m2f</link>
      <guid>https://dev.to/gebleksengek/trying-carbon-language-on-an-aarch64-device-1m2f</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fof73ovy7s1sreolm67tx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fof73ovy7s1sreolm67tx.png" alt="Image Logo on Carbon's GitHub organization" width="182" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

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

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

&lt;p&gt;To automate this process, I created a &lt;strong&gt;dedicated GitHub repository&lt;/strong&gt; to provide &lt;strong&gt;Carbon Language ARMv8-A builds&lt;/strong&gt;. You can check it out here:  &lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;&lt;a href="https://github.com/gebleksengek/carbon-lang-armv8a-builder" rel="noopener noreferrer"&gt;gebleksengek/carbon-lang-armv8a-builder&lt;/a&gt;&lt;/strong&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Build Automation Process
&lt;/h2&gt;

&lt;p&gt;To build Carbon Language for AArch64, I created a &lt;strong&gt;GitHub Actions workflow&lt;/strong&gt; similar to the &lt;strong&gt;official Carbon build process&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;Key points of this automation:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Build Schedule&lt;/strong&gt;: I chose to trigger the build &lt;strong&gt;3 hours after the official nightly release&lt;/strong&gt;.

&lt;ul&gt;
&lt;li&gt;On average, &lt;strong&gt;Carbon Language takes around 2 hours&lt;/strong&gt; to build on GitHub Actions without caching.
&lt;/li&gt;
&lt;li&gt;This delay ensures that the latest nightly release is available before starting the AArch64 build.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Using an ARM-Based Runner&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;I opted for a &lt;strong&gt;native ARM runner&lt;/strong&gt; to &lt;strong&gt;avoid the complexity of cross-compiling&lt;/strong&gt; from x86_64 to AArch64.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;You can find the complete scripts and automation setup in my &lt;strong&gt;GitHub repository&lt;/strong&gt;:  &lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;&lt;a href="https://github.com/gebleksengek/carbon-lang-armv8a-builder" rel="noopener noreferrer"&gt;gebleksengek/carbon-lang-armv8a-builder&lt;/a&gt;&lt;/strong&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges Faced
&lt;/h2&gt;

&lt;p&gt;Building Carbon on an ARMv8-A device &lt;strong&gt;was not without challenges&lt;/strong&gt;. Here are some key issues I encountered:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;tcmalloc Compatibility Issues&lt;/strong&gt;  &lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;The default minimum ARM version for Carbon on AArch64 is &lt;strong&gt;ARMv8.2-A&lt;/strong&gt;, while my device only supports &lt;strong&gt;ARMv8-A&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;I modified the build configuration to allow execution on ARMv8-A.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Testing the Built Carbon Toolchain
&lt;/h2&gt;

&lt;p&gt;After successfully building Carbon Language for ARMv8-A, I tested the toolchain by compiling and running Carbon code.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Testing Environment&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This is the environment I used &lt;strong&gt;to run the Carbon toolchain&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Operating System&lt;/strong&gt;: &lt;strong&gt;Android 9 (rooted)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CPU Architecture&lt;/strong&gt;: &lt;strong&gt;ARMv8-A&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Execution Environment&lt;/strong&gt;: &lt;strong&gt;Arch Linux ARM via chroot and termux&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following process is nearly identical to the official &lt;strong&gt;&lt;a href="https://github.com/carbon-language/carbon-lang" rel="noopener noreferrer"&gt;Carbon Language GitHub documentation&lt;/a&gt;&lt;/strong&gt;, except that &lt;strong&gt;the toolchain download link is adjusted to my ARMv8-A build&lt;/strong&gt; from &lt;strong&gt;&lt;a href="https://github.com/gebleksengek/carbon-lang-armv8a-builder" rel="noopener noreferrer"&gt;gebleksengek/carbon-lang-armv8a-builder&lt;/a&gt;&lt;/strong&gt;.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Determine the latest nightly version (from yesterday)&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nv"&gt;VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; yesterday +0.0.0-0.nightly.%Y.%m.%d&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Download the Carbon Language build for ARMv8-A&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   wget https://github.com/gebleksengek/carbon-lang-armv8a-builder/releases/download/v&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/carbon_toolchain-&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Extract the toolchain&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;tar&lt;/span&gt; &lt;span class="nt"&gt;-xvf&lt;/span&gt; carbon_toolchain-&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Create a simple Carbon source file&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"import Core library &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;io&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;; fn Run() { Core.Print(42); }"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; forty_two.carbon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Compile the Carbon file to an object file&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   ./carbon_toolchain-&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/bin/carbon compile &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;--output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;forty_two.o forty_two.carbon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Install minimal system dependencies required for linking&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="c"&gt;# Usually already installed if using GCC or G++&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Link the object file to create an executable&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   ./carbon_toolchain-&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/bin/carbon &lt;span class="nb"&gt;link&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;--output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;forty_two forty_two.o
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Run the compiled program&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   ./forty_two
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If successful, the program should output &lt;strong&gt;42&lt;/strong&gt;.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Results and Takeaways
&lt;/h2&gt;

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

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

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

&lt;p&gt;If you’d like to try it yourself or support this effort, &lt;strong&gt;please consider starring ⭐ the GitHub repository&lt;/strong&gt;:  &lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;&lt;a href="https://github.com/gebleksengek/carbon-lang-armv8a-builder" rel="noopener noreferrer"&gt;gebleksengek/carbon-lang-armv8a-builder&lt;/a&gt;&lt;/strong&gt;  &lt;/p&gt;




&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;This experiment proves that, with some modifications, &lt;strong&gt;Carbon Language can run on ARMv8-A devices&lt;/strong&gt;, 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.  &lt;/p&gt;

&lt;p&gt;I hope that in the near future, &lt;strong&gt;Carbon Language will officially support AArch64&lt;/strong&gt;, eliminating the need for manual builds. Until then, this project will continue bridging the gap.  &lt;/p&gt;

&lt;p&gt;Don’t forget to check out my &lt;strong&gt;GitHub repository&lt;/strong&gt; and support it with a ⭐ star if you find this project useful:  &lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;&lt;a href="https://github.com/gebleksengek/carbon-lang-armv8a-builder" rel="noopener noreferrer"&gt;gebleksengek/carbon-lang-armv8a-builder&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>cpp</category>
      <category>android</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
