ldc-developers / ldc2.snap

Snap package definition for LDC, the LLVM-based D compiler
11 stars 4 forks source link

Add MULTILIB support to the LDC build #32

Closed WebDrake closed 7 years ago

WebDrake commented 7 years ago

This should ensure that both 32- and 64-bit libraries are available in the snap package, whatever the target architecture of the build.

Submitted against the 1.1 branch, with the aim that it be merged into all higher-version branches.

WebDrake commented 7 years ago

As it stands, the build of this is failing:

In file included from /usr/include/stdio.h:27:0,
                 from /build_ldc2/parts/ldc-bootstrap/src/runtime/phobos/etc/c/zlib/gzguts.h:21,
                 from /build_ldc2/parts/ldc-bootstrap/src/runtime/phobos/etc/c/zlib/gzclose.c:6:
/usr/include/features.h:367:25: fatal error: sys/cdefs.h: No such file or directory
compilation terminated.
runtime/CMakeFiles/phobos2-ldc_32.dir/build.make:1682: recipe for target 'runtime/CMakeFiles/phobos2-ldc_32.dir/phobos/etc/c/zlib/gzclose.c.o' failed
make[2]: *** [runtime/CMakeFiles/phobos2-ldc_32.dir/phobos/etc/c/zlib/gzclose.c.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /usr/include/limits.h:25:0,
                 from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h:168,
                 from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h:34,
                 from /build_ldc2/parts/ldc-bootstrap/src/runtime/phobos/etc/c/zlib/zconf.h:395,
                 from /build_ldc2/parts/ldc-bootstrap/src/runtime/phobos/etc/c/zlib/zlib.h:34,
                 from /build_ldc2/parts/ldc-bootstrap/src/runtime/phobos/etc/c/zlib/zutil.h:22,
                 from /build_ldc2/parts/ldc-bootstrap/src/runtime/phobos/etc/c/zlib/deflate.h:16,
                 from /build_ldc2/parts/ldc-bootstrap/src/runtime/phobos/etc/c/zlib/trees.c:37:
/usr/include/features.h:367:25: fatal error: sys/cdefs.h: No such file or directory
compilation terminated.
In file included from /usr/include/limits.h:25:0,
                 from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h:168,
                 from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h:34,
                 from /build_ldc2/parts/ldc-bootstrap/src/runtime/phobos/etc/c/zlib/zconf.h:395,
                 from /build_ldc2/parts/ldc-bootstrap/src/runtime/phobos/etc/c/zlib/zlib.h:34,
                 from /build_ldc2/parts/ldc-bootstrap/src/runtime/phobos/etc/c/zlib/zutil.h:22,
                 from /build_ldc2/parts/ldc-bootstrap/src/runtime/phobos/etc/c/zlib/infback.c:13:
/usr/include/features.h:367:25: fatal error: sys/cdefs.h: No such file or directory
compilation terminated.
runtime/CMakeFiles/phobos2-ldc_32.dir/build.make:1634: recipe for target 'runtime/CMakeFiles/phobos2-ldc_32.dir/phobos/etc/c/zlib/trees.c.o' failed
make[2]: *** [runtime/CMakeFiles/phobos2-ldc_32.dir/phobos/etc/c/zlib/trees.c.o] Error 1
runtime/CMakeFiles/phobos2-ldc_32.dir/build.make:1610: recipe for target 'runtime/CMakeFiles/phobos2-ldc_32.dir/phobos/etc/c/zlib/infback.c.o' failed
make[2]: *** [runtime/CMakeFiles/phobos2-ldc_32.dir/phobos/etc/c/zlib/infback.c.o] Error 1

I presume this is down to an absence of 32-bit dependencies for druntime/phobos. I'm going to try adding lib32c-dev and lib64c-dev as build dependencies.

WebDrake commented 7 years ago

... make that gcc-multilib and g++-multilib (for ldc and ldc-bootstrap respectively).

WebDrake commented 7 years ago

Updated the patch to include gcc-multilib and g++-multilib:

diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
index 8540c34..0c8dc39 100644
--- a/snap/snapcraft.yaml
+++ b/snap/snapcraft.yaml
@@ -40,7 +40,7 @@ parts:
     stage:
     - -etc/ldc2.conf
     build-packages:
-    - gcc
+    - gcc-multilib
     - libconfig++-dev
     - libedit-dev
     - zlib1g-dev
@@ -69,7 +69,7 @@ parts:
     prime:
     - -*
     build-packages:
-    - g++
+    - g++-multilib
     - libconfig++-dev
     - libedit-dev
     - zlib1g-dev

This is sufficient to ensure the package builds, but not that it is actually able to use the extra libraries, because ldc2.conf does not provide any path to the 32-bit libs.

Merely adding an extra -L-L option will work, but results in a warning every time ldc2 is run, e.g.:

$ ldmd2 -m32 -L-L/snap/ldc2/current/lib32/ hello.d
/usr/bin/ld: skipping incompatible /snap/ldc2/x1/bin/../lib/libphobos2-ldc.a when searching for -lphobos2-ldc
/usr/bin/ld: skipping incompatible /snap/ldc2/x1/bin/../lib/libdruntime-ldc.a when searching for -ldruntime-ldc
WebDrake commented 7 years ago

Updated to include the ldc2.conf changes needed to support this:

diff --git a/ldc-config/ldc2.conf b/ldc-config/ldc2.conf
index 031dd83..58e3709 100644
--- a/ldc-config/ldc2.conf
+++ b/ldc-config/ldc2.conf
@@ -10,6 +10,9 @@ default:
         "-I%%ldcbinarypath%%/../include/d/ldc",
         "-I%%ldcbinarypath%%/../include/d",
         "-L-L%%ldcbinarypath%%/../lib",
+        "-L-L%%ldcbinarypath%%/../lib32",
+        "-L-L%%ldcbinarypath%%/../lib64",
+        "-L--no-warn-search-mismatch",
         "-defaultlib=phobos2-ldc,druntime-ldc",
         "-debuglib=phobos2-ldc-debug,druntime-ldc-debug"
     ];
WebDrake commented 7 years ago

This patch has also been merged into the 1.2 and 1.3 branches.