blob: c66c3c1132dc39541c7bdabb9d99a720d3261fad [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
Chih-Hung Hsiehefdd7ac2019-09-26 18:59:27 -070020 "github.com/google/blueprint/proptools"
21
Ivan Lozanoffee3342019-08-27 12:03:00 -070022 "android/soong/android"
23 _ "android/soong/cc/config"
24)
25
26var pctx = android.NewPackageContext("android/soong/rust/config")
27
28var (
Matthew Maurer43f697e2019-09-09 16:17:33 -070029 RustDefaultVersion = "1.37.0"
Ivan Lozanoffee3342019-08-27 12:03:00 -070030 RustDefaultBase = "prebuilts/rust/"
31 DefaultEdition = "2018"
32 Stdlibs = []string{
Ivan Lozanoffee3342019-08-27 12:03:00 -070033 "libstd",
Ivan Lozanoffee3342019-08-27 12:03:00 -070034 "libterm",
Ivan Lozano6d9e7122019-09-20 10:59:56 -070035 "libtest",
Ivan Lozanoffee3342019-08-27 12:03:00 -070036 }
Ivan Lozanof1c84332019-09-20 11:00:37 -070037
Chih-Hung Hsiehefdd7ac2019-09-26 18:59:27 -070038 DefaultDenyWarnings = proptools.BoolPtr(true)
39
Ivan Lozanof1c84332019-09-20 11:00:37 -070040 deviceGlobalRustFlags = []string{}
41
42 deviceGlobalLinkFlags = []string{
43 "-Bdynamic",
44 "-nostdlib",
45 "-Wl,-z,noexecstack",
46 "-Wl,-z,relro",
47 "-Wl,-z,now",
48 "-Wl,--build-id=md5",
49 "-Wl,--warn-shared-textrel",
50 "-Wl,--fatal-warnings",
51
52 "-Wl,--pack-dyn-relocs=android+relr",
53 "-Wl,--use-android-relr-tags",
54 "-Wl,--no-undefined",
55 "-Wl,--hash-style=gnu",
56 }
Ivan Lozanoffee3342019-08-27 12:03:00 -070057)
58
59func init() {
60 pctx.SourcePathVariable("RustDefaultBase", RustDefaultBase)
61 pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
62
63 pctx.VariableFunc("RustBase", func(ctx android.PackageVarContext) string {
64 if override := ctx.Config().Getenv("RUST_PREBUILTS_BASE"); override != "" {
65 return override
66 }
67 return "${RustDefaultBase}"
68 })
69
70 pctx.VariableFunc("RustVersion", func(ctx android.PackageVarContext) string {
71 if override := ctx.Config().Getenv("RUST_PREBUILTS_VERSION"); override != "" {
72 return override
73 }
74 return RustDefaultVersion
75 })
76
77 pctx.StaticVariable("RustPath", "${RustBase}/${HostPrebuiltTag}/${RustVersion}")
78 pctx.StaticVariable("RustBin", "${RustPath}/bin")
79
80 pctx.ImportAs("ccConfig", "android/soong/cc/config")
81 pctx.StaticVariable("RustLinker", "${ccConfig.ClangBin}/clang++")
82 pctx.StaticVariable("RustLinkerArgs", "-B ${ccConfig.ClangBin} -fuse-ld=lld")
Ivan Lozanof1c84332019-09-20 11:00:37 -070083
84 pctx.StaticVariable("DeviceGlobalLinkFlags", strings.Join(deviceGlobalLinkFlags, " "))
85
Ivan Lozanoffee3342019-08-27 12:03:00 -070086}