blob: 7846d212ed68140db0706ed7615606def347b039 [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 (
Matthew Maurer43f697e2019-09-09 16:17:33 -070027 RustDefaultVersion = "1.37.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 Lozanoffee3342019-08-27 12:03:00 -070032 "libterm",
Ivan Lozano6d9e7122019-09-20 10:59:56 -070033 "libtest",
Ivan Lozanoffee3342019-08-27 12:03:00 -070034 }
Ivan Lozanof1c84332019-09-20 11:00:37 -070035
Chih-Hung Hsieh961a30c2019-10-03 09:47:06 -070036 DefaultDenyWarnings = true
Chih-Hung Hsiehefdd7ac2019-09-26 18:59:27 -070037
Joel Galenson724286c2019-09-30 13:01:37 -070038 GlobalRustFlags = []string{
39 "--remap-path-prefix $$(pwd)=",
40 }
41
Ivan Lozanof1c84332019-09-20 11:00:37 -070042 deviceGlobalRustFlags = []string{}
43
44 deviceGlobalLinkFlags = []string{
45 "-Bdynamic",
46 "-nostdlib",
47 "-Wl,-z,noexecstack",
48 "-Wl,-z,relro",
49 "-Wl,-z,now",
50 "-Wl,--build-id=md5",
51 "-Wl,--warn-shared-textrel",
52 "-Wl,--fatal-warnings",
53
54 "-Wl,--pack-dyn-relocs=android+relr",
55 "-Wl,--use-android-relr-tags",
56 "-Wl,--no-undefined",
57 "-Wl,--hash-style=gnu",
58 }
Ivan Lozanoffee3342019-08-27 12:03:00 -070059)
60
61func init() {
62 pctx.SourcePathVariable("RustDefaultBase", RustDefaultBase)
63 pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
64
65 pctx.VariableFunc("RustBase", func(ctx android.PackageVarContext) string {
66 if override := ctx.Config().Getenv("RUST_PREBUILTS_BASE"); override != "" {
67 return override
68 }
69 return "${RustDefaultBase}"
70 })
71
72 pctx.VariableFunc("RustVersion", func(ctx android.PackageVarContext) string {
73 if override := ctx.Config().Getenv("RUST_PREBUILTS_VERSION"); override != "" {
74 return override
75 }
76 return RustDefaultVersion
77 })
78
79 pctx.StaticVariable("RustPath", "${RustBase}/${HostPrebuiltTag}/${RustVersion}")
80 pctx.StaticVariable("RustBin", "${RustPath}/bin")
81
82 pctx.ImportAs("ccConfig", "android/soong/cc/config")
83 pctx.StaticVariable("RustLinker", "${ccConfig.ClangBin}/clang++")
84 pctx.StaticVariable("RustLinkerArgs", "-B ${ccConfig.ClangBin} -fuse-ld=lld")
Ivan Lozanof1c84332019-09-20 11:00:37 -070085
86 pctx.StaticVariable("DeviceGlobalLinkFlags", strings.Join(deviceGlobalLinkFlags, " "))
87
Ivan Lozanoffee3342019-08-27 12:03:00 -070088}