Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add concept of a native Dockerfile. #982

Merged
merged 1 commit into from
Oct 8, 2022

Conversation

Alexhuszagh
Copy link
Contributor

No description provided.

@Alexhuszagh Alexhuszagh added container-images meta issues/PRs related to the maintenance of the crate. A-aarch64-host Area: ARMv8 hosts no changelog A valid PR without changelog (no-changelog) labels Jul 28, 2022
@Alexhuszagh
Copy link
Contributor Author

Alexhuszagh commented Jul 28, 2022

The idea behind this is so we can provide native toolchains if the image platform and the cross-compilation target are the same. This simplifies our logic for say, linux/arm64 images for an aarch64-unknown-linux-gnu toolchain. There's still some work to do, however:

  1. Need to change x86_64-unknown-linux-gnu to actually work when cross-compiled.
  2. Change i686-unknown-linux-gnu and i586-unknown-linux-gnu to allow use from a non-x86_64 image.
  3. Test the Native toolchain on a non-x86_64 image.

We might require slightly more complex logic for i586/i686 since the default package we'd install for x86_64 (g++-x86-64-linux-gnu) I don't believe is multilib (although I could be wrong here).

@Emilgardis
Copy link
Member

I'm not sure I understand what this does and how it differs. How is it used?

@Alexhuszagh
Copy link
Contributor Author

Alexhuszagh commented Jul 28, 2022

I'm not sure I understand what this does and how it differs. How is it used?

Say if I want to build aarch64-unknown-linux-gnu for an image running Ubuntu:20.04 on linux/arm64: I just want to install GCC, G++, glibc, and don't want a cross-compiler: I just want the same logic as the current Dockerfile.x86_64-unknown-linux-gnu. And doing this generic logic for every possible host is a lot: we can just make a generic native Dockerfile and use it for every native toolchain for the image.

@Emilgardis
Copy link
Member

with buildkit it's possible to do conditional stages, I think that could help to not use a script file

# arm64-specific stage
FROM base AS build-arm64
RUN echo "This stage is used on arm64"

# amd64-specific stage
FROM base AS build-amd64
RUN echo "This stage is used on amd64 (x86)"

# common steps
FROM build-${TARGETARCH} AS build
RUN echo "This stage is used on all architectures"

for example

@Alexhuszagh
Copy link
Contributor Author

with buildkit it's possible to do conditional stages, I think that could help to not use a script file

# arm64-specific stage
FROM base AS build-arm64
RUN echo "This stage is used on arm64"

# amd64-specific stage
FROM base AS build-amd64
RUN echo "This stage is used on amd64 (x86)"

# common steps
FROM build-${TARGETARCH} AS build
RUN echo "This stage is used on all architectures"

for example

In retrospect, I don't think we need a script (just native/non-native) unless we want to support targets where we have to build from source (which I think we can omit) or use Debian repositories only for a different architecture (specifically, MIPS).

@Alexhuszagh
Copy link
Contributor Author

bors try --target x86_64-unknown-linux-gnu

bors bot added a commit that referenced this pull request Jul 28, 2022
@bors
Copy link
Contributor

bors bot commented Jul 28, 2022

try

Build succeeded:

@Alexhuszagh Alexhuszagh force-pushed the native_dockerfile branch 3 times, most recently from 25e592e to 33a7a77 Compare July 29, 2022 15:10
@Alexhuszagh Alexhuszagh marked this pull request as ready for review July 29, 2022 15:10
@Alexhuszagh Alexhuszagh requested a review from a team as a code owner July 29, 2022 15:10
@Alexhuszagh Alexhuszagh force-pushed the native_dockerfile branch 2 times, most recently from 7e07118 to ddbb2fc Compare July 30, 2022 04:29
Copy link
Member

@Emilgardis Emilgardis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, I'm just not sure I like the naming.

maybe same-platform?

I'd also like it if with this pr that the image is made available and used when possible.

docker/linux-image.sh Outdated Show resolved Hide resolved
docker/linux-image.sh Outdated Show resolved Hide resolved
docker/linux-image.sh Outdated Show resolved Hide resolved
.changes/982.json Outdated Show resolved Hide resolved
@Alexhuszagh Alexhuszagh mentioned this pull request Aug 10, 2022
@Alexhuszagh
Copy link
Contributor Author

