[RFC,6/8] rust: Mitigate duplicate sections on matching architectures

Message ID 20220222035234.463162-7-andrew@aj.id.au
State New
Headers show
Series rust: Fix powerpc64le support | expand

Commit Message

Andrew Jeffery Feb. 22, 2022, 3:52 a.m. UTC
This seemed to be an issue for Power once the arch mappings were fixed
(by a patch later in this series).

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 meta/recipes-devtools/rust/rust.inc | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

Comments

Alexander Kanavin Feb. 22, 2022, 9:57 a.m. UTC | #1
This needs a better explanation. What is the problem and how is it being fixed?

Alex

On Tue, 22 Feb 2022 at 04:52, Andrew Jeffery <andrew@aj.id.au> wrote:
>
> This seemed to be an issue for Power once the arch mappings were fixed
> (by a patch later in this series).
>
> Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
> ---
>  meta/recipes-devtools/rust/rust.inc | 22 +++++++++++++---------
>  1 file changed, 13 insertions(+), 9 deletions(-)
>
> diff --git a/meta/recipes-devtools/rust/rust.inc b/meta/recipes-devtools/rust/rust.inc
> index cc0730e9cd2d..fd934082bddf 100644
> --- a/meta/recipes-devtools/rust/rust.inc
> +++ b/meta/recipes-devtools/rust/rust.inc
> @@ -35,8 +35,11 @@ setup_cargo_environment () {
>      # Later stages are build for the native target (i.e. target.x86_64-linux)
>      cargo_common_do_configure
>
> -    printf '[target.%s]\n' "${SNAPSHOT_BUILD_SYS}" >> ${CARGO_HOME}/config
> -    printf "linker = '%s'\n" "${RUST_BUILD_CCLD}" >> ${CARGO_HOME}/config
> +    if [ ${SNAPSHOT_BUILD_SYS} != ${RUST_BUILD_SYS} ]
> +    then
> +        printf '[target.%s]\n' "${SNAPSHOT_BUILD_SYS}" >> ${CARGO_HOME}/config
> +        printf "linker = '%s'\n" "${RUST_BUILD_CCLD}" >> ${CARGO_HOME}/config
> +    fi
>  }
>
>  include rust-common.inc
> @@ -88,15 +91,16 @@ python do_configure() {
>      config.set(target_section, "cxx", e(d.expand("${RUST_TARGET_CXX}")))
>      config.set(target_section, "cc", e(d.expand("${RUST_TARGET_CC}")))
>
> -    # If we don't do this rust-native will compile it's own llvm for BUILD.
> -    # [target.${BUILD_ARCH}-unknown-linux-gnu]
> -    target_section = "target.{}".format(d.getVar('SNAPSHOT_BUILD_SYS', True))
> -    config.add_section(target_section)
> +    if (d.getVar('SNAPSHOT_BUILD_SYS') != d.getVar('RUST_TARGET_SYS')):
> +        # If we don't do this rust-native will compile it's own llvm for BUILD.
> +        # [target.${BUILD_ARCH}-unknown-linux-gnu]
> +        target_section = "target.{}".format(d.getVar('SNAPSHOT_BUILD_SYS', True))
> +        config.add_section(target_section)
>
> -    config.set(target_section, "llvm-config", e(llvm_config))
> +        config.set(target_section, "llvm-config", e(llvm_config))
>
> -    config.set(target_section, "cxx", e(d.expand("${RUST_BUILD_CXX}")))
> -    config.set(target_section, "cc", e(d.expand("${RUST_BUILD_CC}")))
> +        config.set(target_section, "cxx", e(d.expand("${RUST_BUILD_CXX}")))
> +        config.set(target_section, "cc", e(d.expand("${RUST_BUILD_CC}")))
>
>      # [rust]
>      config.add_section("rust")
> --
> 2.32.0
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#162120): https://lists.openembedded.org/g/openembedded-core/message/162120
> Mute This Topic: https://lists.openembedded.org/mt/89310362/1686489
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alex.kanavin@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Andrew Jeffery Feb. 23, 2022, 12:38 a.m. UTC | #2
On Tue, 22 Feb 2022, at 20:27, Alexander Kanavin wrote:
> This needs a better explanation. 

Ack.

>What is the problem and how is it being fixed?

The immediate error was the build bailed out complaining of duplicate 
sections in the config. Possibly this is an indication of a broken build 
configuration rather than the code needing fixes, but this is how I 
made the problem go away. As mentioned I kind of just slashed my way 
though everything. It deserves some closer analysis like you stated 
above.

Let me take some time to get a better grip on what's happening here.

Andrew
Andrew Jeffery Feb. 28, 2022, 12:13 a.m. UTC | #3
On Wed, 23 Feb 2022, at 11:08, Andrew Jeffery wrote:
> On Tue, 22 Feb 2022, at 20:27, Alexander Kanavin wrote:
>> This needs a better explanation. 
>
> Ack.
>
>>What is the problem and how is it being fixed?
>
> The immediate error was the build bailed out complaining of duplicate 
> sections in the config. Possibly this is an indication of a broken build 
> configuration rather than the code needing fixes

Okay, so the root cause of this was I was setting RUST_{HOST,TARGET}_SYS
to "powerpc64le-unknown-linux-gnu", which matched RUST_BUILD_SYS. I did
that because rustc seems to be quite unhappy when supplied with
`--target ppc64le-linux` or `--target powerpc64le-linux'. I'm trying to
understand why, but I'm struggling because rustc seems just fine with
`--target x86_64-linux` despite none of `ppc64le-linux`,
`powerpc64le-linux` nor `x86_64-linux` appearing in the `rustc --print
target-list` output that I could gather.

How/why does `--target x86_64-linux` work?

Andrew
Alexander Kanavin Feb. 28, 2022, 8:21 a.m. UTC | #4
On Mon, 28 Feb 2022 at 01:13, Andrew Jeffery <andrew@aj.id.au> wrote:
> Okay, so the root cause of this was I was setting RUST_{HOST,TARGET}_SYS
> to "powerpc64le-unknown-linux-gnu", which matched RUST_BUILD_SYS. I did
> that because rustc seems to be quite unhappy when supplied with
> `--target ppc64le-linux` or `--target powerpc64le-linux'. I'm trying to
> understand why, but I'm struggling because rustc seems just fine with
> `--target x86_64-linux` despite none of `ppc64le-linux`,
> `powerpc64le-linux` nor `x86_64-linux` appearing in the `rustc --print
> target-list` output that I could gather.
>
> How/why does `--target x86_64-linux` work?

I think in the context of oe-core, all targets are custom ones,
specified by writing out json files and directing rust to use them. So
you need to do two things:
1. --print target-list is useless and irrelevant, as it only prints
built-in targets, don't try it.
2. When there's a problem inspect what json files are in the sysroot,
what they contain, and whether rust is able to find them.
x86_64-linux.json is made specifically for building native items.

Alex
Andrew Jeffery Feb. 28, 2022, 1:57 p.m. UTC | #5
On Mon, 28 Feb 2022, at 18:51, Alexander Kanavin wrote:
> On Mon, 28 Feb 2022 at 01:13, Andrew Jeffery <andrew@aj.id.au> wrote:
>> Okay, so the root cause of this was I was setting RUST_{HOST,TARGET}_SYS
>> to "powerpc64le-unknown-linux-gnu", which matched RUST_BUILD_SYS. I did
>> that because rustc seems to be quite unhappy when supplied with
>> `--target ppc64le-linux` or `--target powerpc64le-linux'. I'm trying to
>> understand why, but I'm struggling because rustc seems just fine with
>> `--target x86_64-linux` despite none of `ppc64le-linux`,
>> `powerpc64le-linux` nor `x86_64-linux` appearing in the `rustc --print
>> target-list` output that I could gather.
>>
>> How/why does `--target x86_64-linux` work?
>
> I think in the context of oe-core, all targets are custom ones,
> specified by writing out json files and directing rust to use them. So
> you need to do two things:
> 1. --print target-list is useless and irrelevant, as it only prints
> built-in targets, don't try it.

Ack, certainly experienced that :)

> 2. When there's a problem inspect what json files are in the sysroot,
> what they contain, and whether rust is able to find them.
> x86_64-linux.json is made specifically for building native items.

Thanks, this helped a lot. Before sending the previous mail I had poked 
around a bit and found the json support in rust, but hadn't put enough 
of the puzzle pieces together to make the picture clear. With your 
pointer here I've cut away most of the cruft in the series and am 
testing the rework now.

Andrew

Patch

diff --git a/meta/recipes-devtools/rust/rust.inc b/meta/recipes-devtools/rust/rust.inc
index cc0730e9cd2d..fd934082bddf 100644
--- a/meta/recipes-devtools/rust/rust.inc
+++ b/meta/recipes-devtools/rust/rust.inc
@@ -35,8 +35,11 @@  setup_cargo_environment () {
     # Later stages are build for the native target (i.e. target.x86_64-linux)
     cargo_common_do_configure
 
-    printf '[target.%s]\n' "${SNAPSHOT_BUILD_SYS}" >> ${CARGO_HOME}/config
-    printf "linker = '%s'\n" "${RUST_BUILD_CCLD}" >> ${CARGO_HOME}/config
+    if [ ${SNAPSHOT_BUILD_SYS} != ${RUST_BUILD_SYS} ]
+    then
+        printf '[target.%s]\n' "${SNAPSHOT_BUILD_SYS}" >> ${CARGO_HOME}/config
+        printf "linker = '%s'\n" "${RUST_BUILD_CCLD}" >> ${CARGO_HOME}/config
+    fi
 }
 
 include rust-common.inc
@@ -88,15 +91,16 @@  python do_configure() {
     config.set(target_section, "cxx", e(d.expand("${RUST_TARGET_CXX}")))
     config.set(target_section, "cc", e(d.expand("${RUST_TARGET_CC}")))
 
-    # If we don't do this rust-native will compile it's own llvm for BUILD.
-    # [target.${BUILD_ARCH}-unknown-linux-gnu]
-    target_section = "target.{}".format(d.getVar('SNAPSHOT_BUILD_SYS', True))
-    config.add_section(target_section)
+    if (d.getVar('SNAPSHOT_BUILD_SYS') != d.getVar('RUST_TARGET_SYS')):
+        # If we don't do this rust-native will compile it's own llvm for BUILD.
+        # [target.${BUILD_ARCH}-unknown-linux-gnu]
+        target_section = "target.{}".format(d.getVar('SNAPSHOT_BUILD_SYS', True))
+        config.add_section(target_section)
 
-    config.set(target_section, "llvm-config", e(llvm_config))
+        config.set(target_section, "llvm-config", e(llvm_config))
 
-    config.set(target_section, "cxx", e(d.expand("${RUST_BUILD_CXX}")))
-    config.set(target_section, "cc", e(d.expand("${RUST_BUILD_CC}")))
+        config.set(target_section, "cxx", e(d.expand("${RUST_BUILD_CXX}")))
+        config.set(target_section, "cc", e(d.expand("${RUST_BUILD_CC}")))
 
     # [rust]
     config.add_section("rust")