Building OpenSSL for ARM/Apple silicon Macs

I tend to shy away from dependencies when possible. But my app, Aether, has an unavoidable dependency on tqsllib, which in turn depends on OpenSSL. Originally, OpenSSL shipped with macOS, so using it was no big deal. Apple deprecated it years ago (for very good reasons) and recommends building it yourself from up-to-date source if you need it. So, I do just that.

Normally, building OpenSSL is pretty straightforward. Download the source, run:

./configure darwin64-x86_64-cc
make
make install

and you’re done.

As of right now (June 22, 2020), if you want to build it for Apple’s newly announced Macs with "Apple silicon” (aka ARM), it doesn’t work out of the box. I managed to get it to build and thought I’d share what I did. I did this on an Intel Mac running the Xcode 12.0 for macOS Universal Apps beta, but I believe these instructions should work without changes on an ARM Mac as well.  Disclaimer: This is a bit of a hack job. I expect that the OpenSSL project will add official support fairly quickly so this stuff won’t be necessary. I may try to submit a patch, but I’m not confident enough of the details here to say that it’s the best way to do things or without any lurking issues. So, as always, use this at your own risk! I’m not an SSL expert, a security expert, nor a build system expert.

Here’s how I built OpenSSL for ARM Macs:

1. Install "Xcode 12 for macOS Universal Apps beta"

2. Switch to using the beta for command line tools using:

sudo xcode-select -s /Applications/Xcode-beta.app

3. Download the OpenSSL source code:

git clone git://git.openssl.org/openssl.git

4. Switch to the openssl directory:

cd openssl

Optional 4b. I need OpenSSL 1.1.1, so I switched to that branch:

git switch OpenSSL_1_1_1-stable

5. Open the file Configurations/10-main.conf in your favorite text editor:

bbedit Configurations/10-main.conf

6. OpenSSL uses its own configuration system, and it uses this to configure certain things when building for a particular target. Most importantly, we need to specify the correct architecture (arm64) for Apple silicon/ARM Macs. To do this, find the section where the configuration for darwin64-x86_64-cc is defined. It’s line 1552 as I write this. Add the following new configuration for ARM Macs under it:

"darwin64-arm64-cc" => {
inherit_from => [ "darwin-common", asm("aarch64_asm") ],
CFLAGS => add("-Wall"),
cflags => add("-arch arm64"),
lib_cppflags => add("-DL_ENDIAN"),
bn_ops => "SIXTY_FOUR_BIT_LONG",
perlasm_scheme => "macosx",
},

7. Build for ARM by running the configure script, followed by make and make install. This will build for arm64, and place the results in /tmp/openssl-arm

./Configure darwin64-arm64-cc --prefix="/tmp/openssl-arm" no-asm
make
make install

The no-asm option tells the build system to avoid using assembly language routines, instead falling back to C routines. This prevents errors during build on ARM. The same option is not necessary for the x86 build. I’m sure there’s a way to fix building the ASM routines for arm64 (they build fine for iOS), but it’s beyond me right now.

8. Build for x86_64 by running the build steps again again like so:

./Configure darwin64-x86_64-cc --prefix="/tmp/openssl-x86"
make
make install

9. Lipo the results together to create a single, universal static library:

lipo /tmp/openssl-arm/lib/libssl.a /tmp/openssl-x86/lib/libssl.a -create -output libopenssl/lib/libssl.a
lipo /tmp/openssl-arm/lib/libcrypto.a /tmp/openssl-x86/lib/libcrypto.a -create -output libopenssl/lib/libcrypto.a

10. You’ll also need the headers. I just copy them like so:

