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