aboutsummaryrefslogtreecommitdiffstats
path: root/cc/ndk_sysroot.go
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2016-06-17 16:45:24 -0700
committerDan Albert <danalbert@google.com>2016-07-28 00:42:05 -0700
commit914449fca8c749588e28dfdfafc3226aa407c47e (patch)
tree1f70761b0869ff651676ced2293b530dd7f3e3e6 /cc/ndk_sysroot.go
parentfb8f9a800ed42e548893b13ebc3840fc31aaae94 (diff)
downloadbuild_soong-914449fca8c749588e28dfdfafc3226aa407c47e.tar.gz
build_soong-914449fca8c749588e28dfdfafc3226aa407c47e.tar.bz2
build_soong-914449fca8c749588e28dfdfafc3226aa407c47e.zip
Generate NDK sysroots from the platform build.
The list of migrated libraries is currently empty. Libraries will be migrated as follow up patches. Test: Migrated libc to this system and everything still builds. build.ninja shows libraries being built and used and headers are collected for the sysroot. Bug: http://b/27533932 Change-Id: Iaba00543c1390f432befe0eed768ed3fbb8a9b96
Diffstat (limited to 'cc/ndk_sysroot.go')
-rw-r--r--cc/ndk_sysroot.go112
1 files changed, 112 insertions, 0 deletions
diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go
new file mode 100644
index 00000000..2eae360c
--- /dev/null
+++ b/cc/ndk_sysroot.go
@@ -0,0 +1,112 @@
+// 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 cc
+
+// The platform needs to provide the following artifacts for the NDK:
+// 1. Bionic headers.
+// 2. Platform API headers.
+// 3. NDK stub shared libraries.
+// 4. Bionic static libraries.
+//
+// TODO(danalbert): All of the above need to include NOTICE files.
+//
+// Components 1 and 2: Headers
+// The bionic and platform API headers are generalized into a single
+// `ndk_headers` rule. This rule has a `from` property that indicates a base
+// directory from which headers are to be taken, and a `to` property that
+// indicates where in the sysroot they should reside relative to usr/include.
+// There is also a `srcs` property that is glob compatible for specifying which
+// headers to include.
+//
+// Component 3: Stub Libraries
+// The shared libraries in the NDK are not the actual shared libraries they
+// refer to (to prevent people from accidentally loading them), but stub
+// libraries with dummy implementations of everything for use at build time
+// only.
+//
+// Since we don't actually need to know anything about the stub libraries aside
+// from a list of functions and globals to be exposed, we can create these for
+// every platform level in the current tree. This is handled by the
+// ndk_library rule.
+//
+// Component 4: Static Libraries
+// The NDK only provides static libraries for bionic, not the platform APIs.
+// Since these need to be the actual implementation, we can't build old versions
+// in the current platform tree. As such, legacy versions are checked in
+// prebuilt to development/ndk, and a current version is built and archived as
+// part of the platform build. The platfrom already builds these libraries, our
+// NDK build rules only need to archive them for retrieval so they can be added
+// to the prebuilts.
+//
+// TODO(danalbert): Write `ndk_static_library` rule.
+
+import (
+ "github.com/google/blueprint"
+
+ "android/soong"
+ "android/soong/android"
+)
+
+func init() {
+ soong.RegisterModuleType("ndk_headers", ndkHeadersFactory)
+ soong.RegisterModuleType("ndk_library", ndkLibraryFactory)
+ soong.RegisterSingletonType("ndk", NdkSingleton)
+
+ pctx.Import("android/soong/common")
+}
+
+func getNdkInstallBase(ctx android.ModuleContext) android.OutputPath {
+ return android.PathForOutput(ctx, "ndk")
+}
+
+// Returns the main install directory for the NDK sysroot. Usable with --sysroot.
+func getNdkSysrootBase(ctx android.ModuleContext) android.OutputPath {
+ return getNdkInstallBase(ctx).Join(ctx, "sysroot")
+}
+
+func getNdkSysrootTimestampFile(ctx android.PathContext) android.Path {
+ return android.PathForOutput(ctx, "ndk.timestamp")
+}
+
+func NdkSingleton() blueprint.Singleton {
+ return &ndkSingleton{}
+}
+
+type ndkSingleton struct{}
+
+func (n *ndkSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
+ installPaths := []string{}
+ ctx.VisitAllModules(func(module blueprint.Module) {
+ if m, ok := module.(*headerModule); ok {
+ installPaths = append(installPaths, m.installPaths...)
+ }
+ })
+
+ ctx.VisitAllModules(func(module blueprint.Module) {
+ if m, ok := module.(*Module); ok {
+ if installer, ok := m.installer.(*stubInstaller); ok {
+ installPaths = append(installPaths, installer.installPath)
+ }
+ }
+ })
+
+ // There's a dummy "ndk" rule defined in ndk/Android.mk that depends on
+ // this. `m ndk` will build the sysroots.
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: android.Touch,
+ Outputs: []string{getNdkSysrootTimestampFile(ctx).String()},
+ Implicits: installPaths,
+ })
+}