toltec-dev / toolchain

Set of Docker images for cross-compiling binaries targeting the reMarkable tablet.
MIT License
35 stars 12 forks source link

Add more envs to base #5

Closed LinusCDE closed 3 years ago

LinusCDE commented 3 years ago

This adds a couple more envs to the base image. I added them last since I ran into linking problems when adding those where CROSS_COMPILE and others are (probably something got accidentally as arm).

I used oecore in looking up the envs to add. Those should be all the common envs.

(All the envs oecore sets when sourced) ``` SDKTARGETSYSROOT=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi PKG_CONFIG_SYSROOT_DIR=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi PKG_CONFIG_PATH=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi/usr/lib/pkgconfig:/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi/usr/share/pkgconfig CONFIG_SITE=/usr/local/oecore-x86_64/site-config-cortexa9hf-neon-oe-linux-gnueabi OECORE_NATIVE_SYSROOT=/usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux OECORE_TARGET_SYSROOT=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi OECORE_ACLOCAL_OPTS=-I /usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/share/aclocal CC=arm-oe-linux-gnueabi-gcc -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi CXX=arm-oe-linux-gnueabi-g++ -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi CPP=arm-oe-linux-gnueabi-gcc -E -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi AS=arm-oe-linux-gnueabi-as LD=arm-oe-linux-gnueabi-ld --sysroot=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi GDB=arm-oe-linux-gnueabi-gdb STRIP=arm-oe-linux-gnueabi-strip RANLIB=arm-oe-linux-gnueabi-ranlib OBJCOPY=arm-oe-linux-gnueabi-objcopy OBJDUMP=arm-oe-linux-gnueabi-objdump AR=arm-oe-linux-gnueabi-ar NM=arm-oe-linux-gnueabi-nm M4=m4 TARGET_PREFIX=arm-oe-linux-gnueabi- CONFIGURE_FLAGS=--target=arm-oe-linux-gnueabi --host=arm-oe-linux-gnueabi --build=x86_64-linux --with-libtool-sysroot=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi CFLAGS= -O2 -pipe -g -feliminate-unused-debug-types CXXFLAGS= -O2 -pipe -g -feliminate-unused-debug-types LDFLAGS=-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed CPPFLAGS= KCFLAGS=--sysroot=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi OECORE_DISTRO_VERSION=1.1 OECORE_SDK_VERSION=nodistro.0 ARCH=arm CROSS_COMPILE=arm-oe-linux-gnueabi- OE_QMAKE_CFLAGS= -O2 -pipe -g -feliminate-unused-debug-types OE_QMAKE_CXXFLAGS= -O2 -pipe -g -feliminate-unused-debug-types OE_QMAKE_LDFLAGS=-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed OE_QMAKE_CC=arm-oe-linux-gnueabi-gcc -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi OE_QMAKE_CXX=arm-oe-linux-gnueabi-g++ -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi OE_QMAKE_LINK=arm-oe-linux-gnueabi-g++ -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi OE_QMAKE_AR=arm-oe-linux-gnueabi-ar OE_QMAKE_STRIP=arm-oe-linux-gnueabi-strip QT_CONF_PATH=/usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin/qt.conf OE_QMAKE_LIBDIR_QT=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi/usr/lib OE_QMAKE_INCDIR_QT=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi/usr/include OE_QMAKE_MOC=/usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin/moc OE_QMAKE_UIC=/usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin/uic OE_QMAKE_RCC=/usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin/rcc OE_QMAKE_QDBUSCPP2XML=/usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin/qdbuscpp2xml OE_QMAKE_QDBUSXML2CPP=/usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin/qdbusxml2cpp OE_QMAKE_QT_CONFIG=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi/usr/lib/mkspecs/qconfig.pri OE_QMAKE_PATH_HOST_BINS=/usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin QMAKESPEC=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi/usr/lib/mkspecs/linux-oe-g++ ```

We should also consider adding $CFLAGS and arguments to $CC and $CXX like oecore does, but I was not sure yet and wanted to prevent too many potentially breaking changes at once. I'll probably do a compile test (make repo -l in toltec) with this images later or tomorrow.

EDIT: I already tested all the specified vars to be available in the container. I didn't add M4, as we don't have that one in the toolchain, yet.

matteodelabre commented 3 years ago

Thanks for the PR! The linking problems are a little bit worrying. Do you have more details on which step of the build failed?

matteodelabre commented 3 years ago

I managed to reproduce it on my side. It looks like util-linux is generating an x86 version of libblkid when those environment variables are set, which in turn causes an error when systemd tries to link to that version of libblkid later on.

matteodelabre commented 3 years ago

I think I understand why: Docker sets all the variables of one ENV instruction at the same time. For example, the CC variable does not see the value of the CROSS_COMPILE variable that is set at the same time, so ${CROSS_COMPILE} expands to the empty string and the CC variable ends up with the "gcc" value, which calls the x86 compiler.

matteodelabre commented 3 years ago

Found a workaround by using Docker ARG instructions. All the env vars are now in the same place. I also used that to reduce the duplications of arm-linux-gnueabihf values all over the Dockerfile.

matteodelabre commented 3 years ago

@LinusCDE It seems like the Meson build system does not like that the CC variable family is set to the cross-compiler rather than the native compiler. It produces the following warning, before failing due to an exec format error.

WARNING: Env var CC seems to point to the cross compiler.
This is probably wrong, it should always point to the native compiler.

So, since the different build systems have different interpretations for those variables, I think it’s best to declare them locally before each build. I’ll rollback this change for now.

LinusCDE commented 3 years ago

Cool. Can totally understand that. The changes could probably break some other packages as well.