D Programming language installation how to.

Discussion in general that pertains to Sabayon Linux - Must Pertain to Sabayon Linux

Moderator: Moderators

D Programming language installation how to.

Postby Douglas_E_Knapp » Wed Feb 07, 2018 22:48

What is the proper or best way to install the D programming language? I see it in Gentoo but having no luck with Sabayon.

https://wiki.gentoo.org/wiki/Dlang
Douglas_E_Knapp
Growing Hen
 
Posts: 113
Joined: Sat Nov 03, 2012 8:53

Re: D Programming language installation how to.

Postby flexoron » Sat Feb 10, 2018 12:59

The best way installing things depends on how easy it is to get rid of it afterwards.
In this case use your HOME directory:
$ cd
$ curl -fsS https://dlang.org/install.sh | bash -s dmd
$ source ~/dlang/dmd-2.078.2/activate
$ mkdir dtst && cd dtst && vi hello.d

import std.stdio;

void main()
{
writeln("Hello and Goodbye, World!");
}

$ dmd hello.d
$ ./hello
Hello and Goodbye, World!
$ cd
$ rm -rf dlang
flexoron
Baby Hen
 
Posts: 19
Joined: Tue Sep 26, 2017 23:17

Re: D Programming language installation how to.

Postby flexoron » Mon Feb 12, 2018 23:54

Now the fun part:
Lets imagine we want developing the latest greatest brandnew
Fiber/Multithreaded/Multicore/Distributed D-Web-Application.
One way doing this is using vibe.d (vibed.org)

Because Sabayon is a great end-user experience,
developers should not pollute the main environment.
We will see in a moment.
So we installed dmd in our HOME directory. So far so good.
Now we install vibe.d
$ cd && cd dtst
$ dub init webchat -t vibe.d
$ cd webchat
Because we are developers we should use the latest build.
Substitute 0.7.something with 0.8 in this file:
$ vi dub.json
"vibe-d": "~>0.8"
$ dub upgrade
Fetching ...
$ dub
Performing ...
Linking...
../../.dub/packages/vibe-d-0.8.2/vibe-d/core/.dub/build/libevent-debug-linux.posix-x86_64-dmd_2078-256332B
37907A30EEE4B75CB39C60BA1/libvibe-d_core.a(libevent2_1793_5d7.o): In function `_D4vibe4core7drivers9libeve
nt215Libevent2Driver6__ctorMFNbNeCQChQCf6driver10DriverCoreZCQDiQDgQDeQCzQCs':
/home/user/dtst/webchat/../../.dub/packages/vibe-d-0.8.2/vibe-d/core/vibe/core/drivers/libevent2.d:132: un
defined reference to `event_set_mem_functions'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
/home/user/dlang/dmd-2.078.2/linux/bin64/dmd failed with exit code 1.

HOLAOHA
Something went wrong here. It turns out that the library 'libevent',
factory-provided by Sabayon, is not prepared to satisfy vibe.d

How to avoid polluting the main system?
We should not just upgrade Sabayon's libevent because we do not know what else will break then.
So we make our own libevent for vibe.d:
$ cd ~/dtst
$ git clone https://github.com/libevent/libevent.git
$ cd libevent && mkdir build && cd build
$ cmake ..
$ make
$ cd lib
Here is what we need but where to put?
Something helps us here.
dmd has its own lib64 directory. Thats great!
$ tar cf - . | ( cd ~/dlang/dmd-2.078.2/linux/lib64 ; tar xf - )
$ cd ~/dtst/webchat
$ dub --force
Linking...
Running ./webchat
Listening for requests on http://[::1]:8080/
Listening for requests on http://127.0.0.1:8080/
Please open http://127.0.0.1:8080/ in your browser.

Thats really cool! We don't have to change/break Sabayon's installation.
D Programming, a well thought-out plan.
flexoron
Baby Hen
 
Posts: 19
Joined: Tue Sep 26, 2017 23:17

Re: D Programming language installation how to.

Postby Douglas_E_Knapp » Tue Feb 13, 2018 18:22

