The Journey to Rubies!


MufiZ v0.8.0 Ruby will be coming out today, and with it, we mark a great success! We have converted all 7000 lines of C code into Zig, so how was the process…it was painful, and there is still more cleanup, which I will be doing over time in future versions as we remove more of the C dependency.
Step 1: Translate and Link
The beginning of the transformation was translating all the C files into Zig files using Zig’s translate-c
command. This tool is so powerful and amazing, so from there, we started adding it to the build.zig
file linked to the Zig file and removed the C linking.
Step 2: REMOVE A LOT OF F- BINDINGS
Once we confirm linking is working fine, we start to remove the excessive bindings and have only the core stuff in the file, and begin importing. I wish Zig had like a import *
command, I really do, because it would’ve saved me so much time.
During this stage, which was the longest, I had to deal with hundreds of errors, and thanks to my editor, Zed, and multiline buffering, I was able to handle the errors much more easily.
Also, during this stage, I realized how many integer overflow cases were just not handled in C because, well, it was never reported to me. So, those I had to handle in Zig made me happier about this porting experience.
Step 3: Cleanup…well try to
Yeah, I tried to clean up as much as I could, but there’s still stuff that I will have to do. During this stage, I found our array type acting very strangely, and we didn’t need the design; it was better to have FloatVector. Matrix is broken so got rid of that and once the research is in, we will put it back in, also once we switch our memory model to use Zig’s allocator, we can breathe easier.
Conclusion
There is still a lot to improve in our code base, honestly being a solo developer maintaining 10000 lines of code is overwhelming, but that’s why over releases I will be continuously fixing the code, some releases will have new features, others will just be small fixes.
But the main work has been completed, and having it all under a single language makes my life much easier and less sparse. We can finally better organize the language and make it more DRY. Compiling will be faster due to avoiding linking, and we can take advantage of more of the Zig features and start to support more toolchains once we remove that C dependency.
Subscribe to my newsletter
Read articles from Mustafif Khan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
