Skip to contentSkip to conversation

Native yocto compile in docker container without cross compile

DISCUSSION Fabian Sturm 3 participants 6 messages Sep 18, 2018 – Sep 19, 2018

lore
Share & tools
lore
#0 lore raw

Hi,

I am wondering, there does not seem to be any information about native compile of projects in a Yocto docker container. It seems that most of the people use cross compile even though that imho is not necessary if your target is x86 too. So here is what I want to do:

- Create a docker container with Yocto Linux, possibly same as the target image
- Install gcc, cmake, autotools etc. in the docker container
- Run the docker container on a vanilla Ubuntu Linux
- Run build jobs in this docker container directly

Rational. I have several projects with fully functioning build systems, e.g. make, cmake or autotools which I need to compile for different platforms, e.g. Windows, Ubuntu Linux and Yocto Linux. I now don't want to write recipes just for the Yocto cross compile which I need to additionally maintain and I also don't want to make the original build systems cross compile aware. This can soon get really hard if the build system generates intermediate binaries that are called in the build itself and if it is not prepared for this.
Since my target and host platform are both x86 I do not see the need for a cross compile anyways. Usually it is necessary since the target platform might be a very slow ARM system that can't handle all the builds itself. But I do not have this limitation.

With such a solution my original build systems should still be able to run unmodified. Within the docker container the environment would be almost the same as in an Ubuntu Linux. The compiler can be accessed without any cross compile settings and any intermediate binaries can also be directly executed etc.

If there are some fundamental reasons why this is a bad idea, I would like to know. I also would appreciate any tips on how to create such a docker image. Usually my Yocto image for the target would not contain a compiler or make tool. So I need a way to add those after the fact.

Thanks a lot!
Fabian

#1 lore raw

I think what you are looking for is a Yocto generated SDK for your image?

bitbake -c populate_sdk <image>

Alex

2018-09-18 23:00 GMT+02:00 Fabian Sturm <[email protected]>:

Quoted 46 lines

Hi,

I am wondering, there does not seem to be any information about native compile of projects in a Yocto docker container. It seems that most of the people use cross compile even though that imho is not necessary if your target is x86 too. So here is what I want to do:

- Create a docker container with Yocto Linux, possibly same as the target image
- Install gcc, cmake, autotools etc. in the docker container
- Run the docker container on a vanilla Ubuntu Linux
- Run build jobs in this docker container directly

Rational. I have several projects with fully functioning build systems, e.g. make, cmake or autotools which I need to compile for different platforms, e.g. Windows, Ubuntu Linux and Yocto Linux. I now don't want to write recipes just for the Yocto cross compile which I need to additionally maintain and I also don't want to make the original build systems cross compile aware. This can soon get really hard if the build system generates intermediate binaries that are called in the build itself and if it is not prepared for this.
Since my target and host platform are both x86 I do not see the need for a cross compile anyways. Usually it is necessary since the target platform might be a very slow ARM system that can't handle all the builds itself. But I do not have this limitation.

With such a solution my original build systems should still be able to run unmodified. Within the docker container the environment would be almost the same as in an Ubuntu Linux. The compiler can be accessed without any cross compile settings and any intermediate binaries can also be directly executed etc.

If there are some fundamental reasons why this is a bad idea, I would like to know. I also would appreciate any tips on how to create such a docker image. Usually my Yocto image for the target would not contain a compiler or make tool. So I need a way to add those after the fact.

Thanks a lot!
Fabian

--
_______________________________________________
yocto mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/yocto

#2 lore raw

Hi,

no this is not what I am searching for. What I want is gcc cmake and other tools to be installed inside of the Yocto image, so that I can compile natively in Yocto without having to hack build scripts to work with a cross compiler.
But of course I don'T want to deliver gcc and others with the image on a device. One solution would be to build a separate image that contains the tools. But my hope is to use the original image and just add those tools later on.

Any ideas how to set something like this up best?

Kind regrads,
Fabian

Am Mittwoch, den 19.09.2018, 10:07 +0200 schrieb Alexander Kanavin:

Quoted 6 lines

I think what you are looking for is a Yocto generated SDK for your image?

bitbake -c populate_sdk <image>

Alex

#3 lore raw

If you're targeting just x86 then you can build an image with the tools-sdk IMAGE_FEATURE defined, and use something like systemd-nspawn (insert your preferred container system) to get a shell in it.

Ross

Quoted 30 lines · Fabian Sturm

Hi,

no this is not what I am searching for. What I want is gcc cmake and other tools to be installed inside of the Yocto image, so that I can compile natively in Yocto without having to hack build scripts to work with a cross compiler.
But of course I don'T want to deliver gcc and others with the image on a device. One solution would be to build a separate image that contains the tools. But my hope is to use the original image and just add those tools later on.

Any ideas how to set something like this up best?

Kind regrads,
Fabian

Am Mittwoch, den 19.09.2018, 10:07 +0200 schrieb Alexander Kanavin:

Quoted 6 lines

I think what you are looking for is a Yocto generated SDK for your image?

bitbake -c populate_sdk <image>

Alex

--
_______________________________________________
yocto mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/yocto

#4 lore raw

Hmm I guess I was way overthinking this. The idea seems to just create a secong image definition like this it seems:

core-image-minimal-dev.bb:

    require core-image-minimal.bb

    DESCRIPTION = "A small image just capable of allowing a device to
    boot and \
    is suitable for development work."

    IMAGE_FEATURES += "dev-pkgs tools-sdk"
    IMAGE_INSTALL += "cmake"

dev-pkg: selects e.g. all header files for the image packages
tools-sdk: install the toolchain packages into the image IMAGE_INSTALL += "cmake": here I define any other development tool that I need in my image

I this correct? At least it seems the created image contains everything I need!

Kind regards,
Fabian

Am Mittwoch, den 19.09.2018, 18:21 +0100 schrieb Burton, Ross:

Quoted 6 lines

If you're targeting just x86 then you can build an image with the tools-sdk IMAGE_FEATURE defined, and use something like systemd- nspawn
(insert your preferred container system) to get a shell in it.

Ross

#5 lore raw

Yes, that's it.

Quoted 36 lines · Fabian Sturm

Hmm I guess I was way overthinking this. The idea seems to just create a secong image definition like this it seems:

core-image-minimal-dev.bb:

    require core-image-minimal.bb

    DESCRIPTION = "A small image just capable of allowing a device to
    boot and \
    is suitable for development work."

    IMAGE_FEATURES += "dev-pkgs tools-sdk"
    IMAGE_INSTALL += "cmake"

dev-pkg: selects e.g. all header files for the image packages
tools-sdk: install the toolchain packages into the image IMAGE_INSTALL += "cmake": here I define any other development tool that I need in my image

I this correct? At least it seems the created image contains everything I need!

Kind regards,
Fabian

Am Mittwoch, den 19.09.2018, 18:21 +0100 schrieb Burton, Ross:

Quoted 6 lines

If you're targeting just x86 then you can build an image with the tools-sdk IMAGE_FEATURE defined, and use something like systemd- nspawn
(insert your preferred container system) to get a shell in it.

Ross