Very cool and a lot to learn from! Thanks for that!
Douglas_E_Knapp
Growing Hen
 
Posts: 113
Joined: Sat Nov 03, 2012 8:53

Re: D Programming language installation how to.

Postby flexoron » Thu Feb 15, 2018 0:50

You welcome!

Be aware that this was just a quick solution having vibe.d at work.

There are still problems.

Assume we did not source.../activate the compiler
Code: Select all
$ cd ~/dtst/webchat
$ ./webchat
./webchat: error while loading shared libraries
$ ldd webchat | grep libevent.so
libevent.so.2.2.0 => not found
$ source ~/dlang/dmd-2.078.2/activate
$ ldd webchat | grep libevent.so
libevent.so.2.2.0 => /home/user/dlang/dmd-2.078.2/linux/lib64/libevent.so.2.2.0 (0x00007f575a1f0000)

Not a good idea to 'activate' the compiler environment for just running the application.

Next step is to change the setup again a bit.
Open a new terminal and don't source.../activate the compiler
Create a 'running' mylib64 for the application.
It is just a collection of libs we built so far.
Code: Select all
$ cd ~/dtst && mkdir mylib64
$ cd ~/dtst/libevent/build/lib
$ tar cf - . | ( cd ~/dtst/mylib64 ; tar xf - )

$ cd ~/dtst/webchat
$ export LD_LIBRARY_PATH=~/dtst/mylib64:$LD_LIBRARY_PATH
$ ldd webchat | grep libevent.so
libevent.so.2.2.0 => /home/user/dtst/mylib64/libevent.so.2.2.0 (0x00007fedc6cc8000)
$ ./webchat
Listening ...
Please open ...

This is a bit better now.

Unfortunately, for a reason I don't know yet, we cannot use mylib64 for the build process.
Open a new terminal and remove libevent from ~/dlang/dmd-2.078.2/linux/lib64 before you try this step.
***This does not work***

Code: Select all
$ export LD_LIBRARY_PATH=~/dtst/mylib64:$LD_LIBRARY_PATH
$ source ~/dlang/dmd-2.078.2/activate
$ cd ~/dtst/webchat
$ rm webchat
$ dub --force
Linking ...
Error: linker exited with status 1
*****************************

Preparing dmd for Sabayon's libevent update.
We should always try to use what the main environment provides.

[[--
I guess you did not remove libevent from ~/dlang/dmd-2.078.2/linux/lib64.
If so you must copy back again:
Code: Select all
cd ~dtst/libevent/build/lib && tar cf - . | ( cd ~/dlang/dmd-2.078.2/linux/lib64 ; tar xf - )
--]]
$ cd ~/dlang/dmd-2.078.2/linux
$ mkdir mylib64
$ mkdir dmdlib64
$ cd lib64



Copy everything into mylib64
Code: Select all
$ tar cf - . | ( cd ../mylib64 ; tar xf - )

Remove libevent
Code: Select all
$ rm libevent*

Copy dmd-libs into dmdlib64
Code: Select all
$ tar cf - . | ( cd ../dmdlib64 ; tar xf - )
# remove lib64
$ rm -rf lib64



Initial Situation
Sabayon's libevent still not updated
Code: Select all
$ mv mylib64 lib64




Sabayon provides new libevent
Code: Select all
$ mv lib64 mylib64
$ mv dmdlib64 lib64
$ cd ~/dtst/webchat
$ rm webchat
$ source ~/dlang/dmd-2.078.2/activate # if not done already
$ dub --force
Linking ...
Error: linker exited with status 1



Aha still not working

Rollback
Code: Select all
$ cd ~/dlang/dmd-2.078.2/linux
$ mv lib64 dmdlib64
$ mv mylib64 lib64



Btw changing the 'activate' script also doesn't work.
***This does not work***
Code: Select all
$ vi ~/dlang/dmd-2.078.2/active

orig:
Code: Select all
export LIBRARY_PATH=".../lib64..."
export LD_LIBRARY_PATH=".../lib64..."



