Permalink
Browse files

HACK: Allow cross-compiling with qemu-user

Get qemu-arm-static from:
https://github.com/rtaubes/fedora-qemu-arm-static
(better, from the upcoming RPMs)

 # echo ":qemu-arm-static:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/app/bin/flatpak-arch-emulator:" > /usr/lib/binfmt.d/qemu-arm-static.conf

 # systemctl restart systemd-binfmt.service
and verify through:
 $ cat /proc/sys/fs/binfmt_misc/qemu-arm-static

Make sure you have the arm Platform and Sdk runtimes for arm
installed:
 $ flatpak list --runtime --show-details  | grep arm
should show 5 runtimes (include a Locale one)

 $ flatpak --arch=arm --arch-emulator=/path/to/qemu-arm-static ...

This patch is completely obsoleted by the changes merged into the
Linux kernel at the end of July 2016:
  https://lists.linuxfoundation.org/pipermail/containers/2016-July/037302.html

TODO:
- Get configuration into distributions so cross-compilation works
  out-of-the-box.
- Offer architecture choice when building in Builder
  • Loading branch information...
1 parent fe133c7 commit 560e32feb4c6ca1b09c76eb1d3a275e8e88dfebe @hadess committed Jul 1, 2016
Showing with 57 additions and 2 deletions.
  1. +16 −0 builder/builder-context.c
  2. +3 −0 builder/builder-context.h
  3. +7 −2 builder/builder-main.c
  4. +31 −0 builder/builder-manifest.c
@@ -39,6 +39,7 @@ struct BuilderContext
GFile *base_dir;
SoupSession *soup_session;
char *arch;
+ char *arch_emulator;
GFile *download_dir;
GFile *state_dir;
@@ -85,6 +86,7 @@ builder_context_finalize (GObject *object)
g_clear_object (&self->soup_session);
g_clear_object (&self->options);
g_free (self->arch);
+ g_free (self->arch_emulator);
g_strfreev (self->cleanup);
g_strfreev (self->cleanup_platform);
@@ -266,6 +268,20 @@ builder_context_set_arch (BuilderContext *self,
self->arch = g_strdup (arch);
}
+const char *
+builder_context_get_arch_emulator (BuilderContext *self)
+{
+ return (const char *) self->arch_emulator;
+}
+
+void
+builder_context_set_arch_emulator (BuilderContext *self,
+ const char *arch_emulator)
+{
+ g_free (self->arch_emulator);
+ self->arch_emulator = g_strdup (arch_emulator);
+}
+
BuilderOptions *
builder_context_get_options (BuilderContext *self)
{
@@ -46,6 +46,9 @@ SoupSession * builder_context_get_soup_session (BuilderContext *self);
const char * builder_context_get_arch (BuilderContext *self);
void builder_context_set_arch (BuilderContext *self,
const char *arch);
+const char * builder_context_get_arch_emulator (BuilderContext *self);
+void builder_context_set_arch_emulator (BuilderContext *self,
+ const char *arch_emulator);
int builder_context_get_n_cpu (BuilderContext *self);
void builder_context_set_keep_build_dirs (BuilderContext *self,
gboolean keep_build_dirs);
@@ -45,6 +45,7 @@ static gboolean opt_require_changes;
static gboolean opt_keep_build_dirs;
static gboolean opt_force_clean;
static char *opt_arch;
+static char *opt_arch_emulator;
static char *opt_repo;
static char *opt_subject;
static char *opt_body;
@@ -54,7 +55,8 @@ static char **opt_key_ids;
static GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Print debug information during command processing", NULL },
{ "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Print version information and exit", NULL },
- { "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, "Architecture to build for (must be host compatible)", "ARCH" },
+ { "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, "Architecture to build for (must be host compatible or provide an emulator)", "ARCH" },
+ { "arch-emulator", 0, 0, G_OPTION_ARG_STRING, &opt_arch_emulator, "User Emulator if Architecture to build for is not host compatible", "ARCH-EMULATOR" },
{ "run", 0, 0, G_OPTION_ARG_NONE, &opt_run, "Run a command in the build directory (see --run --help)", NULL },
{ "ccache", 0, 0, G_OPTION_ARG_NONE, &opt_ccache, "Use ccache", NULL },
{ "disable-cache", 0, 0, G_OPTION_ARG_NONE, &opt_disable_cache, "Disable cache lookups", NULL },
@@ -75,7 +77,8 @@ static GOptionEntry entries[] = {
static GOptionEntry run_entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Print debug information during command processing", NULL },
- { "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, "Architecture to build for (must be host compatible)", "ARCH" },
+ { "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, "Architecture to build for (must be host compatible or provide an emulator)", "ARCH" },
+ { "arch-emulator", 0, 0, G_OPTION_ARG_STRING, &opt_arch_emulator, "User Emulator if Architecture to build for is not host compatible", "ARCH-EMULATOR" },
{ "run", 0, 0, G_OPTION_ARG_NONE, &opt_run, "Run a command in the build directory", NULL },
{ "ccache", 0, 0, G_OPTION_ARG_NONE, &opt_ccache, "Use ccache", NULL },
{ NULL }
@@ -284,6 +287,8 @@ main (int argc,
if (opt_arch)
builder_context_set_arch (build_context, opt_arch);
+ if (opt_arch_emulator)
+ builder_context_set_arch_emulator (build_context, opt_arch_emulator);
if (opt_ccache &&
!builder_context_enable_ccache (build_context, &error))
@@ -1022,6 +1022,37 @@ builder_manifest_init_app_dir (BuilderManifest *self,
return FALSE;
}
+ const char *arch_emulator;
+
+ arch_emulator = builder_context_get_arch_emulator (context);
+ if (arch_emulator)
+ {
+ //FIXME should be in a runtime extension instead
+ g_print ("Copying architecture emulator\n");
+ GFile *src_file, *dest_file;
+ GFile *files_dir, *bin_dir;
+
+ src_file = g_file_new_for_path (arch_emulator);
+ files_dir = g_file_get_child (app_dir, "files");
+ bin_dir = g_file_get_child (files_dir, "bin");
+ g_object_unref (files_dir);
+ g_file_make_directory (bin_dir, NULL, NULL);
+ dest_file = g_file_get_child (bin_dir, "flatpak-arch-emulator");
+ g_object_unref (bin_dir);
+
+ if (!g_file_copy (src_file, dest_file,
+ G_FILE_COPY_NONE,
+ NULL, NULL, NULL, error))
+ {
+ g_object_unref (dest_file);
+ g_object_unref (src_file);
+ return FALSE;
+ }
+
+ g_object_unref (dest_file);
+ g_object_unref (src_file);
+ }
+
return TRUE;
}

0 comments on commit 560e32f

Please sign in to comment.