blob: 08ec87777b41bae9f784998d5164122464489b18 [file] [log] [blame]
Ivan Lozanoffee3342019-08-27 12:03:00 -07001// Copyright 2019 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package config
16
17import (
Ivan Lozanof1c84332019-09-20 11:00:37 -070018 "strings"
19
Ivan Lozanoffee3342019-08-27 12:03:00 -070020 "android/soong/android"
21 _ "android/soong/cc/config"
22)
23
24var pctx = android.NewPackageContext("android/soong/rust/config")
25
26var (
Thiébaud Weksteencb738202021-01-08 14:12:18 +010027 RustDefaultVersion = "1.49.0"
Ivan Lozanoffee3342019-08-27 12:03:00 -070028 RustDefaultBase = "prebuilts/rust/"
29 DefaultEdition = "2018"
30 Stdlibs = []string{
Ivan Lozanoffee3342019-08-27 12:03:00 -070031 "libstd",
Ivan Lozano6d9e7122019-09-20 10:59:56 -070032 "libtest",
Ivan Lozanoffee3342019-08-27 12:03:00 -070033 }
Ivan Lozanof1c84332019-09-20 11:00:37 -070034
Thiébaud Weksteen71512f32020-11-03 15:17:51 +010035 // Mapping between Soong internal arch types and std::env constants.
36 // Required as Rust uses aarch64 when Soong uses arm64.
37 StdEnvArch = map[android.ArchType]string{
38 android.Arm: "arm",
39 android.Arm64: "aarch64",
40 android.X86: "x86",
41 android.X86_64: "x86_64",
42 }
43
Joel Galenson724286c2019-09-30 13:01:37 -070044 GlobalRustFlags = []string{
45 "--remap-path-prefix $$(pwd)=",
Ivan Lozano31b095d2019-11-20 10:14:33 -080046 "-C codegen-units=1",
Peter Collingbourneb143cd92020-12-30 21:14:37 -080047 "-C debuginfo=2",
Ivan Lozano31b095d2019-11-20 10:14:33 -080048 "-C opt-level=3",
49 "-C relocation-model=pic",
Joel Galenson724286c2019-09-30 13:01:37 -070050 }
51
Ivan Lozanof1c84332019-09-20 11:00:37 -070052 deviceGlobalRustFlags = []string{}
53
54 deviceGlobalLinkFlags = []string{
Ivan Lozano6d45a982020-09-09 09:08:44 -040055 // Prepend the lld flags from cc_config so we stay in sync with cc
56 "${cc_config.DeviceGlobalLldflags}",
57
58 // Override cc's --no-undefined-version to allow rustc's generated alloc functions
59 "-Wl,--undefined-version",
60
Ivan Lozanof1c84332019-09-20 11:00:37 -070061 "-Bdynamic",
62 "-nostdlib",
Ivan Lozanof1c84332019-09-20 11:00:37 -070063 "-Wl,--pack-dyn-relocs=android+relr",
Thiébaud Weksteen19e1c6c2020-08-19 15:01:44 +020064 "-Wl,--use-android-relr-tags",
Ivan Lozanof1c84332019-09-20 11:00:37 -070065 "-Wl,--no-undefined",
Thiébaud Weksteen682c9d72020-08-31 10:06:16 +020066 "-B${cc_config.ClangBin}",
Ivan Lozanof1c84332019-09-20 11:00:37 -070067 }
Ivan Lozanoffee3342019-08-27 12:03:00 -070068)
69
70func init() {
71 pctx.SourcePathVariable("RustDefaultBase", RustDefaultBase)
72 pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
73
74 pctx.VariableFunc("RustBase", func(ctx android.PackageVarContext) string {
75 if override := ctx.Config().Getenv("RUST_PREBUILTS_BASE"); override != "" {
76 return override
77 }
78 return "${RustDefaultBase}"
79 })
80
81 pctx.VariableFunc("RustVersion", func(ctx android.PackageVarContext) string {
82 if override := ctx.Config().Getenv("RUST_PREBUILTS_VERSION"); override != "" {
83 return override
84 }
85 return RustDefaultVersion
86 })
87
88 pctx.StaticVariable("RustPath", "${RustBase}/${HostPrebuiltTag}/${RustVersion}")
89 pctx.StaticVariable("RustBin", "${RustPath}/bin")
90
Thiébaud Weksteen682c9d72020-08-31 10:06:16 +020091 pctx.ImportAs("cc_config", "android/soong/cc/config")
92 pctx.StaticVariable("RustLinker", "${cc_config.ClangBin}/clang++")
Jeff Vander Stoep6e97a7b2020-07-15 21:34:45 +020093 pctx.StaticVariable("RustLinkerArgs", "")
Ivan Lozanof1c84332019-09-20 11:00:37 -070094
95 pctx.StaticVariable("DeviceGlobalLinkFlags", strings.Join(deviceGlobalLinkFlags, " "))
96
Ivan Lozanoffee3342019-08-27 12:03:00 -070097}