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 15package config 16 17import ( 18 "strings" 19 20 "android/soong/android" 21 _ "android/soong/cc/config" 22) 23 24var pctx = android.NewPackageContext("android/soong/rust/config") 25 26var ( 27 RustDefaultVersion = "1.40.0" 28 RustDefaultBase = "prebuilts/rust/" 29 DefaultEdition = "2018" 30 Stdlibs = []string{ 31 "libstd", 32 "libtest", 33 } 34 35 DefaultDenyWarnings = true 36 37 GlobalRustFlags = []string{ 38 "--remap-path-prefix $$(pwd)=", 39 "-C codegen-units=1", 40 "-C opt-level=3", 41 "-C relocation-model=pic", 42 } 43 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,--no-undefined", 58 "-Wl,--hash-style=gnu", 59 } 60) 61 62func init() { 63 pctx.SourcePathVariable("RustDefaultBase", RustDefaultBase) 64 pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS) 65 66 pctx.VariableFunc("RustBase", func(ctx android.PackageVarContext) string { 67 if override := ctx.Config().Getenv("RUST_PREBUILTS_BASE"); override != "" { 68 return override 69 } 70 return "${RustDefaultBase}" 71 }) 72 73 pctx.VariableFunc("RustVersion", func(ctx android.PackageVarContext) string { 74 if override := ctx.Config().Getenv("RUST_PREBUILTS_VERSION"); override != "" { 75 return override 76 } 77 return RustDefaultVersion 78 }) 79 80 pctx.StaticVariable("RustPath", "${RustBase}/${HostPrebuiltTag}/${RustVersion}") 81 pctx.StaticVariable("RustBin", "${RustPath}/bin") 82 83 pctx.ImportAs("ccConfig", "android/soong/cc/config") 84 pctx.StaticVariable("RustLinker", "${ccConfig.ClangBin}/clang++") 85 pctx.StaticVariable("RustLinkerArgs", "-B ${ccConfig.ClangBin} -fuse-ld=lld") 86 87 pctx.StaticVariable("DeviceGlobalLinkFlags", strings.Join(deviceGlobalLinkFlags, " ")) 88 89} 90