[WIP] Cross-compiling iceoryx2

(Warning: This post is mostly a rant!)

Watch me suffer. For my internship project I thought it would be cute to complicate it as much as possible. It’s a soft PLC running ontop of Linux with PREEMPT_RT. The stack is mostly in Rust, but I wanted to find an excuse to write a part of it in Zig.

So I thought, “Ah, well. I’ll just write a Telegram bot in Zig. Easy work. I’ll just pipe bits out of the soft PLC and send alerts via Telegram”.

It quickly went from 0 to 999 real quick. Mind you, I’m just a kid who could barely make a Streamlit app in a Jupyter notebook. I was already using iceoryx2 to pipe bits between parts I wrote in Rust. Cross compiled it with cross, easy peasy. I didn’t have to worry about paths even once.

Then it hit me. iceoryx2 is a Rust project. Crap. The Zig bindings are ‘planned’. Crap, that means I have to deal with CMake to talk through the C bindings in Zig. After 2 straight hours of talking to LLMs and reading error logs I got it working. But that was just building the C examples.

Now Zig has with it its own under-documented build system. At this point everything I see online, even those coming from the ZSF team itself needs to be taken with approximately 3 mountains of salt. I struggled with CMake, now’s the time to struggle with build.zig.

2 more hours spent, talking with LLMs. I blindly poked around and I finally got it to build, it ran just as expected on my Pi. Yippee.

I was incredibly frustrated, even questioning why I even cared about Zig in the first place. But then it hit me. I struggled about the same with CMake just 4 hours ago, yet CMake is 24 years old, 2.5 years older than me. I struggled because Zig is a massive WIP and up-to-date docs are hard to come by. One can only imagine how much of a breeze it will be once it reaches 1.0.

(End of rant)

This is unsubstantial, I just wanted to tell the world what I got myself into.

7 Likes

I was incredibly frustrated, even questioning why I even cared about Zig in the first place. But then it hit me. I struggled about the same with CMake just 4 hours ago.

Working with CMake is one of the main reasons I love the Zig project. :wink:

Want feedback or are you just sharing a delightful rant?

Don’t think there’s anything that can use feedback on at the moment, this was just a rant😆

The repo I linked has the same utility as pocket lint, and I don’t plan to make it any more useful :slight_smile: But if you have anything to comment I’m all ears.

1 Like

Don’t underestimate pocket lint, MacGyver would find a way to save somebodies life with it :wink:

1 Like

LLMs are terrible for Zig. Relying on them to learn from is one of the easiest ways to drive yourself nuts because they just make stuff up. Better to pick a couple of existing working projects and see how they do stuff. Check the showcase here, and the Projects section of the Zig Discord.

2 Likes

If you want more fun, try using Zig to build a project that relies on CMake to generate source code! :joy: For example, here’s the original Iceoryx used by Cyclone DDS: zig-iceoryx/build.zig at main · JacobCrabill/zig-iceoryx · GitHub

(And why did I build Iceoryx with zig? Well, I’ve been slowly trying to build upon the work of zig-robotics · GitHub to have a complete ROS ecosystem built with Zig. If you’re familiar with how awful ROS’s build systems are on top of CMake, you can understand just how great it would be to use Zig instead.)

For Zenoh (a rust project and DDS alternative), I just download the pre-built binaries and link against them :person_shrugging: , and translate-c the headers:

Its kinda hacky but it supports all the targets I need to support, at least for now (windows and linux-musl).

1 Like