Alexhuszagh commented Aug 10, 2022

Based on comments elsewhere, I should clarify that this is not used to publish a ghcr.io/cross-rs/native:$tag image: it is meant so Dockerfile.native is used for ghcr.io/cross-rs/x86_64-unknown-linux-gnu:$tag on linux/amd64 and ghcr.io/cross-rs/aarch64-unknown-linux-gnu:$tag on linux/arm64, and that Dockerfile.x86_64-unknown-linux-gnu is only used if the platform is not linux/amd64 (same with Dockerfile.aarch64-unknown-linux-gnu and linux/arm64).

When building the image, we change the Dockerfile used for the build. If the image architecture is the same as the target architecture, and the target triple is *-linux-gnu, then use Dockerfile.native. Otherwise, use the normal Dockerfile. This is required since packages like g++ are not for x86_64 on a linux/arm64 platform, and packages like g++-x86-64-linux-gnu and g++-aarch64-linux-gnu are not available on linux/amd64 and linux/arm64, respectively.

bors bot added a commit that referenced this pull request Oct 5, 2022
982: Add concept of a native Dockerfile. r=Emilgardis a=Alexhuszagh



Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
@bors
Copy link
Contributor

bors bot commented Oct 6, 2022

Build failed:

docker/native-linux-runner Outdated Show resolved Hide resolved
docker/native-linux-image.sh Show resolved Hide resolved
@Alexhuszagh Alexhuszagh force-pushed the native_dockerfile branch 2 times, most recently from e5c53fd to 3d20996 Compare October 6, 2022 16:44
@Emilgardis
Copy link
Member

bors try --target x86_64-unknown-linux-gnu*

bors bot added a commit that referenced this pull request Oct 6, 2022
@bors
Copy link
Contributor

bors bot commented Oct 6, 2022

try

Build succeeded:

COPY xargo.sh /
RUN /xargo.sh

ARG TARGETARCH
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done after the shared code, which will be nice when creating a base image but also for cached layers even before then.

Copy link
Member

@Emilgardis Emilgardis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot about this

looks good

bors r+

bors bot added a commit that referenced this pull request Oct 7, 2022
982: Add concept of a native Dockerfile. r=Emilgardis a=Alexhuszagh



Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
docker/lib.sh Outdated Show resolved Hide resolved
@Emilgardis
Copy link
Member

bors cancel

@bors
Copy link
Contributor

bors bot commented Oct 7, 2022

Canceled.

This allows builds for different architectures to work by using the native, base image native for the built platform. This supported both the Ubuntu and CentOS image bases, and adds a `CROSS_TARGET_TRIPLE` to ensure simplify exported the cargo-specific environment variables for the native images.
@Alexhuszagh
Copy link
Contributor Author

bors r=Emilgardis

bors bot added a commit that referenced this pull request Oct 7, 2022
982: Add concept of a native Dockerfile. r=Emilgardis a=Alexhuszagh



Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
@bors
Copy link
Contributor

bors bot commented Oct 7, 2022

Build failed:

@Alexhuszagh
Copy link
Contributor Author

This target did not change and passed the last time...
https://github.com/cross-rs/cross/actions/runs/3207655589/jobs/5242799975#step:12:146

@Emilgardis
Copy link
Member

I see no reason for why it would not work now except for some filesystem error

lets try again

bors r+

bors bot added a commit that referenced this pull request Oct 7, 2022
982: Add concept of a native Dockerfile. r=Emilgardis a=Alexhuszagh



Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
@Emilgardis
Copy link
Member

bors cancel

bors retry

@bors
Copy link
Contributor

bors bot commented Oct 7, 2022

Canceled.

@Emilgardis
Copy link
Member

bors r+

doesn't seem like it got queued https://app.bors.tech/repositories/45789

@bors
Copy link
Contributor

bors bot commented Oct 8, 2022

Build succeeded:

@bors bors bot merged commit cfc9a15 into cross-rs:main Oct 8, 2022
@Alexhuszagh Alexhuszagh deleted the native_dockerfile branch October 8, 2022 03:22
@Emilgardis Emilgardis added this to the v0.3.0 milestone Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-aarch64-host Area: ARMv8 hosts container-images meta issues/PRs related to the maintenance of the crate. no changelog A valid PR without changelog (no-changelog)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants