Artifact 63a035291466f4616b5335f135a011eaedeaaed9043461804348302a970193ce:

Wiki page [D on OpenBSD] by admin 2021-10-13 05:40:46.
D 2021-10-13T05:40:46.519
L D\son\sOpenBSD
P 9f74452e356d87a36ec15cb8b5bb79a0dbba7a4f93d5c62b0b0ebb5d458b7672
U admin
W 3584
<h2>D on OpenBSD</h2>

<h3>Step 1: do a normal install OpenBSD 6.9.</h3>

If you're installing a later version, you can probably skip step #2.

<h3>Step 2: update to OpenBSD-current from 6.9</h3>

<verbatim>
# sysupgrade -s
</verbatim>

<h3>Step 3: install gdc</h3>

<verbatim>
# pkg_add gdc
</verbatim>

<h3>Step 4: add 'gdc' to your PATH</h3>

<verbatim>
$ mkdir ~/bin
$ ln -s /usr/local/bin/egdc ~/bin/gdc
</verbatim>

<h3>Step 5: add 'gdmd' to your PATH</h3>

<verbatim>
# pkg_add git
$ mkdir ~/dlang
$ cd ~/dlang
$ git clone https://github.com/D-Programming-GDC/gdmd
$ cp -pv gdmd/dmd-script ~/bin
</verbatim>

To make these available to any user on the system, /usr/local/bin's a better directory. Just note that the math/gbc package also tries to install a /usr/local/bin/gdc

<h3>Step 6: raise user memory limits</h3>

If you don't want to have to compile D programs as root. The defaults are too low for building dub in particular.

<verbatim>
# cat >> /etc/login.conf <<'EOF'

# 
# Login class for users that will be building D programs.
# 
dmd:\
        :datasie-cur=infinity:\
        :datasize-max=infinity:\
        :tc=staff:

EOF
# usermod -L dmd USER
</verbatim>

You'll may need to log out and log back in to get a session with the new limits. On a desktop with 32GB of RAM and 32GB of swap, 'ulimit -a' reported a data(kbytes) value of 32GB.

<h3>Step 7: build and install dub</h3>

<verbatim>
$ cd ~/dlang
$ git clone https://github.com/dlang/dub
$ cd dub
$ gdc -O -o build build.d
$ ./build
Building dub using gdmd (dflags: ["-g", "-O", "-w"]), this may take a while...
DUB has been built as: /home/USER/dlang/dub/bin/dub
You may want to run `sudo ln -s /home/USER/dlang/dub/bin/dub /usr/local/bin` now
</verbatim>

<h3>Step 8: confirm dub actually works</h3>

... presently, most functions segfault pretty early on.

<verbatim>
$ echo 'void main(){writeln("test");}' | dub -q run dfmt -- --brace_style=otbs 
Segmentation fault (core dumped) 
</verbatim>

<h3>Step 9: get D tools</h3>

The OpenBSD gdc package just gives you an 'egdc' bin. You'll probably want at least ddemangle and rdmd

<verbatim>
$ cd ~/dlang
$ git clone https://github.com/dlang/tools
$ cd tools
$ perl -i -lpe 's/"-v", // if /-v.*rootModule/' rdmd.d 
$ gdc -O2 -o ~/bin/rdmd rdmd.d
$ rdmd --eval 'writeln("it works")'          
it works
$ gdc -O2 -o ~/bin/ddemangle ddemangle.d
$ objdump -dwr --no-show-raw-insn ~/bin/rdmd|egrep -m1 std.conv 
  18f72d:       jmp    18f730 <_D3std4conv__T10emplaceRefTAyaTQeTQhZQxFKQoKQrZ1S9__xtoHashFNbNeKxSQCnQCm__TQCkTQCbTQCfTQCjZQDaFKQCsKQCwZQCgZm>
shadow$ objdump -dwr --no-show-raw-insn ~/bin/rdmd|egrep -m1 std.conv|ddemangle
  18f72d:       jmp    18f730 <nothrow @trusted ulong std.conv.emplaceRef!(immutable(char)[], immutable(char)[], immutable(char)[]).emplaceRef(ref immutable(char)[], ref immutable(char)[]).S.__xtoHash(ref const(std.conv.emplaceRef!(immutable(char)[], immutable(char)[], immutable(char)[]).emplaceRef(ref immutable(char)[], ref immutable(char)[]).S))>
</verbatim>

That perl line strips a -v (verbose) flag out of the command that rdmd passes to gdmd. I haven't looked into why this produces tons of noisy output on OpenBSD but not on Linux, but it's probably a bug.

<h3>Step 10: build dmd?</h3>

It fails right now, but why not give it a try?

<verbatim>
# pkg_add gmake
$ cd ~/dlang
$ for x in dmd druntime phobos; do git clone https://github.com/dlang/$x; done
$ ( cd dmd; HOST_DMD=gdmd gmake -f posix.mak )
$ ( cd druntime; HOST_DMD=gdmd gmake -f posix.mak )
$ ( cd phobos; HOST_DMD=gdmd gmake -f posix.mak )
</verbatim>
Z 95e51e8d622cb7ad294484dfc73acb48