blob: 2f4d930e7d07d12702941c295d2e3a19533457bf [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 (
Jeff Vander Stoep3a9d80a2020-08-14 13:53:14 +020027 RustDefaultVersion = "1.45.2"
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 Lozano6d9e7122019-09-20 10:59:56 -070032 "libtest",
Ivan Lozanoffee3342019-08-27 12:03:00 -070033 }
Ivan Lozanof1c84332019-09-20 11:00:37 -070034
Joel Galenson724286c2019-09-30 13:01:37 -070035 GlobalRustFlags = []string{
36 "--remap-path-prefix $$(pwd)=",
Ivan Lozano31b095d2019-11-20 10:14:33 -080037 "-C codegen-units=1",
38 "-C opt-level=3",
39 "-C relocation-model=pic",
Joel Galenson724286c2019-09-30 13:01:37 -070040 }
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",
Thiébaud Weksteen19e1c6c2020-08-19 15:01:44 +020055 "-Wl,--use-android-relr-tags",
Ivan Lozanof1c84332019-09-20 11:00:37 -070056 "-Wl,--no-undefined",
57 "-Wl,--hash-style=gnu",
Jeff Vander Stoep6e97a7b2020-07-15 21:34:45 +020058
Thiébaud Weksteen682c9d72020-08-31 10:06:16 +020059 "-B${cc_config.ClangBin}",
Jeff Vander Stoep6e97a7b2020-07-15 21:34:45 +020060 "-fuse-ld=lld",
Ivan Lozanof1c84332019-09-20 11:00:37 -070061 }
Ivan Lozanoffee3342019-08-27 12:03:00 -070062)
63
64func 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
Thiébaud Weksteen682c9d72020-08-31 10:06:16 +020085 pctx.ImportAs("cc_config", "android/soong/cc/config")
86 pctx.StaticVariable("RustLinker", "${cc_config.ClangBin}/clang++")
Jeff Vander Stoep6e97a7b2020-07-15 21:34:45 +020087 pctx.StaticVariable("RustLinkerArgs", "")
Ivan Lozanof1c84332019-09-20 11:00:37 -070088
89 pctx.StaticVariable("DeviceGlobalLinkFlags", strings.Join(deviceGlobalLinkFlags, " "))
90
Ivan Lozanoffee3342019-08-27 12:03:00 -070091}