cp /tmp/openssl-arm/include/openssl/* include/openssl/

11. If everything worked, you’ll now have static library binaries for libcrypto and libssl in lib/, along with headers in include/openssl/

First Day

Today is my first day at Luma Touch. I’m joining them as a Principal Software Engineer. I'll be working on their incredible iOS apps, including LumaFusion. I talked about leaving Lambda in my last post. I wouldn’t have left if I weren’t incredibly excited about where I was going.

Luma Touch’s biggest product is LumaFusion, a professional video editing app for iOS. LumaFusion has a big, passionate user base made up of video professionals as well as “regular people”. They have a solid roadmap with lots of fun stuff to work on in the weeks, months, and years to come.

At Luma Touch, I’m joining a team of engineers I’ve known and respected for a while, including one of my former students. I'll get to work with a group of engineers with varying experience levels, and hope to be able to mentor those who are newer to the industry.

I’m most fulfilled when I get to work on things that people use because they love them. I got into Mac development, and later iOS development, precisely because I loved the user-focused, design-first approach that apps on the Mac platform took. I wanted to build the same kinds of things that I loved using myself. I’ve been lucky enough to spend most of my software engineering career working on just those kinds of apps. I also have a background in media programming and even some video editing and production experience (a long time ago!).

With all of this in mind, Luma Touch feels like a perfect fit.

Last Day

My Team at Lambda

A gift from my team on my last day.

Today is my last day at Lambda School. I’m really excited about what’s next, but first I wanted to write down my thoughts about Lambda and my time there. I started at Lambda in March 2018, just over 2 years ago. At the beginning of 2015, my friend Caleb Hicks was starting the full-time immersive iOS program at DevMountain. He asked me to come in to do a guest lecture. Teaching in a formal setting seemed like fun, so of course I said yes. I had a blast teaching a bunch of eager, brand-new iOS developers about SceneKit. He asked me to keep coming back, and soon I was teaching once a week.

A year and a half later, I joined DevMountain full time to run their iOS program. It was a nice change of pace from engineering, and I loved getting to work with students every day. Every teacher will tell you about the feeling of watching a student learning something from scratch and the excitement they feel when they suddenly can do something that seemed impossible just a little while ago. There’s nothing that compares. Having a job where I got to be part of that every day was great, and that it still let me exercise my expertise in programming was even better. I learned a ton, got a lot better at teaching, and most importantly got to be directly involved in helping a bunch of people start their iOS development careers.

Lambda School started in mid-2017. I had known of Austen Allred, the CEO and co-founder, from Twitter, mutual friends, and his work on a previous startup, Grasswire. That summer, I was interviewing at Apple for an engineering job, and staying with Caleb in San Jose during WWDC. Caleb was at Apple working on the Everyone Can Code project, and was talking to Lambda’s founders about maybe joining them. I got an offer to work on an incredible team at Apple, and was very seriously considering taking it. At the last minute, partly because I had Lambda in the back of my mind, I decided it wasn’t the right move for me. That fall, Caleb left Apple to join Lambda, and we had already started talking about me joining him there. A few months later, I left DevMountain to start Lambda’s iOS program.

At the time, Lambda was small, with around 20 full time employees. Our only physical office was in a small business park in Pleasanton, CA, though only 3 or 4 people worked there regularly. I’m used to working at companies this size, and it’s the sweet spot for me. Those of us in Utah got together for lunch every week, I talked to people working on everything going on at the company regularly, and felt like I had a big impact. In short, it was great, and quickly became my favorite job ever. I’ve worked with smart people, but the group of people at Lambda were some of the smartest, most ambitious people I know. It didn’t hurt that a number of them were existing friends.

We launched the iOS program at Lambda in July of 2018 and I taught the entire first cohort myself. Halfway through the course, I started to “run out” of curriculum that I had already written. It meant that I was staying up late almost every night writing lessons, creating project assignments, recording videos, etc. only to get up the next morning to teach. Anyone who has taught knows how fulfilling it is, but also that it’s not exactly relaxing! I’ve rarely worked harder, but it was a blast. Every day I got to work directly with a small group of students taking a chance on a brand new program. I was continually impressed by how hard they worked, how eager they were to learn, and how fun they were to be around. I’m proud to say that nearly all of them are now out in the industry working as iOS developers on amazing things. It was one of my favorite few months of my entire career. I got to hire a team of full-time iOS instructors who are still there, still teaching, and still changing students’ lives.

A year or so ago, I moved into a role where I was building and leading Lambda’s dedicated curriculum team. I got to assemble a team of curriculum developers, and building that team is the project I’m most proud of. I’m convinced there’s not a better group of people in the world. I’m impressed by them every day, and love working with them. Not getting to work with them is the thing about leaving Lambda that I’m saddest about. I’m really excited to follow what they do from the outside, though. If you have any doubt about the people making Lambda happen, go talk to the curriculum team. You’ll find some of the smartest, most accomplished, most interesting, driven, and most importantly, kind people anywhere in the world.

As all of this has happened, Lambda has grown. The company is in the neighborhood of 200 full time staff now, with thousands of students. It has changed a great deal in the two years I’ve been here. Many of the changes have been great, a blast to be a part of, and have helped us get even better at helping students change their lives. There have also been some growing pains, but even those have been an important part of the story, and have taught me a lot.

So, if Lambda’s so great, why am I leaving? I’ve been in tech education full time for about 4 years now. I’ve loved it, but I am an engineer at heart, and have been my entire life. Solving problems, especially deep technical problems, is the work my brain likes most. The past eight months, I’ve had some contract work for a few clients doing audio programming for iOS, which is right up my alley, and I’ve found myself looking forward to evenings and weekends when I could work on it. Simultaneously, I’ve felt like, while my engineering ability isn’t declining, I’m not pushing myself in that area. It makes me feel like I’m falling behind. In short, as much as I’ve loved being in education, it’s just time for me to be an engineer again.

I’ll share more about my new job next week, but I’m incredibly excited about where I’m going. It’s exactly the kind of project I love most, working with a very small team of people, including some I’ve known and respected for a while, on a native iOS app that people buy if — and only if — it’s excellent. I’ll even have one of my former students as a teammate. It feels like an opportunity tailor made for me, and when it came along, it was obvious pretty quickly that it was the right move for me to make.

I’ll miss Lambda, especially the friends -- coworkers and students -- I’ve gotten to know. It’s the best job I’ve ever had, and I couldn’t be more grateful for my time here. I’m extremely optimistic about their future, will be rooting for them, and if I’m lucky, they’ll invite me back to teach, even if only part-time.

P.S. Lambda had to lay off some people a couple weeks back due to the effects of COVID-19. I wasn’t part of this group, having decided to take this new job well before lay offs happened. Some really good people were affected, and you should snap them up if you’re hiring. Get in touch if you want recommendations.

Remapping ⌘-. (command-period) to BREAK in iTerm2

I switched to iTerm2 from the default macOS Terminal app a few months ago. Mostly, I really like it. It has a ton of power-user features missing in Terminal.app, as well as a nice ecosystem of enhancements. However, there are a few differences that have bugged me.

In Terminal.app, instead of pressing ^C to send a break, and thereby terminate a running program, etc., you can press the standard Mac cancel keyboard shortcut, which is ⌘-. (command-period). This is built into my muscle memory, and is used widely through the Mac interface, as it has been for decades. Out of the box, iTerm2 doesn’t recognize ⌘-. as BREAK, instead filling your terminal with escape sequences.

Of course, iTerm2 is extremely customizable, so it’s a fairly simple matter to remap ⌘-. to send break. To do so, open iTerm2’s Preferences, select the Profiles pane, then the Keys tab. Click the “+” button below the list of keyboard shortcuts to create a new short cut. Record the shortcut itself by selecting the Keyboard Shortcut field and pressing the Command and Period keys. For Action, select “Send Hex Code”. In the text field at the bottom, enter 0x03, which is ASCII for “end of text” (ETX), which is what control-C actually sends in a regular terminal. Click OK and you’re done.

Screen Shot 2020 01 25 at 4 19 17 PM

You can test it out by running something that takes a while, for example an infinitely looping shell script (see below), then pressing ⌘-. to make sure it actually breaks/stops.

#!/bin/bash
while :
do
echo "Press [CTRL+C] to stop.."
sleep 1
done

Screen Shot 2020 01 25 at 4 29 13 PM

Crosley RSD3 Counterweight Fix

For Christmas, I got a Crosley RSD3 3” mini turntable. It’s definitely a novelty, not a serious device, but it’s fun nonetheless. It plays 3” vinyl singles (which are unfortunately quite expensive), runs on batteries or USB power, and has a built in speaker.

The Problem

Out of the box, I noticed that while it actually has a real stylus (Audio Technica NP5), the tracking force is so high that the record won’t reliably turn with the stylus down! Even if the high tracking force didn’t cause the record to stop turning, it’s so high that it would likely damage the record and/or the stylus. I used my tracking force gauge to measure it, and found that it was literally off the scale. After playing around with the built in counterweight — which is sort of adjustable — without being able to bring the tracking force down, I decided to design something to fix it.

The Solution

Using the excellent ShapeScript, I designed and 3D printed a little adapter that fits over the built in counter weight, and has spots to insert #8-32 nuts (which I had laying around) to increase the counterweight and thereby decrease the tracking force. With 6 nuts inserted, the tracking force is about 2.5 grams, which is in spec for the stylus, and allows the turntable to spin just fine with the stylus down.

I’ve put the 3D model for the adapter up on Thingiverse so anyone can download and print it. It’s intentionally designed to be easily removable without damaging the turntable. It also doesn’t interfere with the included dust cover for the turntable.

Tips

It’s easiest to remove the built in counterweight before installing this adapter. Just remove the screw in the center, and pull the counterweight straight off. You can then press it into the hole in the adapter before reinstalling the whole thing on the tone arm. If you want to secure the nuts, use a soldering iron to gently melt down the top of the post going through each nut. It will mushroom out a little holding the nut in place.

IMG 0813