blob: 03bea82740498873cf3198c596d8d3fd0ae852db [file] [log] [blame]
Ivan Lozano1c2ff862019-10-21 09:57:38 -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 (
18 "strings"
19
20 "android/soong/android"
21)
22
23var (
Jeff Vander Stoep6e97a7b2020-07-15 21:34:45 +020024 DarwinRustFlags = []string{}
25 DarwinRustLinkFlags = []string{
ThiƩbaud Weksteen682c9d72020-08-31 10:06:16 +020026 "-B${cc_config.MacToolPath}",
Jeff Vander Stoep6e97a7b2020-07-15 21:34:45 +020027 }
Dan Willemsen8528f4e2021-10-19 00:22:06 -070028 darwinArm64Rustflags = []string{}
29 darwinArm64Linkflags = []string{}
Ivan Lozano1c2ff862019-10-21 09:57:38 -070030 darwinX8664Rustflags = []string{}
31 darwinX8664Linkflags = []string{}
32)
33
34func init() {
Dan Willemsen8528f4e2021-10-19 00:22:06 -070035 registerToolchainFactory(android.Darwin, android.Arm64, darwinArm64ToolchainFactory)
Ivan Lozano1c2ff862019-10-21 09:57:38 -070036 registerToolchainFactory(android.Darwin, android.X86_64, darwinX8664ToolchainFactory)
Dan Willemsen8528f4e2021-10-19 00:22:06 -070037
Ivan Lozano1c2ff862019-10-21 09:57:38 -070038 pctx.StaticVariable("DarwinToolchainRustFlags", strings.Join(DarwinRustFlags, " "))
39 pctx.StaticVariable("DarwinToolchainLinkFlags", strings.Join(DarwinRustLinkFlags, " "))
Dan Willemsen8528f4e2021-10-19 00:22:06 -070040
41 pctx.StaticVariable("DarwinToolchainArm64RustFlags", strings.Join(darwinArm64Rustflags, " "))
42 pctx.StaticVariable("DarwinToolchainArm64LinkFlags", strings.Join(darwinArm64Linkflags, " "))
Ivan Lozano1c2ff862019-10-21 09:57:38 -070043 pctx.StaticVariable("DarwinToolchainX8664RustFlags", strings.Join(darwinX8664Rustflags, " "))
44 pctx.StaticVariable("DarwinToolchainX8664LinkFlags", strings.Join(darwinX8664Linkflags, " "))
45
46}
47
48type toolchainDarwin struct {
Dan Willemsen8528f4e2021-10-19 00:22:06 -070049 toolchain64Bit
Ivan Lozano1c2ff862019-10-21 09:57:38 -070050 toolchainRustFlags string
51 toolchainLinkFlags string
52}
53
Dan Willemsen8528f4e2021-10-19 00:22:06 -070054type toolchainDarwinArm64 struct {
Ivan Lozano1c2ff862019-10-21 09:57:38 -070055 toolchainDarwin
56}
57
Dan Willemsen8528f4e2021-10-19 00:22:06 -070058type toolchainDarwinX8664 struct {
59 toolchainDarwin
60}
61
62func (toolchainDarwinArm64) Supported() bool {
63 return true
64}
65
Ivan Lozano1c2ff862019-10-21 09:57:38 -070066func (toolchainDarwinX8664) Supported() bool {
67 return true
68}
69
Dan Willemsen8528f4e2021-10-19 00:22:06 -070070func (toolchainDarwin) Bionic() bool {
Ivan Lozano1c2ff862019-10-21 09:57:38 -070071 return false
72}
73
Dan Willemsen8528f4e2021-10-19 00:22:06 -070074func (t *toolchainDarwinArm64) Name() string {
75 return "arm64"
76}
77
Ivan Lozano1c2ff862019-10-21 09:57:38 -070078func (t *toolchainDarwinX8664) Name() string {
79 return "x86_64"
80}
81
Dan Willemsen8528f4e2021-10-19 00:22:06 -070082func (t *toolchainDarwinArm64) RustTriple() string {
83 return "aarch64-apple-darwin"
84}
85
Ivan Lozano1c2ff862019-10-21 09:57:38 -070086func (t *toolchainDarwinX8664) RustTriple() string {
87 return "x86_64-apple-darwin"
88}
89
Ivan Lozanoc0ccb6b2020-05-28 11:31:16 -040090func (t *toolchainDarwin) SharedLibSuffix() string {
91 return ".dylib"
92}
93
Ivan Lozano33c05282020-07-15 11:33:37 -040094func (t *toolchainDarwin) DylibSuffix() string {
95 return ".rustlib.dylib"
96}
97
Ivan Lozanoc0ccb6b2020-05-28 11:31:16 -040098func (t *toolchainDarwin) ProcMacroSuffix() string {
Ivan Lozano1c2ff862019-10-21 09:57:38 -070099 return ".dylib"
100}
101
Dan Willemsen8528f4e2021-10-19 00:22:06 -0700102func (t *toolchainDarwinArm64) ToolchainLinkFlags() string {
103 // Prepend the lld flags from cc_config so we stay in sync with cc
104 return "${cc_config.DarwinLldflags} ${config.DarwinToolchainLinkFlags} ${config.DarwinToolchainArm64LinkFlags}"
105}
106
107func (t *toolchainDarwinArm64) ToolchainRustFlags() string {
108 return "${config.DarwinToolchainRustFlags} ${config.DarwinToolchainArm64RustFlags}"
109}
110
Ivan Lozano1c2ff862019-10-21 09:57:38 -0700111func (t *toolchainDarwinX8664) ToolchainLinkFlags() string {
Ivan Lozano6d45a982020-09-09 09:08:44 -0400112 // Prepend the lld flags from cc_config so we stay in sync with cc
Colin Cross0523ba22021-07-14 18:45:05 -0700113 return "${cc_config.DarwinLldflags} ${config.DarwinToolchainLinkFlags} ${config.DarwinToolchainX8664LinkFlags}"
Ivan Lozano1c2ff862019-10-21 09:57:38 -0700114}
115
116func (t *toolchainDarwinX8664) ToolchainRustFlags() string {
117 return "${config.DarwinToolchainRustFlags} ${config.DarwinToolchainX8664RustFlags}"
118}
119
Dan Willemsen8528f4e2021-10-19 00:22:06 -0700120func darwinArm64ToolchainFactory(arch android.Arch) Toolchain {
121 return toolchainDarwinArm64Singleton
122}
123
Ivan Lozano1c2ff862019-10-21 09:57:38 -0700124func darwinX8664ToolchainFactory(arch android.Arch) Toolchain {
125 return toolchainDarwinX8664Singleton
126}
127
Dan Willemsen8528f4e2021-10-19 00:22:06 -0700128var toolchainDarwinArm64Singleton Toolchain = &toolchainDarwinArm64{}
Ivan Lozano1c2ff862019-10-21 09:57:38 -0700129var toolchainDarwinX8664Singleton Toolchain = &toolchainDarwinX8664{}