Skip to content

class/cargo: Handle case when host and target has same arch #82

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

Merged
merged 1 commit into from
Sep 4, 2020
Merged

class/cargo: Handle case when host and target has same arch #82

merged 1 commit into from
Sep 4, 2020

Conversation

otavio
Copy link
Contributor

@otavio otavio commented Aug 21, 2020

When we have same architecture for the host and target, we need to
properly handle the native and target case as Rust cannot differentiate
both.

Fixes: #70.

Signed-off-by: Otavio Salvador [email protected]

When we have same architecture for the host and target, we need to
properly handle the native and target case as Rust cannot differentiate
both.

Fixes: #70.

Signed-off-by: Otavio Salvador <[email protected]>
@otavio
Copy link
Contributor Author

otavio commented Aug 27, 2020

Any feedback on this one? This fixed the runtime errors we were facing when using UpdateHub.

Copy link
Member

@posborne posborne left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks @otavio

@posborne posborne merged commit c6208b4 into rust-embedded:master Sep 4, 2020
sarfata added a commit to sarfata/meta-rust-bin that referenced this pull request Oct 3, 2023
In rust-embedded#82 we fixed the build when the target arch is the same as the build arch. A
side effect of the fix is that the rust build-scripts (which are intended to run
on the build host) are now built with the target compiler and cflags.

This is fine in most cases but it breaks when the host system is older than the
system we are building. For example, we might build for a newer glibc that will
be available on the target but when we run the build script on the host, this
version does not exist which leads to the error described in rust-embedded#83.

Another version of the same problem is that we may try to use some build flags
that are available on the compiler for the target (`aarch64-poky-linux-gcc`) but
not on the host compiler (`gcc`) because the host compiler is older than the one
we are using for the target.

This patch fixes the problem by using two unstable features of cargo:

 - [`UNSTABLE_TARGET_APPLIES_TO_HOST`](https://doc.rust-lang.org/cargo/reference/unstable.html#target-applies-to-host)
 allows us to pass the `CARGO_TARGET_APPLIES_TO_HOST=false` setting so that the
 target build settings are not used when building for the host.
 - [`UNSTABLE_HOST_CONFIG`](https://doc.rust-lang.org/cargo/reference/unstable.html#host-config)
 allows us to set build flags for the host in a `[host]` section of the
 `Cargo.toml` file.

The `__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS` environment variable is
required to use these unstable features on a stable rust. This patch works with
stable rust and does not require unstable.

The inspiration for this solution [comes from buildroot](https://github.com/buildroot/buildroot/blob/25d865996d1d9753fe7d4dfe39cf18c7e9f91224/package/pkg-cargo.mk#L26-L47).

fixes rust-embedded#83
sarfata added a commit to sarfata/meta-rust-bin that referenced this pull request Oct 9, 2023
In rust-embedded#82 we fixed the build when the target arch is the same as the build arch. A
side effect of the fix is that the rust build-scripts (which are intended to run
on the build host) are now built with the target compiler and cflags.

This is fine in most cases but it breaks when the host system is older than the
system we are building. For example, we might build for a newer glibc that will
be available on the target but when we run the build script on the host, this
version does not exist which leads to the error described in rust-embedded#83.

Another version of the same problem is that we may try to use some build flags
that are available on the compiler for the target (`aarch64-poky-linux-gcc`) but
not on the host compiler (`gcc`) because the host compiler is older than the one
we are using for the target.

This patch fixes the problem by using two unstable features of cargo:

 - [`UNSTABLE_TARGET_APPLIES_TO_HOST`](https://doc.rust-lang.org/cargo/reference/unstable.html#target-applies-to-host)
 allows us to pass the `CARGO_TARGET_APPLIES_TO_HOST=false` setting so that the
 target build settings are not used when building for the host.
 - [`UNSTABLE_HOST_CONFIG`](https://doc.rust-lang.org/cargo/reference/unstable.html#host-config)
 allows us to set build flags for the host in a `[host]` section of the
 `Cargo.toml` file.

The `__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS` environment variable is
required to use these unstable features on a stable rust. This patch works with
stable rust and does not require unstable.

The inspiration for this solution [comes from buildroot](https://github.com/buildroot/buildroot/blob/25d865996d1d9753fe7d4dfe39cf18c7e9f91224/package/pkg-cargo.mk#L26-L47).

fixes rust-embedded#83
sarfata added a commit to sarfata/meta-rust-bin that referenced this pull request Oct 9, 2023
In rust-embedded#82 we fixed the build when the target arch is the same as the build arch. A
side effect of the fix is that the rust build-scripts (which are intended to run
on the build host) are now built with the target compiler and cflags.

This is fine in most cases but it breaks when the host system is older than the
system we are building. For example, we might build for a newer glibc that will
be available on the target but when we run the build script on the host, this
version does not exist which leads to the error described in rust-embedded#83.

Another version of the same problem is that we may try to use some build flags
that are available on the compiler for the target (`aarch64-poky-linux-gcc`) but
not on the host compiler (`gcc`) because the host compiler is older than the one
we are using for the target.

This patch fixes the problem by using two unstable features of cargo:

 - [`UNSTABLE_TARGET_APPLIES_TO_HOST`](https://doc.rust-lang.org/cargo/reference/unstable.html#target-applies-to-host)
 allows us to pass the `CARGO_TARGET_APPLIES_TO_HOST=false` setting so that the
 target build settings are not used when building for the host.
 - [`UNSTABLE_HOST_CONFIG`](https://doc.rust-lang.org/cargo/reference/unstable.html#host-config)
 allows us to set build flags for the host.

The `__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS` environment variable is
required to use these unstable features on a stable rust. This patch works with
stable rust and does not require unstable.

During review of this PR, it was decided to drop the `cargo_home/config` file
completely and use only environment variables.

The inspiration for this solution [comes from buildroot](https://github.com/buildroot/buildroot/blob/25d865996d1d9753fe7d4dfe39cf18c7e9f91224/package/pkg-cargo.mk#L26-L47).

fixes rust-embedded#83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect linker-wrapper used when target architecture is the same as build one
2 participants