www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to use D on M2 macOS?

reply Albert <albeva me.com> writes:
Hi all,

I am completely new to D, wished to try it out and write a small 
app in it. However, for the last couple hours I am ready to pull 
my hair out as I have no idea how to compile even a simplest 
hello world app.

I installed ldc and dub (nowhere on the download page did it even 
mention that dub should be installed separately!) from home-brew, 
installed code-d for vscode, used the plugin to create a new 
project and that is as far as I've gotten.

For example the plugin prompts me to "Compile serve-d", however 
doing so just fails with:

```
Error Command failed with exit code 127: rdmd 
"/Users/albert/.dub/packages/dfmt/0.14.1/dfmt/dubhash.d"
Failed to install serve-d (Error code 2)
```

And so on and so forth. Am I missing something obvious?
Jul 21
next sibling parent reply Luna <luna foxgirls.gay> writes:
On Monday, 21 July 2025 at 13:29:23 UTC, Albert wrote:
 Hi all,

 I am completely new to D, wished to try it out and write a 
 small app in it. However, for the last couple hours I am ready 
 to pull my hair out as I have no idea how to compile even a 
 simplest hello world app.

 I installed ldc and dub (nowhere on the download page did it 
 even mention that dub should be installed separately!) from 
 home-brew, installed code-d for vscode, used the plugin to 
 create a new project and that is as far as I've gotten.

 For example the plugin prompts me to "Compile serve-d", however 
 doing so just fails with:

 ```
 Error Command failed with exit code 127: rdmd 
 "/Users/albert/.dub/packages/dfmt/0.14.1/dfmt/dubhash.d"
 Failed to install serve-d (Error code 2)
 ```

 And so on and so forth. Am I missing something obvious?
I highly recommend using LDC2 from the official packages https://github.com/ldc-developers/ldc/releases/tag/v1.41.0 I've additionally written a script that installs LDC 1.41 + various tools and the latest main branch dub you can use here https://gist.github.com/LunaTheFoxgirl/3e14a3aa977c14398c902023e567268a
Jul 21
parent Luna <luna foxgirls.gay> writes:
On Monday, 21 July 2025 at 13:52:52 UTC, Luna wrote:
 On Monday, 21 July 2025 at 13:29:23 UTC, Albert wrote:
 Hi all,

 I am completely new to D, wished to try it out and write a 
 small app in it. However, for the last couple hours I am ready 
 to pull my hair out as I have no idea how to compile even a 
 simplest hello world app.

 I installed ldc and dub (nowhere on the download page did it 
 even mention that dub should be installed separately!) from 
 home-brew, installed code-d for vscode, used the plugin to 
 create a new project and that is as far as I've gotten.

 For example the plugin prompts me to "Compile serve-d", 
 however doing so just fails with:

 ```
 Error Command failed with exit code 127: rdmd 
 "/Users/albert/.dub/packages/dfmt/0.14.1/dfmt/dubhash.d"
 Failed to install serve-d (Error code 2)
 ```

 And so on and so forth. Am I missing something obvious?
I highly recommend using LDC2 from the official packages https://github.com/ldc-developers/ldc/releases/tag/v1.41.0 I've additionally written a script that installs LDC 1.41 + various tools and the latest main branch dub you can use here https://gist.github.com/LunaTheFoxgirl/3e14a3aa977c14398c902023e567268a
Also as a sidenote, the homebrew release of the compiler is not maintained by the D Language Foundation and in general is relatively far behind upstream. I recommend uninstalling any D tools you've installed via homebrew and install using the upstream methods. The crashes you encounter are due to a change Apple made to their dynamic linker and thread local variable support in macOS 15.4. LDC 1.41 fixes this issue; and unlike DMD can compile for arm64.
Jul 21
prev sibling next sibling parent reply Serg Gini <kornburn yandex.ru> writes:
On Monday, 21 July 2025 at 13:29:23 UTC, Albert wrote:
 Hi all,

 I am completely new to D, wished to try it out and write a 
 small app in it. However, for the last couple hours I am ready 
 to pull my hair out as I have no idea how to compile even a 
 simplest hello world app.

 I installed ldc and dub (nowhere on the download page did it 
 even mention that dub should be installed separately!) from 
 home-brew, installed code-d for vscode, used the plugin to 
 create a new project and that is as far as I've gotten.

 For example the plugin prompts me to "Compile serve-d", however 
 doing so just fails with:

 ```
 Error Command failed with exit code 127: rdmd 
 "/Users/albert/.dub/packages/dfmt/0.14.1/dfmt/dubhash.d"
 Failed to install serve-d (Error code 2)
 ```

 And so on and so forth. Am I missing something obvious?
