[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#859177: meson is unuseable for package cross compilation



Hi,

I took a while to reply for a number of reasons:
 * There wasn't anything left to disagree with.
 * Testing debcrossgen.py was difficult due to #859173.

In the mean time:
 * ninja-build is marked M-A:foreign (i.e. #859173 is fixed).
 * systemd can be built with meson.
 * The Debian systemd package is built with meson.

=> We have a test case!

So I went ahead and tried making it cross compile.

On Sun, Apr 02, 2017 at 07:50:33PM +0300, Jussi Pakkanen wrote:
> Attached is a simple script that generates a cross file that works for
> me when using a simple project. Use it like this:
> 
> ./debcrossgen.py armhf generated_cross.txt
> 
> And then pass --libdir=lib/archdir_here --cross-file
> generated_cross.txt to Meson to use it.
> 
> It only takes care of host, not target. Consider it an MVP. :)

That looks like a very good start.

I dropped that script into systemd's Debian packaging with slight
modifications and made systemd execute it during cross compilation. I
annotated the Build-Depends: meson with :native (which is accepted by
sbuild) and cheated dpkg-buildpackage with -d. To my surprise, systemd
just cross built successfully on the first attempt. The patch is
attached, but it is not meant to be applied to systemd. It just serves
as a proof of feasibility.

Essentially there are three issues that need fixing to make this work
properly:
 1. Dependencies on meson need to become cross-satisfiable. We discussed
    that already and essentially concluded that meson should follow
    cmake and become M-A:foreign. Any objections?
 2. The debcrossgen.py script needs some place to live. When debhelper
    and meson are installed together, it needs to be in the filesystem.
    An easy approach to do so is to put it into the meson binary
    package. We should probably spend a little discussing bike shedding
    questions such as:
     a. What path/filename to use?
     b. What options/arguments should it take?
 3. debhelper needs to call debcrossgen.py during cross compilation and
    add the --cross-file option. This one is straight forward to
    implement once the questions from 2. are answered.

Would it make sense to split this bug report into three?

So let's focus on debcrossgen.py. I'm not sure whether it needs to live
on $PATH. Due to its use of dpkg-architecture the script is probably
useless on non-Debian systems. I think passing the architecture should
be optional or disabled: dpkg-architecture looks up the host
architecture from the environment. When dropping the architecture from
the command line, "./debcrossgen.py armhf output.txt" becomes
"dpkg-architecture -aarmhf -c ./debcrossgen.py output" and while
building a package, those environment variables are already set up
correctly. Optimizing for the common case means not requesting the
architecture name.

The output of debcrossgen.py still is subtly wrong for a number of
architectures including armhf, musl-linux-mips, kfreebsd-amd64,
hurd-i386 and a few more. I think that's ok. We should start shipping it
and fix the output later. That's what we did for cmake (in debhelper)
and it worked well.

Helmut
diff --minimal -Nru systemd-234/debian/changelog systemd-234/debian/changelog
--- systemd-234/debian/changelog	2017-07-20 15:13:42.000000000 +0200
+++ systemd-234/debian/changelog	2017-07-27 21:50:40.000000000 +0200
@@ -1,3 +1,10 @@
+systemd (234-2.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * 
+
+ -- Helmut Grohne <helmut@subdivi.de>  Thu, 27 Jul 2017 21:50:40 +0200
+
 systemd (234-2) unstable; urgency=medium
 
   [ Martin Pitt ]
diff --minimal -Nru systemd-234/debian/control systemd-234/debian/control
--- systemd-234/debian/control	2017-07-20 15:13:42.000000000 +0200
+++ systemd-234/debian/control	2017-07-27 21:50:39.000000000 +0200
@@ -16,7 +16,7 @@
                docbook-xsl,
                docbook-xml,
                m4,
-               meson (>= 0.40.0),
+               meson:native (>= 0.40.0),
                intltool,
                gperf,
                gnu-efi [amd64 i386 arm64],
diff --minimal -Nru systemd-234/debian/debcrossgen.py systemd-234/debian/debcrossgen.py
--- systemd-234/debian/debcrossgen.py	1970-01-01 01:00:00.000000000 +0100
+++ systemd-234/debian/debcrossgen.py	2017-07-27 21:50:40.000000000 +0200
@@ -0,0 +1,48 @@
+#!/usr/bin/env python3
+
+# Copyright 2017 Jussi Pakkanen
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+#     http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import sys, os, subprocess
+
+def run():
+    output = subprocess.check_output(['dpkg-architecture'], universal_newlines=True)
+    data = {}
+    for line in output.split('\n'):
+        line = line.strip()
+        if line == '':
+            continue
+        k, v = line.split('=', 1)
+        data[k] = v
+    host_arch = data['DEB_HOST_GNU_TYPE']
+    host_os = data['DEB_HOST_ARCH_OS']
+    host_cpu_family = data['DEB_HOST_GNU_CPU']
+    host_cpu = data['DEB_HOST_ARCH'] # Not really correct, should be arm7hlf etc but it is not exposed.
+    host_endian = data['DEB_HOST_ARCH_ENDIAN']
+    ofile = sys.stdout
+    ofile.write('[binaries]\n')
+    ofile.write("c = '/usr/bin/%s-gcc-6'\n" % host_arch)
+    ofile.write("cpp = '/usr/bin/%s-g++-6'\n" % host_arch)
+    ofile.write("ar = '/usr/bin/%s-ar'\n" % host_arch)
+    ofile.write("strip = '/usr/bin/%s-strip'\n" % host_arch)
+    ofile.write("pkgconfig = '/usr/bin/%s-pkg-config'\n" % host_arch)
+    ofile.write('\n[properties]\n')
+    ofile.write('\n[host_machine]\n')
+    ofile.write("system = '%s'\n" % host_os)
+    ofile.write("cpu_family = '%s'\n" % host_cpu_family)
+    ofile.write("cpu = '%s'\n" % host_cpu)
+    ofile.write("endian = '%s'\n" % host_endian)
+
+if __name__ == '__main__':
+    run()
diff --minimal -Nru systemd-234/debian/rules systemd-234/debian/rules
--- systemd-234/debian/rules	2017-07-20 15:13:42.000000000 +0200
+++ systemd-234/debian/rules	2017-07-27 21:50:40.000000000 +0200
@@ -64,6 +64,10 @@
 	-Dnobody-user=nobody \
 	-Dnobody-group=nogroup
 
+ifneq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
+CONFFLAGS += --cross-file ../crossfile.txt
+endif
+
 # resolved's DNSSEC support is still not mature enough, don't enable it by
 # default on stable Debian or any Ubuntu releases
 CONFFLAGS += $(shell grep -qE 'stretch|ubuntu' /etc/os-release && echo -Ddefault-dnssec=no)
@@ -145,6 +149,9 @@
 	-Dsysusers=false
 
 override_dh_auto_configure:
+ifneq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
+	python3 debian/debcrossgen.py > crossfile.txt
+endif
 	dh_auto_configure --builddirectory=build-deb \
 		-- $(CONFFLAGS) $(CONFFLAGS_deb)
 ifeq (, $(filter noudeb, $(DEB_BUILD_PROFILES)))
@@ -180,7 +187,7 @@
 ifeq (, $(filter noudeb, $(DEB_BUILD_PROFILES)))
 	dh_auto_clean --builddirectory=build-udeb
 endif
-	rm -rf debian/install/ debian/shlibs.local
+	rm -rf debian/install/ debian/shlibs.local crossfile.txt
 	# remove Python byte code files
 	rm -rf tools/__pycache__/
 

Reply to: