lmi
[Top][All Lists]
Advanced

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

Re: [lmi] Creating a chroot for cross-building lmi


From: Vadim Zeitlin
Subject: Re: [lmi] Creating a chroot for cross-building lmi
Date: Fri, 9 Sep 2016 00:06:24 +0200

On Fri, 2 Sep 2016 01:31:12 +0000 Greg Chicares <address@hidden> wrote:

GC> Here, between scissors lines, is a quasi-script that successfully
GC> creates a debian-8 chroot and cross-builds lmi for msw there.
GC> Some comments and questions follow the script. I call it only a
GC> "quasi-script" because I've tested it by cutting and pasting each
GC> line or block of lines; interaction is required at several points,
GC> e.g., to enter passwords that I don't want to write in a script.
GC> 
GC> 
--------8<--------8<--------8<--------8<--------8<--------8<--------8<--------
GC> # Create a chroot for cross-building lmi--with wine, which is
GC> # required to run programs built in the chroot.
GC> 
GC> # Starting in a normal terminal, enter a root shell.
GC> su
GC> mkdir -p /srv/chroot/cross3
GC> apt-get update
GC> apt-get install schroot debootstrap
GC> 
GC> # If the connection hiccups, 'debootstrap' doesn't seem to resume,
GC> # so keep trying until it succeeds.
GC> 
GC> debootstrap --arch=amd64 jessie /srv/chroot/cross3 
http://httpredir.debian.org/debian
GC> while [ $? -ne 0 ]; do !!; done
GC> 
GC> cat >/etc/schroot/chroot.d/cross3.conf <<\EOF
GC> [cross3]
GC> description=debian-8 cross build with wine
GC> directory=/srv/chroot/cross3
GC> users=greg
GC> groups=greg
GC> root-groups=root
GC> EOF
GC> 
GC> # Exit root shell (return to normal shell).
GC> exit
GC> 
GC> # This command--to start a root shell in the chroot--can be run as a
GC> # normal user. It will prompt for the root password.
GC> 
GC> schroot --chroot=cross3 --user=root --directory=/
GC> # enter password
GC> 
GC> # Add i386 before installing wine, so that wine can run 32-bit .exe's .
GC> 
GC> dpkg --add-architecture i386
GC> 
GC> apt-get update
GC> apt-get install g++-mingw-w64-i686 automake libtool make pkg-config \
GC>  git zsh bzip2 unzip sudo wine
GC> 
GC> # Don't worry about messages like these:
GC> #   E: Can not write log (Is /dev/pts mounted?)
GC> #   [FAIL] Can't start system message bus - /proc is not mounted ... failed!
GC> # It's okay that /dev/pts and /proc are not mounted in this chroot.
GC> 
GC> addgroup --gid=1000 greg
GC> adduser --gid=1000 --uid=1000 greg
GC> # enter user password, twice
GC> # then just press Enter repeatedly to accept defaults
GC> 
GC> mkdir -p /opt/lmi
GC> chown greg:greg /opt/lmi
GC> mkdir -p /cache_for_lmi
GC> chown greg:greg /cache_for_lmi
GC> 
GC> chsh -s /bin/zsh greg
GC> touch /home/greg/.zshrc
GC> chown greg:greg /home/greg/.zshrc
GC> 
GC> # Substitute your system's $DISPLAY below:
GC> 
GC> cat >/home/greg/.zshrc <<\EOF
GC> export WINEPATH='Z:\\opt\\lmi\\local\\bin;Z:\\opt\\lmi\\local\\lib'
GC> export LMI_HOST=i686-w64-mingw32
GC> export PATH="/opt/lmi/local/bin:/opt/lmi/local/lib:$PATH"
GC> # At a regular user prompt, outside the chroot, do this:
GC> #   $ echo $DISPLAY
GC> # and replace :0.0 below with the string it returns:
GC> export DISPLAY=":0.0"
GC> 
GC> export coefficiency='--jobs=32'
GC> 
GC> # export TZ=UCT
GC> # export LANG=en_US.UTF-8 LC_TIME=en_DK.UTF-8 LC_COLLATE=C.UTF-8
GC> #  No--better to do this:
GC> # update-locale LANG=en_US.UTF-8 LC_TIME=en_DK.UTF-8 LC_COLLATE=C.UTF-8
GC> 
GC> # bindkey "\e[3~" delete-char      # Del
GC> # bindkey '\e[H' beginning-of-line # Home
GC> # bindkey '\e[F' end-of-line       # End
GC> bindkey "^[[1;5D" backward-word  # Ctrl-left
GC> bindkey "^[[1;5C" forward-word   # Ctrl-right
GC> bindkey '\e[1;3D' backward-word  # Alt-left
GC> bindkey '\e[1;3C' forward-word   # Alt-right
GC> 
GC> prompt='%d[%?]%(!.#.$)'
GC> 
GC> HISTSIZE=1000
GC> SAVEHIST=1000
GC> HISTFILE=~/.history
GC> setopt HIST_IGNORE_DUPS
GC> 
GC> autoload -U compinit
GC> compinit -u
GC> EOF
GC> 
GC> # Repair /usr/share/libtool/config/ltmain.sh as indicated here:
GC> #   http://lists.gnu.org/archive/html/libtool-patches/2011-06/msg00001.html
GC> # Do this as root because root owns the file.
GC> 
GC> cat >/home/greg/ltmain.sh.patch <<\EOF
GC> --- /usr/share/libtool/config/ltmain.sh.original 2016-01-25 
03:43:07.768000000 +0000
GC> +++ /usr/share/libtool/config/ltmain.sh 2016-01-25 03:44:17.100000000 +0000
GC> @@ -4178,7 +4178,8 @@
GC>  /* declarations of non-ANSI functions */
GC>  #if defined(__MINGW32__)
GC>  # ifdef __STRICT_ANSI__
GC> -int _putenv (const char *);
GC> +     /* int _putenv (const char *); */
GC> +_CRTIMP int _putenv (const char *);
GC>  # endif
GC>  #elif defined(__CYGWIN__)
GC>  # ifdef __STRICT_ANSI__
GC> EOF
GC> 
GC> patch --dry-run --strip=0 </home/greg/ltmain.sh.patch \
GC>  && patch --strip=0 </home/greg/ltmain.sh.patch
GC> 
GC> # Exit from the root shell in the chroot.
GC> exit
GC> 
GC> # If cached lmi downloads are available elsewhere, copy them, e.g.:
GC> #   cp -a /srv/chroot/cross1/cache_for_lmi/* 
/srv/chroot/cross3/cache_for_lmi/
GC> # This optional step merely conserves bandwidth.
GC> 
GC> # Enter the chroot as a normal user
GC> 
GC> schroot --chroot=cross3
GC> 
GC> wget -N 'http://git.savannah.gnu.org/cgit/lmi.git/plain/install_msw.sh'
GC> chmod +x install_msw.sh
GC> ./install_msw.sh >log 2>&1
GC> 
-------->8-------->8-------->8-------->8-------->8-------->8-------->8--------
GC> 
GC> I anticipate running this periodically, so I'd much prefer to cache
GC> the 'debootstrap' step. I tried splitting it into these two steps:
GC> 
GC>   debootstrap --arch=amd64 --download-only jessie /srv/cache 
http://httpredir.debian.org/debian
GC>   debootstrap --arch=amd64 --second-stage 
--second-stage-target=/srv/chroot/cross3 file:///srv/cache
GC> 
GC> but the '--second-stage' step failed with this message:
GC>   cat: /usr/share/debootstrap/suite: No such file or directory
GC> What am I doing wrong?

 Hello,

 The missing step here is running "debootstrap --foreign" to extract the
packages. The option is called like this because it mostly makes sense for
installing releases for foreign architectures, for which debootstrap can't
execute the steps inside the chroot on its own, but it can also be used to
do what we want here, i.e. you could run

        # debootstrap --arch=amd64 --download-only jessie /srv/cache 
http://httpredir.debian.org/debian
        # debootstrap --arch=amd64 --foreign jessie /srv/cache 
http://httpredir.debian.org/debian
        # chroot /srv/cache /debootstrap/debootstrap --second-stage

to do this and it seems to work for me (if you hadn't already done the
--download-only step, you can omit it, of course, --foreign would do it as
well).

 One problem with this approach is that I didn't find a way to use a
different directory for the downloaded packages and the chroot itself.
Maybe it's possible but, to be honest, I didn't look for very long because
I think a slightly better option is to use different debootstrap options:
--{make,unpack}-tarball:

        # debootstrap --arch=amd64 \
                --make-tarball=/var/cache/jessie_bootstrap.tar \
                jessie \
                /tmp/whatever-you-want-it-is-going-to-be-deleted-anyhow
        # debootstrap --arch=amd64 \
                --unpack-tarball=/var/cache/jessie_bootstrap.tar \
                jessie \
                /srv/chroot/cross3


GC> And is there a way to cache downloads for this step:
GC>   apt-get update
GC>   apt-get install g++-mingw-w64-i686 automake libtool make pkg-config \
GC>     git zsh bzip2 unzip sudo wine
GC> which I'm doing as root inside the chroot (which runs a later version
GC> of debian than my real system)?

 I see two ways of doing this. The proper one would be to setup a local
Debian repository and drop a line with a (file:///) URI for it in a file in
/etc/apt/sources.list.d directory in chroot. If you'd like to do this, I
think the simplest and newest (so still actively maintained) tool for doing
this is aptly (https://www.aptly.info/), but I am not really sure, this
changes regularly.

 But I think we could use a simpler low-tech solution here: just download
these packages into some directory ("apt-get download") and run "dpkg -i"
on them inside chroot. As there are relatively few dependencies, it should
be simple enough to do it in the right order, which is really the "only"
advantage that using apt over dpkg brings.

 If you'd like, I could try really testing either the first or the second
solution and write more precise instructions.

GC> During 'debootstrap', I see messages like this:
GC> #   E: Can not write log (Is /dev/pts mounted?)
GC> #   [FAIL] Can't start system message bus - /proc is not mounted ... failed!
GC> and I just ignore them, because the chroot seems to work perfectly.
GC> What negative consequences could this have?

 I don't know because I don't see them, probably because I updated my last
Wheezy system to Jessie by now. I probably could install a Wheezy chroot
and try creating a Jessie chroot from it, but this is starting getting
seriously metaphysical, so let me just give two advices without bothering
practically checking them:

1. As I said before, I think you do need to mount /dev/pts because many
programs risk to fail mysteriously if PTYs don't work. This can be done
manually using "mount -o bind -t devpts /dev/pts devpts".

2. For the system bus, this is a systemd thing and I'm almost sure it's not
going to function correctly without it, so I'd do "mount -t proc /proc
proc" too (here "-o bind" could be used too, but is not necessary, I
think).

GC> The '~/.zshrc' created by the quasi-script suggests running
GC>   update-locale LANG=en_US.UTF-8 LC_TIME=en_DK.UTF-8 LC_COLLATE=C.UTF-8

 I have no idea where is this coming from, especially DK for the time
format. I just use "LC_ALL=C.UTF-8" and set "LANG" to the same value.

GC> but I haven't installed 'update-locale' in the chroot. This doesn't
GC> seem to matter: time is UTC, and text like
GC>   tn_range.hpp:/// This class's raison d'ĂȘtre is to
GC> prints e-circonflexe correctly. BTW, `locale` shows all LC_* facets set
GC> to "POSIX".

 Yes, this is the default Debian setting which I can see running "env -i
locale" on my main system too. I am pretty sure that "POSIX" is just a
fancy name for "C" locale, so I believe setting LC_ALL to C.UTF-8 is still
a good idea.

GC> When the last step
GC>   ./install_msw.sh >log 2>&1
GC> finishes, I see a popup messagebox:
GC>   Wine could not find a Mono package...see http://wiki.winehq.org/Mono
GC> I simply hit Cancel, and everything seems fine, and I never see it again.
GC> 'install_msw.sh' makes the lmi 'install' target, which does this:
GC>   @cd $(data_dir); $(PERFORM) $(bin_dir)/product_files$(EXEEXT)
GC> where $PERFORM is 'wine'; this is the first time 'wine' is used in the
GC> chroot, and apparently the first time it's run it checks for 'mono'.
GC> This shouldn't matter, because 'mono' is some "dot-net" thing we don't
GC> need. Debian is aware of it:
GC>   https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=677094
GC> so I guess we should just live with the nuisance for now.

 Yes, I don't see any way to work around this. It's strange that I don't
remember getting it when installing Wine here, but then I used the version
from Sid to test a fix for a Wine bug I found, maybe this is somehow fixed
there. Or maybe I just forgot it.

 Sorry for the delay with reply!
VZ


reply via email to

[Prev in Thread] Current Thread [Next in Thread]