I agree with Luna that installing from official GitHub Releases are the easiest way. There is also this project: https://code.dlang.org/packages/ldcup regarding serve-d - you need to download the code from the github and build it locally with the latest LDC compiler. It should fix the issue. Also don't forget to switch the version of the "code-d" extension to "beta/nightly". Stable is very old and not updating properly.
Jul 21
next sibling parent reply Luna <luna foxgirls.gay> writes:
On Monday, 21 July 2025 at 14:10:44 UTC, Serg Gini wrote:
 On Monday, 21 July 2025 at 13:29:23 UTC, Albert wrote:
 [...]
I agree with Luna that installing from official GitHub Releases are the easiest way. There is also this project: https://code.dlang.org/packages/ldcup regarding serve-d - you need to download the code from the github and build it locally with the latest LDC compiler. It should fix the issue. Also don't forget to switch the version of the "code-d" extension to "beta/nightly". Stable is very old and not updating properly.
The script I posted automates some of these steps by the way; so you'll just have to set the paths correctly in the plugin (/opt/SDKs/serve-d/bin/serve-d, /opt/SDKs/dcd/bin/dcd-server, /opt/SDKs/dcd/bin/dcd-client); then set the serve-d version as frozen.
Jul 21
parent reply Albert <albeva me.com> writes:
On Monday, 21 July 2025 at 14:16:29 UTC, Luna wrote:
 The script I posted automates some of these steps by the way; 
 so you'll just have to set the paths correctly in the plugin 
 (/opt/SDKs/serve-d/bin/serve-d, /opt/SDKs/dcd/bin/dcd-server, 
 /opt/SDKs/dcd/bin/dcd-client); then set the serve-d version as 
 frozen.
Thank you. This seems to have worked better! Though I am still getting errors: ``` Could not initialize DCD for ``` and in the output get a lot of: ``` 2025-07-21T15:30:59.455 [warning] first.d:474:visit Could not resolve location of module 'std/stdio' 2025-07-21T15:30:59.455 [warning] first.d:474:visit Could not resolve location of module 'std/getopt' 2025-07-21T15:30:59.455 [warning] first.d:474:visit Could not resolve location of module 'std/json' 2025-07-21T15:30:59.455 [warning] first.d:474:visit Could not resolve location of module 'config' 2025-07-21T15:30:59.455 [warning] first.d:474:visit Could not resolve location of module 'std/file' ```
Jul 21
parent reply Luna <luna foxgirls.gay> writes:
On Monday, 21 July 2025 at 14:32:49 UTC, Albert wrote:
 On Monday, 21 July 2025 at 14:16:29 UTC, Luna wrote:
 [...]
Thank you. This seems to have worked better! Though I am still getting errors: ``` Could not initialize DCD for ``` and in the output get a lot of: ``` 2025-07-21T15:30:59.455 [warning] first.d:474:visit Could not resolve location of module 'std/stdio' 2025-07-21T15:30:59.455 [warning] first.d:474:visit Could not resolve location of module 'std/getopt' 2025-07-21T15:30:59.455 [warning] first.d:474:visit Could not resolve location of module 'std/json' 2025-07-21T15:30:59.455 [warning] first.d:474:visit Could not resolve location of module 'config' 2025-07-21T15:30:59.455 [warning] first.d:474:visit Could not resolve location of module 'std/file' ```
The script works by adding a special startup script to your shell session; as such you may need to restart your mac for it to fully work.
Jul 21
parent reply Albert <albeva me.com> writes:
On Monday, 21 July 2025 at 16:24:31 UTC, Luna wrote:
 The script works by adding a special startup script to your 
 shell session; as such you may need to restart your mac for it 
 to fully work.
I've tried everything I can think of, now getting the following errors: ``` Could not initialize dub for /Users/albert/Developer/lbc-d. Falling back to limited functionality! Cannot use dub with invalid configuration, cannot list import paths needed for build and auto-complete. Selected config: '' (targetType: autodetect) - available: ["application", "library"] Try selecting a different configuration. ``` Sorry to be blunt, but not great first impression so far. I'm still trying to make this work, but stuck with no clue...
Jul 21
parent reply Albert <albeva me.com> writes:
On Monday, 21 July 2025 at 16:42:31 UTC, Albert wrote:
 Sorry to be blunt, but not great first impression so far. I'm 
 still trying to make this work, but stuck with no clue...
