Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package config |
| 16 | |
| 17 | import ( |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 18 | "strings" |
| 19 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 20 | "android/soong/android" |
| 21 | _ "android/soong/cc/config" |
| 22 | ) |
| 23 | |
| 24 | var pctx = android.NewPackageContext("android/soong/rust/config") |
| 25 | |
| 26 | var ( |
Thiébaud Weksteen | cb73820 | 2021-01-08 14:12:18 +0100 | [diff] [blame] | 27 | RustDefaultVersion = "1.49.0" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 28 | RustDefaultBase = "prebuilts/rust/" |
| 29 | DefaultEdition = "2018" |
| 30 | Stdlibs = []string{ |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 31 | "libstd", |
Ivan Lozano | 6d9e712 | 2019-09-20 10:59:56 -0700 | [diff] [blame] | 32 | "libtest", |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 33 | } |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 34 | |
Thiébaud Weksteen | 71512f3 | 2020-11-03 15:17:51 +0100 | [diff] [blame] | 35 | // 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 Galenson | 724286c | 2019-09-30 13:01:37 -0700 | [diff] [blame] | 44 | GlobalRustFlags = []string{ |
| 45 | "--remap-path-prefix $$(pwd)=", |
Ivan Lozano | 31b095d | 2019-11-20 10:14:33 -0800 | [diff] [blame] | 46 | "-C codegen-units=1", |
Peter Collingbourne | b143cd9 | 2020-12-30 21:14:37 -0800 | [diff] [blame] | 47 | "-C debuginfo=2", |
Ivan Lozano | 31b095d | 2019-11-20 10:14:33 -0800 | [diff] [blame] | 48 | "-C opt-level=3", |
| 49 | "-C relocation-model=pic", |
Joel Galenson | 724286c | 2019-09-30 13:01:37 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Jeff Vander Stoep | bf7a902 | 2021-01-26 14:35:38 +0100 | [diff] [blame] | 52 | deviceGlobalRustFlags = []string{ |
| 53 | "-C panic=abort", |
| 54 | } |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 55 | |
| 56 | deviceGlobalLinkFlags = []string{ |
Ivan Lozano | 6d45a98 | 2020-09-09 09:08:44 -0400 | [diff] [blame] | 57 | // Prepend the lld flags from cc_config so we stay in sync with cc |
| 58 | "${cc_config.DeviceGlobalLldflags}", |
| 59 | |
| 60 | // Override cc's --no-undefined-version to allow rustc's generated alloc functions |
| 61 | "-Wl,--undefined-version", |
| 62 | |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 63 | "-Bdynamic", |
| 64 | "-nostdlib", |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 65 | "-Wl,--pack-dyn-relocs=android+relr", |
Thiébaud Weksteen | 19e1c6c | 2020-08-19 15:01:44 +0200 | [diff] [blame] | 66 | "-Wl,--use-android-relr-tags", |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 67 | "-Wl,--no-undefined", |
Thiébaud Weksteen | 682c9d7 | 2020-08-31 10:06:16 +0200 | [diff] [blame] | 68 | "-B${cc_config.ClangBin}", |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 69 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 70 | ) |
| 71 | |
| 72 | func init() { |
| 73 | pctx.SourcePathVariable("RustDefaultBase", RustDefaultBase) |
| 74 | pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS) |
| 75 | |
| 76 | pctx.VariableFunc("RustBase", func(ctx android.PackageVarContext) string { |
| 77 | if override := ctx.Config().Getenv("RUST_PREBUILTS_BASE"); override != "" { |
| 78 | return override |
| 79 | } |
| 80 | return "${RustDefaultBase}" |
| 81 | }) |
| 82 | |
| 83 | pctx.VariableFunc("RustVersion", func(ctx android.PackageVarContext) string { |
| 84 | if override := ctx.Config().Getenv("RUST_PREBUILTS_VERSION"); override != "" { |
| 85 | return override |
| 86 | } |
| 87 | return RustDefaultVersion |
| 88 | }) |
| 89 | |
| 90 | pctx.StaticVariable("RustPath", "${RustBase}/${HostPrebuiltTag}/${RustVersion}") |
| 91 | pctx.StaticVariable("RustBin", "${RustPath}/bin") |
| 92 | |
Thiébaud Weksteen | 682c9d7 | 2020-08-31 10:06:16 +0200 | [diff] [blame] | 93 | pctx.ImportAs("cc_config", "android/soong/cc/config") |
| 94 | pctx.StaticVariable("RustLinker", "${cc_config.ClangBin}/clang++") |
Jeff Vander Stoep | 6e97a7b | 2020-07-15 21:34:45 +0200 | [diff] [blame] | 95 | pctx.StaticVariable("RustLinkerArgs", "") |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 96 | |
| 97 | pctx.StaticVariable("DeviceGlobalLinkFlags", strings.Join(deviceGlobalLinkFlags, " ")) |
| 98 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 99 | } |