• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2016 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 clang
16
17import (
18	"android/soong/android"
19	"android/soong/cc"
20
21	"github.com/google/blueprint/proptools"
22)
23
24// Clang binaries (clang, clang-check, clang-format) need to be compiled for both 32-bit and 64-bit,
25// but only when FORCE_BUILD_LLVM_COMPONENTS is set
26
27func init() {
28	android.RegisterModuleType("clang_binary_host", clangBinaryHostFactory)
29}
30
31func clangForceBuildLlvmComponents(ctx android.LoadHookContext) {
32	type props struct {
33		Target struct {
34			Host struct {
35				Compile_multilib *string
36			}
37		}
38		Multilib struct {
39			Lib32 struct {
40				Suffix *string
41			}
42		}
43	}
44	p := &props{}
45
46	if ctx.AConfig().IsEnvTrue("FORCE_BUILD_LLVM_COMPONENTS") {
47		p.Target.Host.Compile_multilib = proptools.StringPtr("both")
48		p.Multilib.Lib32.Suffix = proptools.StringPtr("_32")
49	}
50
51	ctx.AppendProperties(p)
52}
53
54func clangBinaryHostFactory() android.Module {
55	module, _ := cc.NewBinary(android.HostSupported)
56	android.AddLoadHook(module, clangForceBuildLlvmComponents)
57
58	return module.Init()
59}
60