Wednesday, 5 February 2025

Visual Studio, Ada Language Server, macOS

If you’re using VSCode on a Mac with Apple silicon (an M-series chip) you will probably have noticed that Ada code formatting doesn’t work.

This is thought to be because of an issue with the aarch64-apple-darwin compiler. It’s stated that the problem doesn’t occur if the Ada Language Server is compiled for the Intel (x86_64) architecture.

Can we run the Intel version?

Macs with Apple silicon (arm64 or aarch64) can use Rosetta to run x86_64 programs.

VSCode installs the Ada Language Server of the architecture matching the CPU, in the directory darwin/ in (for ALS release 26.0.202412191)

~/.vscode/extensions/adacore.ada-26.0.202412191-darwin-arm64/arm64/

The contents of darwin/ are

-rwxr-xr-x  1 simon  staff  108059392 23 Jan 11:10 ada_language_server
drwxr-xr-x  3 simon  staff         96 23 Jan 11:10 ada_language_server.dSYM
-r--r--r--  1 simon  staff     452816 23 Jan 11:10 libgmp.10.dylib

where

$ darwin/ada_language_server --version
ALS version: 26.0.202412191 ()
$ file darwin/ada_language_server
darwin/ada_language_server: Mach-O 64-bit executable arm64

Yes, we can!

Since this ada_language_server is an executable, we can trick VSCode into running the x86_64 version by replacing the contents of darwin/.

Going to AdaCore’s Releases directory, download als-26.0.202412191-darwin-x64.tar.gz.

Remove the quarantine attribute:

$ xattr -d com.apple.quarantine` als-26.0.202412191-darwin-x64.tar.gz

and unpack it into a convenient directory, e.g. ~/als-downloads, where the darwin/ directory will be at integration-202412191/vscode/ada/x64/darwin/.

Make this be the one that VSCode finds. I’ve used symbolic links to avoid accidents as far as possible.

$ cd ~/.vscode/extensions/adacore.ada-26.0.202412191-darwin-arm64/arm64/
$ mv darwin darwin-arm64
$ cp -pR ~/als-downloads/integration-202412191/vscode/ada/x64/darwin darwin-x86_64
$ ln -s darwin-x86_64 darwin

Should you want to reverse this, you can swap the symlink over, but be aware that whatever man ln may say, ln -sf darwin-arm64 darwin will not work; you need to delete the original symlink first, rm darwin.

What next?

It turns out that if you build ada_language_server with GCC 15, this issue isn’t present. GCC 15 is still in the pre-release stage (15.0.1 20250126), and it’ll be a while before it’s released and then makes it onto one of the standard download sites.

1 comment:

  1. The problem happens when you let VSCode format using GNATformat (it crashes). If you untick this in the settings it will, for the moment, use GNATpp, which (a) doesn’t crash, (b) supports casing, you’ll be much happier.

    By default, GNATpp adjusts names to the casing with which they were declared (e.g. Ada.Text_IO).

    ReplyDelete