Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 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 | |
| 15 | package config |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | var ( |
Jeff Vander Stoep | 6e97a7b | 2020-07-15 21:34:45 +0200 | [diff] [blame] | 24 | DarwinRustFlags = []string{} |
| 25 | DarwinRustLinkFlags = []string{ |
ThiƩbaud Weksteen | 682c9d7 | 2020-08-31 10:06:16 +0200 | [diff] [blame] | 26 | "-B${cc_config.MacToolPath}", |
Jeff Vander Stoep | 6e97a7b | 2020-07-15 21:34:45 +0200 | [diff] [blame] | 27 | } |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 28 | darwinArm64Rustflags = []string{} |
| 29 | darwinArm64Linkflags = []string{} |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 30 | darwinX8664Rustflags = []string{} |
| 31 | darwinX8664Linkflags = []string{} |
| 32 | ) |
| 33 | |
| 34 | func init() { |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 35 | registerToolchainFactory(android.Darwin, android.Arm64, darwinArm64ToolchainFactory) |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 36 | registerToolchainFactory(android.Darwin, android.X86_64, darwinX8664ToolchainFactory) |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 37 | |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 38 | pctx.StaticVariable("DarwinToolchainRustFlags", strings.Join(DarwinRustFlags, " ")) |
| 39 | pctx.StaticVariable("DarwinToolchainLinkFlags", strings.Join(DarwinRustLinkFlags, " ")) |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 40 | |
| 41 | pctx.StaticVariable("DarwinToolchainArm64RustFlags", strings.Join(darwinArm64Rustflags, " ")) |
| 42 | pctx.StaticVariable("DarwinToolchainArm64LinkFlags", strings.Join(darwinArm64Linkflags, " ")) |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 43 | pctx.StaticVariable("DarwinToolchainX8664RustFlags", strings.Join(darwinX8664Rustflags, " ")) |
| 44 | pctx.StaticVariable("DarwinToolchainX8664LinkFlags", strings.Join(darwinX8664Linkflags, " ")) |
| 45 | |
| 46 | } |
| 47 | |
| 48 | type toolchainDarwin struct { |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 49 | toolchain64Bit |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 50 | toolchainRustFlags string |
| 51 | toolchainLinkFlags string |
| 52 | } |
| 53 | |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 54 | type toolchainDarwinArm64 struct { |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 55 | toolchainDarwin |
| 56 | } |
| 57 | |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 58 | type toolchainDarwinX8664 struct { |
| 59 | toolchainDarwin |
| 60 | } |
| 61 | |
| 62 | func (toolchainDarwinArm64) Supported() bool { |
| 63 | return true |
| 64 | } |
| 65 | |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 66 | func (toolchainDarwinX8664) Supported() bool { |
| 67 | return true |
| 68 | } |
| 69 | |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 70 | func (toolchainDarwin) Bionic() bool { |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 71 | return false |
| 72 | } |
| 73 | |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 74 | func (t *toolchainDarwinArm64) Name() string { |
| 75 | return "arm64" |
| 76 | } |
| 77 | |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 78 | func (t *toolchainDarwinX8664) Name() string { |
| 79 | return "x86_64" |
| 80 | } |
| 81 | |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 82 | func (t *toolchainDarwinArm64) RustTriple() string { |
| 83 | return "aarch64-apple-darwin" |
| 84 | } |
| 85 | |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 86 | func (t *toolchainDarwinX8664) RustTriple() string { |
| 87 | return "x86_64-apple-darwin" |
| 88 | } |
| 89 | |
Ivan Lozano | c0ccb6b | 2020-05-28 11:31:16 -0400 | [diff] [blame] | 90 | func (t *toolchainDarwin) SharedLibSuffix() string { |
| 91 | return ".dylib" |
| 92 | } |
| 93 | |
Ivan Lozano | 33c0528 | 2020-07-15 11:33:37 -0400 | [diff] [blame] | 94 | func (t *toolchainDarwin) DylibSuffix() string { |
| 95 | return ".rustlib.dylib" |
| 96 | } |
| 97 | |
Ivan Lozano | c0ccb6b | 2020-05-28 11:31:16 -0400 | [diff] [blame] | 98 | func (t *toolchainDarwin) ProcMacroSuffix() string { |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 99 | return ".dylib" |
| 100 | } |
| 101 | |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 102 | func (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 | |
| 107 | func (t *toolchainDarwinArm64) ToolchainRustFlags() string { |
| 108 | return "${config.DarwinToolchainRustFlags} ${config.DarwinToolchainArm64RustFlags}" |
| 109 | } |
| 110 | |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 111 | func (t *toolchainDarwinX8664) ToolchainLinkFlags() string { |
Ivan Lozano | 6d45a98 | 2020-09-09 09:08:44 -0400 | [diff] [blame] | 112 | // Prepend the lld flags from cc_config so we stay in sync with cc |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 113 | return "${cc_config.DarwinLldflags} ${config.DarwinToolchainLinkFlags} ${config.DarwinToolchainX8664LinkFlags}" |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | func (t *toolchainDarwinX8664) ToolchainRustFlags() string { |
| 117 | return "${config.DarwinToolchainRustFlags} ${config.DarwinToolchainX8664RustFlags}" |
| 118 | } |
| 119 | |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 120 | func darwinArm64ToolchainFactory(arch android.Arch) Toolchain { |
| 121 | return toolchainDarwinArm64Singleton |
| 122 | } |
| 123 | |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 124 | func darwinX8664ToolchainFactory(arch android.Arch) Toolchain { |
| 125 | return toolchainDarwinX8664Singleton |
| 126 | } |
| 127 | |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 128 | var toolchainDarwinArm64Singleton Toolchain = &toolchainDarwinArm64{} |
Ivan Lozano | 1c2ff86 | 2019-10-21 09:57:38 -0700 | [diff] [blame] | 129 | var toolchainDarwinX8664Singleton Toolchain = &toolchainDarwinX8664{} |