Sunday | 28 APR 2024
[ previous ]
[ next ]

ScarletDME on MacOS

Title:
Date: 2023-12-03
Tags:  scarletdme, mac

Previously on Dragon Ball Z.

I finished up getting my MacBook set up as a server and the next thing up was to get ScarletDME running. This involved compiling my fork of scarletdme that uses zig and I figured this was going to be the most painful part.

I also expected to have issues with scarletdme itself running on Mac. I had checked the google groups and someone did have some patches to get everything working on mac but I wasn't sure if those were merged in or if I would have to manually patch things through.

TLDR, you're currently reading this, as of December 3rd, 2023, from a MacBook sitting in my bedroom so everything worked out!

Getting zig set up was straightforward and I simply installed it the usual way instead of using brew. I didn't think I needed brew here because zig doesn't have much in the way of dependencies and I'm happy to manage zig myself. Probably for the better as I'm currently only sure that v0.11 works.

Once I had zig, then came the hard part. I cloned my ScarletDME fork and tried to do a zig build. This errored out catastrophically and terrifyingly. I really do hate the Zig error messages. Still they were helpful in that they told me I was missing mbedtls headers.

I realized that I needed to install mbedtls and so I went directly to brew. I'm not comfy with managing C headers so I figured I'd rather let brew handle this. Luckily there was a bottle available and so installing mbedtls was as simple as doing:

brew install mbedtls

With that done, I ran zig build again. Still errors catastrophically. The errors were still the same, even though I had the mbedtls headers, Zig wasn't finding them. Homebrew was installing the headers to /opt/homebrew/include and so I needed this path to be in the search path of zig. I couldn't figure that out so instead I added the path to the build.zig directly.

This was a bit of a learning experience as I didn't put it together that 5 exes I was building were really being built seperately. I had assumed that if I had added the header files and the static library files to my op_secure_sockets.zig file that it would work it's way into the system. In reality it didn't, I need to link mbedtls against all 5 binaries that get generated as they all rely on qm.h. qm.h in turn needs mbedtls.

This took awhile for my to figure out, I ultimately stripped my build.zig down to just the qm binary and was then able to compile it. I then slowly worked out what I had to do to get the full build.zig to work. This is really a knowledge issue but luckily one that wasn't too far out of my reach.

Now the next time I ran zig build, I got much further. Now I ran into an alignCast error and helpfully zig told me how to fix it. I added an aligCast() function call and that got me through that. Ask me what it does. Ask! No idea. Some sort of byte alignment magic?

Anyway the next and final trouble was that the parse_key function from mbedtls was giving me an error saying that it was expecting 5 arguments and I was giving it only 3. I learned that brew installed the latest version of mbedtls whereas I was using mbedtls 2.something on CentOS 7. This required me to make the change directly here and luckily it was a minor one. I found an example from the mbedtls github and simplied copied it to fix the parse_key function.

I didn't want to roll mbedtls back as this looked to be just a 1 function difference.

At this point I got it all working and now I had the qm binary ready to go.

The next port was the install script and this required the largest changes. I split my install.sh script into a Linux script and a mac script. Both scripts will check what system is being run and tell you to use the correct script.

The install-mac.sh uses some pretty different user and group creation stuff which I hadn't seen before. Overall it was a straightforward port but it did require reading quite a bit to get all the commands right. I'm still not sure if my install-mac script is truly done as I didn't run it enough times. It worked well enough but I had to do some manual fudging to get all the numbers set properly.

Mac seems to require you generate the group ids and the user ids directly. It's not automatic which is really weird. I wonder what is going on.

The other big thing was that mac doesn't let you use /usr so you have to put everything in /usr/local. This wasn't a big deal so I changed the mac version of the install script to use /usr/local/qmsys and to link things to /usr/local/bin.

Once I actually got everything set up and I ran the install script for mac, everything worked pretty much right out of the box.

I was able to test ScarletDME and everything worked. I had my NPM, NSH and EVA working right away and everything looked good.

This gave me hope that my web server and blog would also work and luckily enough they did! I'm honestly surprised at how easily ScarletDME ran on the MacBook. The installation and compilation were hard but not terrible.

OpenQM did work on Mac so probably the work was already done. Also the patches from the google groups were probably incorporated in at some point. I didn't check and for now I don't see the need to. My blog was working and all the functionality that I wanted looked to be working properly.

With my blog being server out from my server at home, this means that I'm now ready to start building out applications that are home specific and public. This will be a fun little adventure. I'm really hoping I don't have to deal with much sysadmin stuff but we'll see how it goes.