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
15package config
16
17import (
18	"strings"
19
20	"android/soong/android"
21)
22
23var (
24	DarwinRustFlags     = []string{}
25	DarwinRustLinkFlags = []string{
26		"-B${cc_config.MacToolPath}",
27	}
28	darwinX8664Rustflags = []string{}
29	darwinX8664Linkflags = []string{}
30)
31
32func init() {
33	registerToolchainFactory(android.Darwin, android.X86_64, darwinX8664ToolchainFactory)
34	pctx.StaticVariable("DarwinToolchainRustFlags", strings.Join(DarwinRustFlags, " "))
35	pctx.StaticVariable("DarwinToolchainLinkFlags", strings.Join(DarwinRustLinkFlags, " "))
36	pctx.StaticVariable("DarwinToolchainX8664RustFlags", strings.Join(darwinX8664Rustflags, " "))
37	pctx.StaticVariable("DarwinToolchainX8664LinkFlags", strings.Join(darwinX8664Linkflags, " "))
38
39}
40
41type toolchainDarwin struct {
42	toolchainRustFlags string
43	toolchainLinkFlags string
44}
45
46type toolchainDarwinX8664 struct {
47	toolchain64Bit
48	toolchainDarwin
49}
50
51func (toolchainDarwinX8664) Supported() bool {
52	return true
53}
54
55func (toolchainDarwinX8664) Bionic() bool {
56	return false
57}
58
59func (t *toolchainDarwinX8664) Name() string {
60	return "x86_64"
61}
62
63func (t *toolchainDarwinX8664) RustTriple() string {
64	return "x86_64-apple-darwin"
65}
66
67func (t *toolchainDarwin) SharedLibSuffix() string {
68	return ".dylib"
69}
70
71func (t *toolchainDarwin) DylibSuffix() string {
72	return ".rustlib.dylib"
73}
74
75func (t *toolchainDarwin) ProcMacroSuffix() string {
76	return ".dylib"
77}
78
79func (t *toolchainDarwinX8664) ToolchainLinkFlags() string {
80	// Prepend the lld flags from cc_config so we stay in sync with cc
81	return "${cc_config.DarwinClangLldflags} ${config.DarwinToolchainLinkFlags} ${config.DarwinToolchainX8664LinkFlags}"
82}
83
84func (t *toolchainDarwinX8664) ToolchainRustFlags() string {
85	return "${config.DarwinToolchainRustFlags} ${config.DarwinToolchainX8664RustFlags}"
86}
87
88func darwinX8664ToolchainFactory(arch android.Arch) Toolchain {
89	return toolchainDarwinX8664Singleton
90}
91
92var toolchainDarwinX8664Singleton Toolchain = &toolchainDarwinX8664{}
93