[RFC,1/8] rust: Migrate arch_to_rust_target_arch() to rust-common class

Message ID 20220222035234.463162-2-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 will allow us to use it elsewhere for architecture name
translation. This move is motivated by powerpc64le support.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 meta/classes/rust-common.bbclass           | 16 ++++++++++++++++
 meta/recipes-devtools/rust/rust-common.inc | 16 ----------------
 2 files changed, 16 insertions(+), 16 deletions(-)

Comments

Richard Purdie Feb. 22, 2022, 10:05 a.m. UTC | #1
On Tue, 2022-02-22 at 14:22 +1030, Andrew Jeffery wrote:
> This will allow us to use it elsewhere for architecture name
> translation. This move is motivated by powerpc64le support.
> 
> Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
> ---
>  meta/classes/rust-common.bbclass           | 16 ++++++++++++++++
>  meta/recipes-devtools/rust/rust-common.inc | 16 ----------------
>  2 files changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/meta/classes/rust-common.bbclass b/meta/classes/rust-common.bbclass
> index 98d65970e8c0..2f2a31867ad0 100644
> --- a/meta/classes/rust-common.bbclass
> +++ b/meta/classes/rust-common.bbclass
> @@ -1,5 +1,21 @@
>  inherit python3native
>  
> +# Convert a normal arch (HOST_ARCH, TARGET_ARCH, BUILD_ARCH, etc) to something
> +# rust's internals won't choke on.
> +def arch_to_rust_target_arch(arch):
> +    if arch == "i586" or arch == "i686":
> +        return "x86"
> +    elif arch == "mipsel":
> +        return "mips"
> +    elif arch == "mip64sel":
> +        return "mips64"
> +    elif arch == "armv7":
> +        return "arm"
> +    elif arch == "powerpc64le":
> +        return "powerpc64"
> +    else:
> +        return arch
> +
>  # Common variables used by all Rust builds
>  export rustlibdir = "${libdir}/rust"
>  FILES:${PN} += "${rustlibdir}/*.so"


If we're moving this, it may be a good candidate to move to a new
meta/lib/oe/rust.py python function library for rust. I appreciate that is
slightly move involved and will likely need the imports in base.bbclass to be
tweaked but is probably the better long term fix.

Cheers,

Richard
Andrew Jeffery Feb. 23, 2022, 12:41 a.m. UTC | #2
On Tue, 22 Feb 2022, at 20:35, Richard Purdie wrote:
> On Tue, 2022-02-22 at 14:22 +1030, Andrew Jeffery wrote:
>> This will allow us to use it elsewhere for architecture name
>> translation. This move is motivated by powerpc64le support.
>> 
>> Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
>> ---
>>  meta/classes/rust-common.bbclass           | 16 ++++++++++++++++
>>  meta/recipes-devtools/rust/rust-common.inc | 16 ----------------
>>  2 files changed, 16 insertions(+), 16 deletions(-)
>> 
>> diff --git a/meta/classes/rust-common.bbclass b/meta/classes/rust-common.bbclass
>> index 98d65970e8c0..2f2a31867ad0 100644
>> --- a/meta/classes/rust-common.bbclass
>> +++ b/meta/classes/rust-common.bbclass
>> @@ -1,5 +1,21 @@
>>  inherit python3native
>>  
>> +# Convert a normal arch (HOST_ARCH, TARGET_ARCH, BUILD_ARCH, etc) to something
>> +# rust's internals won't choke on.
>> +def arch_to_rust_target_arch(arch):
>> +    if arch == "i586" or arch == "i686":
>> +        return "x86"
>> +    elif arch == "mipsel":
>> +        return "mips"
>> +    elif arch == "mip64sel":
>> +        return "mips64"
>> +    elif arch == "armv7":
>> +        return "arm"
>> +    elif arch == "powerpc64le":
>> +        return "powerpc64"
>> +    else:
>> +        return arch
>> +
>>  # Common variables used by all Rust builds
>>  export rustlibdir = "${libdir}/rust"
>>  FILES:${PN} += "${rustlibdir}/*.so"
>
>
> If we're moving this, it may be a good candidate to move to a new
> meta/lib/oe/rust.py python function library for rust. I appreciate that is
> slightly move involved and will likely need the imports in base.bbclass to be
> tweaked but is probably the better long term fix.

I'll take a look.

Andrew

Patch

diff --git a/meta/classes/rust-common.bbclass b/meta/classes/rust-common.bbclass
index 98d65970e8c0..2f2a31867ad0 100644
--- a/meta/classes/rust-common.bbclass
+++ b/meta/classes/rust-common.bbclass
@@ -1,5 +1,21 @@ 
 inherit python3native
 
+# Convert a normal arch (HOST_ARCH, TARGET_ARCH, BUILD_ARCH, etc) to something
+# rust's internals won't choke on.
+def arch_to_rust_target_arch(arch):
+    if arch == "i586" or arch == "i686":
+        return "x86"
+    elif arch == "mipsel":
+        return "mips"
+    elif arch == "mip64sel":
+        return "mips64"
+    elif arch == "armv7":
+        return "arm"
+    elif arch == "powerpc64le":
+        return "powerpc64"
+    else:
+        return arch
+
 # Common variables used by all Rust builds
 export rustlibdir = "${libdir}/rust"
 FILES:${PN} += "${rustlibdir}/*.so"
diff --git a/meta/recipes-devtools/rust/rust-common.inc b/meta/recipes-devtools/rust/rust-common.inc
index ceeee9786376..742933f1bd22 100644
--- a/meta/recipes-devtools/rust/rust-common.inc
+++ b/meta/recipes-devtools/rust/rust-common.inc
@@ -254,22 +254,6 @@  def sys_for(d, thing):
 def prefix_for(d, thing):
     return d.getVar('{}_PREFIX'.format(thing))
 
-# Convert a normal arch (HOST_ARCH, TARGET_ARCH, BUILD_ARCH, etc) to something
-# rust's internals won't choke on.
-def arch_to_rust_target_arch(arch):
-    if arch == "i586" or arch == "i686":
-        return "x86"
-    elif arch == "mipsel":
-        return "mips"
-    elif arch == "mip64sel":
-        return "mips64"
-    elif arch == "armv7":
-        return "arm"
-    elif arch == "powerpc64le":
-        return "powerpc64"
-    else:
-        return arch
-
 # generates our target CPU value
 def llvm_cpu(d):
     cpu = d.getVar('PACKAGE_ARCH')