2016-07-29 22:44:28 +02:00
|
|
|
// Copyright 2016 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package config
|
2015-05-01 01:36:18 +02:00
|
|
|
|
|
|
|
import (
|
2020-04-01 23:32:52 +02:00
|
|
|
"fmt"
|
2015-12-15 05:02:44 +01:00
|
|
|
"os/exec"
|
2017-03-13 20:40:30 +01:00
|
|
|
"path/filepath"
|
2015-05-01 01:36:18 +02:00
|
|
|
"strings"
|
2020-04-01 23:32:52 +02:00
|
|
|
"sync"
|
2015-05-01 01:36:18 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2015-05-01 01:36:18 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
darwinCflags = []string{
|
|
|
|
"-fPIC",
|
|
|
|
"-funwind-tables",
|
|
|
|
|
|
|
|
"-isysroot ${macSdkRoot}",
|
2016-10-27 04:20:58 +02:00
|
|
|
"-mmacosx-version-min=${macMinVersion}",
|
|
|
|
"-DMACOSX_DEPLOYMENT_TARGET=${macMinVersion}",
|
2018-08-29 02:12:56 +02:00
|
|
|
|
|
|
|
"-m64",
|
2021-07-15 02:03:16 +02:00
|
|
|
|
|
|
|
"-integrated-as",
|
|
|
|
"-fstack-protector-strong",
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
darwinLdflags = []string{
|
|
|
|
"-isysroot ${macSdkRoot}",
|
|
|
|
"-Wl,-syslibroot,${macSdkRoot}",
|
2016-10-27 04:20:58 +02:00
|
|
|
"-mmacosx-version-min=${macMinVersion}",
|
2015-05-01 01:36:18 +02:00
|
|
|
"-m64",
|
2021-07-23 09:34:34 +02:00
|
|
|
"-mlinker-version=305",
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
2015-12-15 05:02:44 +01:00
|
|
|
darwinSupportedSdkVersions = []string{
|
2021-10-20 06:37:15 +02:00
|
|
|
"11",
|
2021-12-08 05:19:58 +01:00
|
|
|
"12",
|
2015-12-15 05:02:44 +01:00
|
|
|
}
|
2016-05-25 23:47:21 +02:00
|
|
|
|
2016-09-29 23:22:54 +02:00
|
|
|
darwinAvailableLibraries = append(
|
|
|
|
addPrefix([]string{
|
|
|
|
"c",
|
|
|
|
"dl",
|
|
|
|
"m",
|
|
|
|
"ncurses",
|
|
|
|
"objc",
|
|
|
|
"pthread",
|
|
|
|
}, "-l"),
|
2016-11-22 02:31:08 +01:00
|
|
|
"-framework AppKit",
|
2016-09-29 23:22:54 +02:00
|
|
|
"-framework CoreFoundation",
|
2016-11-22 02:31:08 +01:00
|
|
|
"-framework Foundation",
|
2016-09-29 23:22:54 +02:00
|
|
|
"-framework IOKit",
|
2016-11-22 02:31:08 +01:00
|
|
|
"-framework Security",
|
2019-02-20 19:28:56 +01:00
|
|
|
"-framework SystemConfiguration",
|
2016-09-29 23:22:54 +02:00
|
|
|
)
|
2015-05-01 01:36:18 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2018-03-12 21:24:09 +01:00
|
|
|
pctx.VariableFunc("macSdkRoot", func(ctx android.PackageVarContext) string {
|
2020-04-01 23:32:52 +02:00
|
|
|
return getMacTools(ctx).sdkRoot
|
2015-12-15 05:02:44 +01:00
|
|
|
})
|
2023-11-08 02:10:51 +01:00
|
|
|
pctx.StaticVariable("macMinVersion", "10.14")
|
2018-03-12 21:24:09 +01:00
|
|
|
pctx.VariableFunc("MacArPath", func(ctx android.PackageVarContext) string {
|
2020-04-01 23:32:52 +02:00
|
|
|
return getMacTools(ctx).arPath
|
2015-12-15 05:02:44 +01:00
|
|
|
})
|
2015-05-01 01:36:18 +02:00
|
|
|
|
2021-10-20 05:24:49 +02:00
|
|
|
pctx.VariableFunc("MacLipoPath", func(ctx android.PackageVarContext) string {
|
|
|
|
return getMacTools(ctx).lipoPath
|
|
|
|
})
|
|
|
|
|
2018-03-12 21:24:09 +01:00
|
|
|
pctx.VariableFunc("MacStripPath", func(ctx android.PackageVarContext) string {
|
2020-04-01 23:32:52 +02:00
|
|
|
return getMacTools(ctx).stripPath
|
2016-05-04 00:10:29 +02:00
|
|
|
})
|
|
|
|
|
2018-03-12 21:24:09 +01:00
|
|
|
pctx.VariableFunc("MacToolPath", func(ctx android.PackageVarContext) string {
|
2020-04-01 23:32:52 +02:00
|
|
|
return getMacTools(ctx).toolPath
|
2017-03-13 20:40:30 +01:00
|
|
|
})
|
|
|
|
|
2021-07-15 03:45:05 +02:00
|
|
|
pctx.StaticVariable("DarwinCflags", strings.Join(darwinCflags, " "))
|
|
|
|
pctx.StaticVariable("DarwinLdflags", strings.Join(darwinLdflags, " "))
|
|
|
|
pctx.StaticVariable("DarwinLldflags", strings.Join(darwinLdflags, " "))
|
2016-03-09 19:30:22 +01:00
|
|
|
|
2018-08-29 02:12:56 +02:00
|
|
|
pctx.StaticVariable("DarwinYasmFlags", "-f macho -m amd64")
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
2021-07-14 06:52:04 +02:00
|
|
|
func MacStripPath(ctx android.PathContext) string {
|
|
|
|
return getMacTools(ctx).stripPath
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:32:52 +02:00
|
|
|
type macPlatformTools struct {
|
|
|
|
once sync.Once
|
|
|
|
err error
|
|
|
|
|
|
|
|
sdkRoot string
|
|
|
|
arPath string
|
2021-10-20 05:24:49 +02:00
|
|
|
lipoPath string
|
2020-04-01 23:32:52 +02:00
|
|
|
stripPath string
|
|
|
|
toolPath string
|
2017-05-08 23:15:59 +02:00
|
|
|
}
|
|
|
|
|
2020-04-01 23:32:52 +02:00
|
|
|
var macTools = &macPlatformTools{}
|
2015-12-15 05:02:44 +01:00
|
|
|
|
2021-07-14 06:52:04 +02:00
|
|
|
func getMacTools(ctx android.PathContext) *macPlatformTools {
|
2020-04-01 23:32:52 +02:00
|
|
|
macTools.once.Do(func() {
|
2021-03-11 08:52:39 +01:00
|
|
|
xcrunTool := "/usr/bin/xcrun"
|
2020-04-01 23:32:52 +02:00
|
|
|
|
|
|
|
xcrun := func(args ...string) string {
|
|
|
|
if macTools.err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2021-10-20 06:37:15 +02:00
|
|
|
bytes, err := exec.Command(xcrunTool, append([]string{"--sdk", "macosx"}, args...)...).Output()
|
2020-04-01 23:32:52 +02:00
|
|
|
if err != nil {
|
|
|
|
macTools.err = fmt.Errorf("xcrun %q failed with: %q", args, err)
|
|
|
|
return ""
|
|
|
|
}
|
2015-12-15 05:02:44 +01:00
|
|
|
|
2018-03-12 21:24:09 +01:00
|
|
|
return strings.TrimSpace(string(bytes))
|
2015-12-15 05:02:44 +01:00
|
|
|
}
|
2020-04-01 23:32:52 +02:00
|
|
|
|
2021-10-20 06:37:15 +02:00
|
|
|
sdkVersion := xcrun("--show-sdk-version")
|
|
|
|
sdkVersionSupported := false
|
|
|
|
for _, version := range darwinSupportedSdkVersions {
|
|
|
|
if version == sdkVersion || strings.HasPrefix(sdkVersion, version+".") {
|
|
|
|
sdkVersionSupported = true
|
2020-04-01 23:32:52 +02:00
|
|
|
}
|
2021-10-20 06:37:15 +02:00
|
|
|
}
|
|
|
|
if !sdkVersionSupported {
|
|
|
|
macTools.err = fmt.Errorf("Unsupported macOS SDK version %q not in %v", sdkVersion, darwinSupportedSdkVersions)
|
|
|
|
return
|
2020-04-01 23:32:52 +02:00
|
|
|
}
|
|
|
|
|
2021-10-20 06:37:15 +02:00
|
|
|
macTools.sdkRoot = xcrun("--show-sdk-path")
|
2020-04-01 23:32:52 +02:00
|
|
|
|
|
|
|
macTools.arPath = xcrun("--find", "ar")
|
2021-10-20 05:24:49 +02:00
|
|
|
macTools.lipoPath = xcrun("--find", "lipo")
|
2020-04-01 23:32:52 +02:00
|
|
|
macTools.stripPath = xcrun("--find", "strip")
|
|
|
|
macTools.toolPath = filepath.Dir(xcrun("--find", "ld"))
|
|
|
|
})
|
|
|
|
if macTools.err != nil {
|
2021-07-14 06:52:04 +02:00
|
|
|
android.ReportPathErrorf(ctx, "%q", macTools.err)
|
2015-12-15 05:02:44 +01:00
|
|
|
}
|
2020-04-01 23:32:52 +02:00
|
|
|
return macTools
|
2015-12-15 05:02:44 +01:00
|
|
|
}
|
|
|
|
|
2015-05-01 01:36:18 +02:00
|
|
|
type toolchainDarwin struct {
|
|
|
|
cFlags, ldFlags string
|
|
|
|
toolchain64Bit
|
2022-09-01 20:02:15 +02:00
|
|
|
toolchainNoCrt
|
|
|
|
toolchainBase
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
2021-10-19 09:22:06 +02:00
|
|
|
type toolchainDarwinX86 struct {
|
|
|
|
toolchainDarwin
|
|
|
|
}
|
|
|
|
|
|
|
|
type toolchainDarwinArm struct {
|
|
|
|
toolchainDarwin
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinArm) Name() string {
|
|
|
|
return "arm64"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX86) Name() string {
|
2015-05-01 01:36:18 +02:00
|
|
|
return "x86_64"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) IncludeFlags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2021-10-19 09:22:06 +02:00
|
|
|
func (t *toolchainDarwinArm) ClangTriple() string {
|
|
|
|
return "aarch64-apple-darwin"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX86) ClangTriple() string {
|
2016-03-30 09:01:12 +02:00
|
|
|
return "x86_64-apple-darwin"
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainDarwin) Cflags() string {
|
2021-07-15 03:45:05 +02:00
|
|
|
return "${config.DarwinCflags}"
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainDarwin) Cppflags() string {
|
2016-03-09 19:30:22 +01:00
|
|
|
return ""
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainDarwin) Ldflags() string {
|
2021-07-15 03:45:05 +02:00
|
|
|
return "${config.DarwinLdflags}"
|
2018-04-03 20:33:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainDarwin) Lldflags() string {
|
2021-07-15 03:45:05 +02:00
|
|
|
return "${config.DarwinLldflags}"
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
2018-08-29 02:12:56 +02:00
|
|
|
func (t *toolchainDarwin) YasmFlags() string {
|
|
|
|
return "${config.DarwinYasmFlags}"
|
2017-10-05 02:31:43 +02:00
|
|
|
}
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
func (t *toolchainDarwin) ShlibSuffix() string {
|
|
|
|
return ".dylib"
|
|
|
|
}
|
|
|
|
|
2022-09-01 20:02:15 +02:00
|
|
|
func (t *toolchainDarwin) ExecutableSuffix() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:47:21 +02:00
|
|
|
func (t *toolchainDarwin) AvailableLibraries() []string {
|
|
|
|
return darwinAvailableLibraries
|
|
|
|
}
|
|
|
|
|
2022-02-16 07:48:04 +01:00
|
|
|
func (t *toolchainDarwin) ToolchainCflags() string {
|
|
|
|
return "-B${config.MacToolPath}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) ToolchainLdflags() string {
|
|
|
|
return "-B${config.MacToolPath}"
|
2017-03-13 20:40:30 +01:00
|
|
|
}
|
|
|
|
|
2021-10-19 09:22:06 +02:00
|
|
|
var toolchainDarwinArmSingleton Toolchain = &toolchainDarwinArm{}
|
|
|
|
var toolchainDarwinX86Singleton Toolchain = &toolchainDarwinX86{}
|
|
|
|
|
|
|
|
func darwinArmToolchainFactory(arch android.Arch) Toolchain {
|
|
|
|
return toolchainDarwinArmSingleton
|
|
|
|
}
|
2015-05-01 01:36:18 +02:00
|
|
|
|
2021-10-19 09:22:06 +02:00
|
|
|
func darwinX86ToolchainFactory(arch android.Arch) Toolchain {
|
|
|
|
return toolchainDarwinX86Singleton
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2021-10-19 09:22:06 +02:00
|
|
|
registerToolchainFactory(android.Darwin, android.Arm64, darwinArmToolchainFactory)
|
|
|
|
registerToolchainFactory(android.Darwin, android.X86_64, darwinX86ToolchainFactory)
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|