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 | |
Chih-Hung Hsieh | efdd7ac | 2019-09-26 18:59:27 -0700 | [diff] [blame] | 20 | "github.com/google/blueprint/proptools" |
| 21 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 22 | "android/soong/android" |
| 23 | _ "android/soong/cc/config" |
| 24 | ) |
| 25 | |
| 26 | var pctx = android.NewPackageContext("android/soong/rust/config") |
| 27 | |
| 28 | var ( |
Matthew Maurer | 43f697e | 2019-09-09 16:17:33 -0700 | [diff] [blame] | 29 | RustDefaultVersion = "1.37.0" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 30 | RustDefaultBase = "prebuilts/rust/" |
| 31 | DefaultEdition = "2018" |
| 32 | Stdlibs = []string{ |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 33 | "libstd", |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 34 | "libterm", |
Ivan Lozano | 6d9e712 | 2019-09-20 10:59:56 -0700 | [diff] [blame] | 35 | "libtest", |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 36 | } |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 37 | |
Chih-Hung Hsieh | efdd7ac | 2019-09-26 18:59:27 -0700 | [diff] [blame] | 38 | DefaultDenyWarnings = proptools.BoolPtr(true) |
| 39 | |
Joel Galenson | 724286c | 2019-09-30 13:01:37 -0700 | [diff] [blame^] | 40 | GlobalRustFlags = []string{ |
| 41 | "--remap-path-prefix $$(pwd)=", |
| 42 | } |
| 43 | |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 44 | deviceGlobalRustFlags = []string{} |
| 45 | |
| 46 | deviceGlobalLinkFlags = []string{ |
| 47 | "-Bdynamic", |
| 48 | "-nostdlib", |
| 49 | "-Wl,-z,noexecstack", |
| 50 | "-Wl,-z,relro", |
| 51 | "-Wl,-z,now", |
| 52 | "-Wl,--build-id=md5", |
| 53 | "-Wl,--warn-shared-textrel", |
| 54 | "-Wl,--fatal-warnings", |
| 55 | |
| 56 | "-Wl,--pack-dyn-relocs=android+relr", |
| 57 | "-Wl,--use-android-relr-tags", |
| 58 | "-Wl,--no-undefined", |
| 59 | "-Wl,--hash-style=gnu", |
| 60 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 61 | ) |
| 62 | |
| 63 | func init() { |
| 64 | pctx.SourcePathVariable("RustDefaultBase", RustDefaultBase) |
| 65 | pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS) |
| 66 | |
| 67 | pctx.VariableFunc("RustBase", func(ctx android.PackageVarContext) string { |
| 68 | if override := ctx.Config().Getenv("RUST_PREBUILTS_BASE"); override != "" { |
| 69 | return override |
| 70 | } |
| 71 | return "${RustDefaultBase}" |
| 72 | }) |
| 73 | |
| 74 | pctx.VariableFunc("RustVersion", func(ctx android.PackageVarContext) string { |
| 75 | if override := ctx.Config().Getenv("RUST_PREBUILTS_VERSION"); override != "" { |
| 76 | return override |
| 77 | } |
| 78 | return RustDefaultVersion |
| 79 | }) |
| 80 | |
| 81 | pctx.StaticVariable("RustPath", "${RustBase}/${HostPrebuiltTag}/${RustVersion}") |
| 82 | pctx.StaticVariable("RustBin", "${RustPath}/bin") |
| 83 | |
| 84 | pctx.ImportAs("ccConfig", "android/soong/cc/config") |
| 85 | pctx.StaticVariable("RustLinker", "${ccConfig.ClangBin}/clang++") |
| 86 | pctx.StaticVariable("RustLinkerArgs", "-B ${ccConfig.ClangBin} -fuse-ld=lld") |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 87 | |
| 88 | pctx.StaticVariable("DeviceGlobalLinkFlags", strings.Join(deviceGlobalLinkFlags, " ")) |
| 89 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 90 | } |