I typically use ASDF when installing Elixir and Erlang so that I'm able to pin versions for projects. In most cases compiler warnings will cause builds to fail so we need to test things with new versions before we're ready to fully migrate.

KERL_BUILD_DOCS=yes asdf install erlang 27.1.2

This week I went to install the latest version of Erlang using ASDF and I kept getting a strange error:

Build failed.
  525 | #include <_ctermid.h>
      |          ^
 CXX	obj/aarch64-apple-darwin24.0.0/opt/jit/process_main.o
1 error generated.
make[4]: *** [obj/aarch64-apple-darwin24.0.0/opt/jit/beam_asm_module.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [opt] Error 2
make[2]: *** [opt] Error 2
make[1]: *** [jit] Error 2
make: *** [emulator] Error 2

Please see /Users/me/.asdf/plugins/erlang/kerl-home/builds/asdf_27.1.2/otp_build_27.1.2.log for full details.
Removing all artifacts except the logfile
(Use KERL_AUTOCLEAN=0 to keep build on failure, if desired)
Cleaning up compilation products for asdf_27.1.2
Cleaned up compilation products for asdf_27.1.2 under /Users/me/.asdf/plugins/erlang/kerl-home/builds

Build failed.

I'd been running the macOS Sequoia beta for months without issue so this puzzled me. It's still not clear to me what has changed to trigger the underlying cause.

Looking at the logs I noticed the error too many open files. Running ulimit -n returned 256 which was obviously the problem.

However the fix was more involved.

You can temporarily increase the limits using the command:

 ulimit -n 65536

but the fix doesn't persist across reboots. The solution has become more complicated since Apple introduced SIP (System Integrity Protection).

The solution is to use a Launch Daemon to change the limits on startup as noted by this blogpost by Jordan Williams:
https://www.jwillikers.com/too-many-open-files-on-macos-when-compiling

Create a plist file for the Launch Daemon and save it as /Library/LaunchDaemons/limit.maxfiles.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>limit.maxfiles</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>maxfiles</string>
      <string>65536</string>
      <string>2147483647</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

/Library/LaunchDaemons/limit.maxfiles.plist

Then activate the Launch Daemon:

# set permissions and ownership
sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
sudo chmod 644 /Library/LaunchDaemons/limit.maxfiles.plist

# enable the Launch Daemon
sudo launchctl bootstrap system /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl enable system/limit.maxfiles

After a reboot you should have a more reasonable file limit:

> ulimit -n
65536

and compiling should succeed!