Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 71512f32 authored by Thiébaud Weksteen's avatar Thiébaud Weksteen
Browse files

rust: set STD_ENV_ARCH

In 1.47.0, std::env requires the STD_ENV_ARCH environment variable to be
set to the target architecture [1].

[1] https://github.com/rust-lang/rust/blob/8e8939b8045b7af6076fb718e2e298844aaf4650/library/std/src/env.rs#L866

Bug: 171280890
Test: cd external/rust; mm
Change-Id: If4ddf4b9bad2a1a7518a358a5fb597170a97c67e
parent 37f5a8fb
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import (


	"android/soong/android"
	"android/soong/android"
	"android/soong/cc"
	"android/soong/cc"
	"android/soong/rust/config"
)
)


var (
var (
@@ -138,6 +139,13 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
	crate_name := ctx.RustModule().CrateName()
	crate_name := ctx.RustModule().CrateName()
	targetTriple := ctx.toolchain().RustTriple()
	targetTriple := ctx.toolchain().RustTriple()


	// libstd requires a specific environment variable to be set. This is
	// not officially documented and may be removed in the future. See
	// https://github.com/rust-lang/rust/blob/master/library/std/src/env.rs#L866.
	if crate_name == "std" {
		envVars = append(envVars, "STD_ENV_ARCH="+config.StdEnvArch[ctx.RustModule().Arch().ArchType])
	}

	inputs = append(inputs, main)
	inputs = append(inputs, main)


	// Collect rustc flags
	// Collect rustc flags
+9 −0
Original line number Original line Diff line number Diff line
@@ -32,6 +32,15 @@ var (
		"libtest",
		"libtest",
	}
	}


	// Mapping between Soong internal arch types and std::env constants.
	// Required as Rust uses aarch64 when Soong uses arm64.
	StdEnvArch = map[android.ArchType]string{
		android.Arm:    "arm",
		android.Arm64:  "aarch64",
		android.X86:    "x86",
		android.X86_64: "x86_64",
	}

	GlobalRustFlags = []string{
	GlobalRustFlags = []string{
		"--remap-path-prefix $$(pwd)=",
		"--remap-path-prefix $$(pwd)=",
		"-C codegen-units=1",
		"-C codegen-units=1",