Snapping LDC (LLVM-based D compiler)

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Wed Aug 31 19:35:44 UTC 2016


On 30.08.2016 06:18, Andrew Wilkins wrote:
> Actually, editing the files isn't necessary at all. You can just pass the
> --sysroot option to gcc. I just hacked up a quick gcc snap which works:
>     https://gist.github.com/axw/1d4b0206e11ff46a26439244224a4cc9

Cool stuff.  As a gcc snap, this works for me; note you can use --sysroot=$SNAP 
for portability.

> If you can convince ldc2 to pass the same option (/etc/ldc2.conf?), then it
> should just work.

Unfortunately, it looks like there are some complications here :-\  Let's start 
with my snapcraft.yaml:
https://gist.github.com/WebDrake/e4ec1d1065df3011bf88f69a0c00544a

... which defines commands for both gcc and ld, both with the --sysroot=$SNAP 
option.

First things first, run `snapcraft stage`.  Then edit the auto-generated 
stage/etc/ldc2.conf and replace it with this:
https://gist.github.com/WebDrake/229645efeca14fa54b0b1c82bcbb6477

... which as you can see includes a compiler flag: `-gcc=ldc2.gcc`.  This should 
ensure that ldc2.gcc is called when LDC wants to call GCC.

Now we can run `snapcraft snap` to finish up, and we can install the resulting 
snap package.

OK, let's create a simple Hello World in D:

////////////////////
void main ()
{
     import std.stdio : writeln;
     writeln("Hello, snappy LDC!");
}
////////////////////

Now, let's try to build it, using the -v flag so that it'll output all that it does:

     ldc2.ldmd2 -v hello.d

... and much follows, concluding with:

/snap/ldc2/x1/usr/bin/gcc hello.o -o hello -L/snap/ldc2/x1/bin/../lib 
-lphobos2-ldc -ldruntime-ldc -Wl,--gc-sections -lrt -ldl -lpthread -lm -m64
/snap/ldc2/x1/usr/bin/ld: cannot find 
/usr/lib/x86_64-linux-gnu/libpthread_nonshared.a
collect2: error: ld returned 1 exit status
Error: /snap/ldc2/x1/usr/bin/gcc failed with status: 1

... which is very odd; it suggests that despite explicitly asking for `ldc2.gcc` 
to be called (which would use the --sysroot flag), it's somehow not.

I've tried testing by running the "normal" apt-installed ldc and passing the 
-gcc=ldc2.gcc option, and this works just fine, which makes me wonder: could 
something weird be happening which is causing the ldc2.gcc command to be 
"de-aliased" if it's run from within the snap itself?

Thanks & best wishes,

     -- Joe




More information about the Snapcraft mailing list