What is the state of Zig in Termux?

Hello, Zig community friends. How are you? :hugs:

I apologize for the inconvenience, but I wanted to ask about the status of Zig support in Termux. Has anyone used it yet?

I’m asking because I don’t have a PC and I use Termux on my Android phone for programming. I’ve been interested in learning Zig, but it doesn’t work properly. When I try to build in Termux, I get the message illegal instruction. :sob:

What processor is your tablet running? What kernel version? You can look here for the list of supported architetures and OSs.
This use case is probably not on the Zig team’s radar, so I think you are blazing a trail here. Are you trying to build Zig from source? Or are you trying to run zig build and are getting this error?

Hi @Southporter. Thanks for your response. :wave:

My kernel version is 4.14.87+ and the processor is Mediatek MT8168M with 2 GB of RAM. Below is all the information I was able to extract with fastfetch:

OS: Android REL 9 armv8l
Host: Amazon KFONWI
Kernel: Linux 4.14.87+
Packages: 147 (dpkg)
Shell: zsh 5.9
WM: Window Manager
Terminal: Termux 0.118.1
CPU: MT8168M (4) @ 2.00 GHz
Locale: en_US.UTF-8

I can install Zig through Termux with the command pkg install zig, which installs version 0.13.0. I start a project with zig init and the corresponding files are created. Then, I enter zig build and get the following message:

Warning: Encountered error: FileNotFound, falling back to default ABI and dynamic linker.
[1] Compile Build Script
└─ [1] AST Lowering
   ├─ crypto/tlcsprng.zig
   └─ bounded_array.zigzsh: bus error  zig build

I get an illegal instruction error message when trying to install Zig on Alpine using Termux proot-distro and following the previous steps.

I’ve also tried it on another device with the following specifications:

OS: Android REL 9 aarch64
Host: Amazon KFTRWI
Kernel: Linux 4.4.146+
Packages: 139 (dpkg)
Shell: zsh 5.9
WM: Window Manager
Terminal: tmux 3.4
CPU: Cortex-A53*4 + Cortex-A73*4 (8) @ 1.99 GHz
Locale: en_US.UTF-8

On this device, I get the following error message:

illegal hardware instruction  zig build

I think I’ll have to wait until Zig reaches version 1.0.0 or at least version 0.14.0 before trying again. :slightly_smiling_face:

This is looking like a compiler bug to me. Or more exactly an untested use case. You might want to add this as an issue on GitHub - ziglang/zig: General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software..

This looks like a missing target or something like that. You might try compiling with a more generic target (i.e. -Dtarget=aarch64) or something similar to see if you can get around it.
You can see the available targets with zig targets.

In regards to your first question, what is the state of Zig in Termux?
It looks like it is untested. You might get it to work, but you’ll have to fiddle with it.

1 Like

Hello, @farias-hecdin
Welcome to ziggit :slight_smile:

Try to build using zig build -mcpu=baseline

Running zig build-exe --show-builtin zig displays as zig source code the abi, os, and cpu with it’s features.
You can set the target cpu and reduce the cpu features using -mcpu=baseline-dsp where–for example–dsp is a baseline cpu feature that MT8168M don’t have.

3 Likes

I have some good news and some bad news.

Bad news :sob:

@dimdin, I followed your recommendations, but it still doesn’t work. It seems that, as you mentioned, the MT8168M processor lacks the necessary features to compile Zig code.

@Southporter, I tried using the -Dtarget=aarch64 flag, but I received the same illegal hardware instruction message.

Good news :partying_face:

I tested it on a friend’s smartphone. He has a Tecno Pova 5, and I was able to install Termux and Zig without needing to set up any termux proot-distro, and it worked perfectly! The smartphone has the following specifications:

  • CPU: MT6789 (MediaTek Helio 99)
  • Kernel: Linux 5.10.198-android12-9-00036-g85b…
  • OS: Android REL 14 aarch64

I should mention that I only created a simple program that returns the text “Hello World” and used the command zig build-exe <filename>.zig to test it.

When I tried using the zig init command, it generated the necessary files, but when I ran zig build, the CLI displayed messages about the build progress and then returned a message related to error testing.

I couldn’t continue testing further since the smartphone wasn’t mine, but this is great news for anyone looking to learn Zig in Termux!

Thanks to @dimdin and @Southporter for your help. :two_hearts:

4 Likes