new:
Code: Select all
export LIBRARY_PATH=".../mylib64..."
export LD_LIBRARY_PATH=".../mylib64..."
*****************************



Remember, this is just a quick and dirty patch.

Clearly the best solution is having Rigo being dlang-aware but this is a task for specialists.
flexoron
Baby Hen
 
Posts: 19
Joined: Tue Sep 26, 2017 23:17

Re: D Programming language installation how to.

Postby sabayonino » Thu Feb 15, 2018 12:44

please, provide your outputs/commands using the "code" button
Thanks
[Che Cos'è Il Calcolo Distribuito (BOINC)

BOINC ready ! Sabayon+BOINC = BILD ,my Sabayon spin :cyclops: - Ready to crunch for the Science everywhere :)
User avatar
sabayonino
Sagely Hen
 
Posts: 3154
Joined: Sun Sep 21, 2008 1:12
Location: Italy

Re: D Programming language installation how to.

Postby flexoron » Fri Feb 16, 2018 1:13

Ok, thanks for the hint.

Here is a slightly better solution.
Sometimes it is good to know of different approaches.
Cleanup dmd lib64, remove libevent
Code: Select all
cd ~/dlang/dmd-2.078.2/linux/lib64 && rm -f libevent*


1. Open a new terminal:
Edit project-file dub.json, add "lflags"
Export LD_LIBRARY_PATH and source.../activate compiler
Code: Select all
cd ~/dtst/webchat
ex dub.json <<EX
/{/a
"lflags": ["-L$HOME/dtst/mylib64"],
.
w
EX

export LD_LIBRARY_PATH=~/dtst/mylib64:$LD_LIBRARY_PATH
source ~/dlang/dmd-2.078.2/activate
dub --force
 

2. Open a new terminal:
Just running the application, no compiler activated
Code: Select all
cd ~/dtst/webchat
export LD_LIBRARY_PATH=~/dtst/mylib64:$LD_LIBRARY_PATH
./webchat
 

3. Open a new terminal:
Testing Sabayon's libevent update
Do not set LD_LIBRARY_PATH
Edit dub.json, delete "lflags" path
Code: Select all
cd ~/dtst/webchat
ex dub.json <<EX
/lflags/d
.
w
EX
source ~/dlang/dmd-2.078.2/activate
dub --force
 

Linking...undefined reference to `event_set_mem_functions'
Error: linker exited with status 1

Goto 1. Open a new terminal

Maybe we should ask Sabayon now.It seems that
/usr/lib64/libevent-2.1.so.6.0.2
is built without 'event_set_mem_functions'?
flexoron
Baby Hen
 
Posts: 19
Joined: Tue Sep 26, 2017 23:17

Re: D Programming language installation how to.

Postby flexoron » Sun Feb 18, 2018 1:23

In the meantime dmd has been updated.
New version: dmd-2.078.3
Just cut n paste commands from above might not work any longer.
flexoron
Baby Hen
 
Posts: 19
Joined: Tue Sep 26, 2017 23:17

Re: D Programming language installation how to.

Postby flexoron » Sat Mar 03, 2018 18:24

Again dmd has been updated: dmd-2.079.0
vibe.d-0.8.2 does not compile with this version.
There are know issues which get fixed soon.
vibe.d-0.8.3-beta.1 is back on track.

Code: Select all
cd $HOME
curl -fsS https://dlang.org/install.sh | bash -s dmd
export LD_LIBRARY_PATH=~/dtst/mylib64:$LD_LIBRARY_PATH
source ~/dlang/dmd-2.079.0/activate
cd $HOME/dtst/webchat
ex dub.json <<'EX'
/vibe-d/d
i
                "vibe-d": "~>0.8.3-beta.1"
.
w
EX

mv $HOME/.dub/packages $HOME/.dub/packages-2.078.3
rm webchat
dub upgrade
dub --force


Linking...
Running ./webchat
flexoron
Baby Hen
 
Posts: 19
Joined: Tue Sep 26, 2017 23:17


Return to Sabayon Linux General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest