1// Copyright 2020 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	LinuxBionicRustFlags = []string{
25		"-C panic=abort",
26	}
27	LinuxBionicRustLinkFlags = []string{
28		"-B${cc_config.ClangBin}",
29		"-fuse-ld=lld",
30		"-Wl,--undefined-version",
31		"-nostdlib",
32	}
33)
34
35func init() {
36	registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicX8664ToolchainFactory)
37
38	pctx.StaticVariable("LinuxBionicToolchainRustFlags", strings.Join(LinuxBionicRustFlags, " "))
39	pctx.StaticVariable("LinuxBionicToolchainLinkFlags", strings.Join(LinuxBionicRustLinkFlags, " "))
40}
41
42type toolchainLinuxBionicX8664 struct {
43	toolchain64Bit
44}
45
46func (toolchainLinuxBionicX8664) Supported() bool {
47	return true
48}
49
50func (toolchainLinuxBionicX8664) Bionic() bool {
51	return true
52}
53
54func (t *toolchainLinuxBionicX8664) Name() string {
55	return "x86_64"
56}
57
58func (t *toolchainLinuxBionicX8664) RustTriple() string {
59	return "x86_64-linux-android"
60}
61
62func (t *toolchainLinuxBionicX8664) ToolchainLinkFlags() string {
63	// Prepend the lld flags from cc_config so we stay in sync with cc
64	return "${cc_config.LinuxBionicLldflags} ${config.LinuxBionicToolchainLinkFlags}"
65}
66
67func (t *toolchainLinuxBionicX8664) ToolchainRustFlags() string {
68	return "${config.LinuxBionicToolchainRustFlags}"
69}
70
71func linuxBionicX8664ToolchainFactory(arch android.Arch) Toolchain {
72	return toolchainLinuxBionicX8664Singleton
73}
74
75var toolchainLinuxBionicX8664Singleton Toolchain = &toolchainLinuxBionicX8664{}
76