Commit 8fb174f
committed
fix: build when target_arch==build_arch
In #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 #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 #831 parent 7ac87ec commit 8fb174f
1 file changed
+18
-29
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | 54 | | |
79 | 55 | | |
80 | 56 | | |
| |||
106 | 82 | | |
107 | 83 | | |
108 | 84 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | 85 | | |
113 | 86 | | |
114 | 87 | | |
115 | 88 | | |
116 | 89 | | |
117 | 90 | | |
118 | 91 | | |
119 | | - | |
120 | | - | |
121 | 92 | | |
122 | 93 | | |
123 | 94 | | |
124 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
125 | 114 | | |
126 | 115 | | |
127 | 116 | | |
| |||
0 commit comments