I think setting sodlib path in settings helped somewhat. At least errors are gone and seems to have detected the build type and compiler. How do I build & run the executable though?
Jul 21
parent reply Albert <albeva me.com> writes:
On Monday, 21 July 2025 at 17:08:17 UTC, Albert wrote:
 How do I build & run the executable though?
Anyway with some perseverance I managed to build & run hello world app. Thank you guys for your help. Though I do think D could do so much better with onboarding first time users...
Jul 21
parent Sergey <kornburn yandex.ru> writes:
On Monday, 21 July 2025 at 17:21:58 UTC, Albert wrote:
 On Monday, 21 July 2025 at 17:08:17 UTC, Albert wrote:
 How do I build & run the executable though?
Anyway with some perseverance I managed to build & run hello world app. Thank you guys for your help. Though I do think D could do so much better with onboarding first time users...
which is kinda unusual you installing LDC (it is going with Dub) run `dub init` then write code then `dub build` and it works
Jul 21
prev sibling parent reply Albert <albeva me.com> writes:
On Monday, 21 July 2025 at 14:10:44 UTC, Serg Gini wrote:
 Also don't forget to switch the version of the "code-d" 
 extension to "beta/nightly". Stable is very old and not 
 updating properly.
Thanks, how do I get the beta/nightly version? Only one I see is 0.23.1 from 2021. Thanks
Jul 21
parent Mike Parker <aldacron gmail.com> writes:
On Monday, 21 July 2025 at 14:25:57 UTC, Albert wrote:

 Thanks, how do I get the beta/nightly version? Only one I see 
 is 0.23.1 from 2021. Thanks
It's an option in the code-d extension settings.
Jul 21
prev sibling next sibling parent Christian =?UTF-8?B?S8O2c3RsaW4=?= <christian.koestlin gmail.com> writes:
On Monday, 21 July 2025 at 13:29:23 UTC, Albert wrote:
 Hi all,

 I am completely new to D, wished to try it out and write a 
 small app in it. However, for the last couple hours I am ready 
 to pull my hair out as I have no idea how to compile even a 
 simplest hello world app.

 I installed ldc and dub (nowhere on the download page did it 
 even mention that dub should be installed separately!) from 
 home-brew, installed code-d for vscode, used the plugin to 
 create a new project and that is as far as I've gotten.

 For example the plugin prompts me to "Compile serve-d", however 
 doing so just fails with:

 ```
 Error Command failed with exit code 127: rdmd 
 "/Users/albert/.dub/packages/dfmt/0.14.1/dfmt/dubhash.d"
 Failed to install serve-d (Error code 2)
 ```

 And so on and so forth. Am I missing something obvious?
Mhh ... imho the install.sh on the homepage is not pushed enough. For me this is the best (for installing the compiler and dub and the tools that come with it). For Apple Silicon ldc is the best choice (again imho). After sourcing the activate script in the respective folder (default ~/dlang/COMPILER_VERSION/activate(.fish)) you are setup nicely with dub, so `dub init`, `dub run` should work directly. VSCode I am not so familiar with. Kind regards, Christian
Jul 23
prev sibling parent reply Brian Callahan <bcallah openbsd.org> writes:
On Monday, 21 July 2025 at 13:29:23 UTC, Albert wrote:
 Hi all,

 I am completely new to D, wished to try it out and write a 
 small app in it. However, for the last couple hours I am ready 
 to pull my hair out as I have no idea how to compile even a 
 simplest hello world app.

 I installed ldc and dub (nowhere on the download page did it 
 even mention that dub should be installed separately!) from 
 home-brew, installed code-d for vscode, used the plugin to 
 create a new project and that is as far as I've gotten.

 For example the plugin prompts me to "Compile serve-d", however 
 doing so just fails with:

 ```
 Error Command failed with exit code 127: rdmd 
 "/Users/albert/.dub/packages/dfmt/0.14.1/dfmt/dubhash.d"
 Failed to install serve-d (Error code 2)
 ```

 And so on and so forth. Am I missing something obvious?
I know you got things going with LDC, but I use GDC for all my D needs on macOS. I have a tarball that's a simple extract, add to PATH, and done: https://github.com/ibara/aarch64-apple-darwin24.2.0-gcc-14.2.0/releases/tag/20250112
Jul 23
parent Serg Gini <kornburn yandex.ru> writes:
On Wednesday, 23 July 2025 at 14:12:30 UTC, Brian Callahan wrote:
 I know you got things going with LDC, but I use GDC for all my 
 D needs on macOS. I have a tarball that's a simple extract, add
When I tried it last time - it was magnitude slower than LDC solution
Jul 23