-
Notifications
You must be signed in to change notification settings - Fork 74
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]>
Any feedback on this one? This fixed the runtime errors we were facing when using UpdateHub. |
posborne
approved these changes
Sep 4, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks @otavio
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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]