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

Commit 59855831 authored by Matthew Maurer's avatar Matthew Maurer Committed by Gerrit Code Review
Browse files

Merge changes I4b86b2e1,Ie0985540 into main

* changes:
  rust-project.json: Set sysroot in generated file
  rust-project.json: Generate proc-macro paths
parents f69bffbc 5524b5b7
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
package config

import (
	"fmt"
	"strings"

	"android/soong/android"
@@ -93,6 +94,16 @@ var (
	}
)

func RustPath(ctx android.PathContext) string {
	// I can't see any way to flatten the static variable inside Soong, so this
	// reproduces the init logic.
	var RustBase string = RustDefaultBase
	if override := ctx.Config().Getenv("RUST_PREBUILTS_BASE"); override != "" {
		RustBase = override
	}
	return fmt.Sprintf("%s/%s/%s", RustBase, HostPrebuiltTag(ctx.Config()), GetRustVersion(ctx))
}

func init() {
	pctx.SourcePathVariable("RustDefaultBase", RustDefaultBase)
	pctx.VariableConfigMethod("HostPrebuiltTag", HostPrebuiltTag)
+26 −16
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import (
	"fmt"

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

// This singleton collects Rust crate definitions and generates a JSON file
@@ -51,9 +52,11 @@ type rustProjectCrate struct {
	Cfg            []string          `json:"cfg"`
	Env            map[string]string `json:"env"`
	ProcMacro      bool              `json:"is_proc_macro"`
	ProcMacroDylib *string           `json:"proc_macro_dylib_path"`
}

type rustProjectJson struct {
	Sysroot string             `json:"sysroot"`
	Crates  []rustProjectCrate `json:"crates"`
}

@@ -135,7 +138,11 @@ func (singleton *projectGeneratorSingleton) addCrate(ctx android.SingletonContex
		return 0, false
	}

	_, procMacro := rModule.compiler.(*procMacroDecorator)
	var procMacroDylib *string = nil
	if procDec, procMacro := rModule.compiler.(*procMacroDecorator); procMacro {
		procMacroDylib = new(string)
		*procMacroDylib = procDec.baseCompiler.unstrippedOutputFilePath().String()
	}

	crate := rustProjectCrate{
		DisplayName:    rModule.Name(),
@@ -144,7 +151,8 @@ func (singleton *projectGeneratorSingleton) addCrate(ctx android.SingletonContex
		Deps:           make([]rustProjectDep, 0),
		Cfg:            make([]string, 0),
		Env:            make(map[string]string),
		ProcMacro:   procMacro,
		ProcMacro:      procMacroDylib != nil,
		ProcMacroDylib: procMacroDylib,
	}

	if rModule.compiler.cargoOutDir().Valid() {
@@ -197,6 +205,8 @@ func (singleton *projectGeneratorSingleton) GenerateBuildActions(ctx android.Sin
		return
	}

	singleton.project.Sysroot = config.RustPath(ctx)

	singleton.knownCrates = make(map[string]crateInfo)
	ctx.VisitAllModules(func(module android.Module) {
		singleton.appendCrateAndDependencies(ctx, module)