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