Support .rs and .fs files in cc_* module srcs lists
Translate .rs and .fs files to .cpp files using llvm-rs-cc. Test: builds Change-Id: I242cea0d09c9985730a512cec7705c3f1479f4ed
This commit is contained in:
parent
7e0eaf15b9
commit
2a252bef50
|
@ -127,6 +127,7 @@ bootstrap_go_package {
|
|||
"cc/prebuilt.go",
|
||||
"cc/proto.go",
|
||||
"cc/relocation_packer.go",
|
||||
"cc/rs.go",
|
||||
"cc/sanitize.go",
|
||||
"cc/sabi.go",
|
||||
"cc/stl.go",
|
||||
|
|
|
@ -56,20 +56,21 @@ func addStandardProperties(propertyType bpparser.Type, properties map[string]str
|
|||
func init() {
|
||||
addStandardProperties(bpparser.StringType,
|
||||
map[string]string{
|
||||
"LOCAL_MODULE": "name",
|
||||
"LOCAL_CXX_STL": "stl",
|
||||
"LOCAL_STRIP_MODULE": "strip",
|
||||
"LOCAL_MULTILIB": "compile_multilib",
|
||||
"LOCAL_ARM_MODE_HACK": "instruction_set",
|
||||
"LOCAL_SDK_VERSION": "sdk_version",
|
||||
"LOCAL_NDK_STL_VARIANT": "stl",
|
||||
"LOCAL_JAR_MANIFEST": "manifest",
|
||||
"LOCAL_JARJAR_RULES": "jarjar_rules",
|
||||
"LOCAL_CERTIFICATE": "certificate",
|
||||
"LOCAL_PACKAGE_NAME": "name",
|
||||
"LOCAL_MODULE_RELATIVE_PATH": "relative_install_path",
|
||||
"LOCAL_PROTOC_OPTIMIZE_TYPE": "proto.type",
|
||||
"LOCAL_MODULE_OWNER": "owner",
|
||||
"LOCAL_MODULE": "name",
|
||||
"LOCAL_CXX_STL": "stl",
|
||||
"LOCAL_STRIP_MODULE": "strip",
|
||||
"LOCAL_MULTILIB": "compile_multilib",
|
||||
"LOCAL_ARM_MODE_HACK": "instruction_set",
|
||||
"LOCAL_SDK_VERSION": "sdk_version",
|
||||
"LOCAL_NDK_STL_VARIANT": "stl",
|
||||
"LOCAL_JAR_MANIFEST": "manifest",
|
||||
"LOCAL_JARJAR_RULES": "jarjar_rules",
|
||||
"LOCAL_CERTIFICATE": "certificate",
|
||||
"LOCAL_PACKAGE_NAME": "name",
|
||||
"LOCAL_MODULE_RELATIVE_PATH": "relative_install_path",
|
||||
"LOCAL_PROTOC_OPTIMIZE_TYPE": "proto.type",
|
||||
"LOCAL_MODULE_OWNER": "owner",
|
||||
"LOCAL_RENDERSCRIPT_TARGET_API": "renderscript.target_api",
|
||||
})
|
||||
addStandardProperties(bpparser.ListType,
|
||||
map[string]string{
|
||||
|
@ -96,7 +97,9 @@ func init() {
|
|||
"LOCAL_INIT_RC": "init_rc",
|
||||
"LOCAL_TIDY_FLAGS": "tidy_flags",
|
||||
// TODO: This is comma-separated, not space-separated
|
||||
"LOCAL_TIDY_CHECKS": "tidy_checks",
|
||||
"LOCAL_TIDY_CHECKS": "tidy_checks",
|
||||
"LOCAL_RENDERSCRIPT_INCLUDES": "renderscript.include_dirs",
|
||||
"LOCAL_RENDERSCRIPT_FLAGS": "renderscript.flags",
|
||||
|
||||
"LOCAL_JAVA_RESOURCE_DIRS": "java_resource_dirs",
|
||||
"LOCAL_JAVACFLAGS": "javacflags",
|
||||
|
|
|
@ -229,6 +229,7 @@ type builderFlags struct {
|
|||
sAbiFlags string
|
||||
yasmFlags string
|
||||
aidlFlags string
|
||||
rsFlags string
|
||||
toolchain config.Toolchain
|
||||
clang bool
|
||||
tidy bool
|
||||
|
|
1
cc/cc.go
1
cc/cc.go
|
@ -106,6 +106,7 @@ type Flags struct {
|
|||
YaccFlags []string // Flags that apply to Yacc source files
|
||||
protoFlags []string // Flags that apply to proto source files
|
||||
aidlFlags []string // Flags that apply to aidl source files
|
||||
rsFlags []string // Flags that apply to renderscript source files
|
||||
LdFlags []string // Flags that apply to linker command lines
|
||||
libFlags []string // Flags to add libraries early to the link order
|
||||
TidyFlags []string // Flags that apply to clang-tidy
|
||||
|
|
|
@ -108,6 +108,17 @@ type BaseCompilerProperties struct {
|
|||
Local_include_dirs []string
|
||||
}
|
||||
|
||||
Renderscript struct {
|
||||
// list of directories that will be added to the llvm-rs-cc include paths
|
||||
Include_dirs []string
|
||||
|
||||
// list of flags that will be passed to llvm-rs-cc
|
||||
Flags []string
|
||||
|
||||
// Renderscript API level to target
|
||||
Target_api *string
|
||||
}
|
||||
|
||||
Debug, Release struct {
|
||||
// list of module-specific flags that will be used for C and C++ compiles in debug or
|
||||
// release builds
|
||||
|
@ -420,6 +431,10 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag
|
|||
"-I"+android.PathForModuleGen(ctx, "aidl").String())
|
||||
}
|
||||
|
||||
if compiler.hasSrcExt(".rs") || compiler.hasSrcExt(".fs") {
|
||||
flags = rsFlags(ctx, flags, &compiler.Properties)
|
||||
}
|
||||
|
||||
return flags
|
||||
}
|
||||
|
||||
|
|
|
@ -151,6 +151,12 @@ func init() {
|
|||
pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
|
||||
pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
|
||||
|
||||
pctx.PrefixedPathsForOptionalSourceVariable("RsGlobalIncludes", "-I",
|
||||
[]string{
|
||||
"external/clang/lib/Headers",
|
||||
"frameworks/rs/script_api/include",
|
||||
})
|
||||
|
||||
pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
|
||||
if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
|
||||
return override + " ", nil
|
||||
|
|
10
cc/gen.go
10
cc/gen.go
|
@ -105,6 +105,8 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths,
|
|||
|
||||
var deps android.Paths
|
||||
|
||||
var rsFiles android.Paths
|
||||
|
||||
for i, srcFile := range srcFiles {
|
||||
switch srcFile.Ext() {
|
||||
case ".y":
|
||||
|
@ -131,8 +133,16 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths,
|
|||
cppFile := android.GenPathWithExt(ctx, "aidl", srcFile, "cpp")
|
||||
srcFiles[i] = cppFile
|
||||
deps = append(deps, genAidl(ctx, srcFile, cppFile, buildFlags.aidlFlags)...)
|
||||
case ".rs", ".fs":
|
||||
cppFile := rsGeneratedCppFile(ctx, srcFile)
|
||||
rsFiles = append(rsFiles, srcFiles[i])
|
||||
srcFiles[i] = cppFile
|
||||
}
|
||||
}
|
||||
|
||||
if len(rsFiles) > 0 {
|
||||
deps = append(deps, rsGenerateCpp(ctx, rsFiles, buildFlags.rsFlags)...)
|
||||
}
|
||||
|
||||
return srcFiles, deps
|
||||
}
|
||||
|
|
|
@ -77,6 +77,8 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
|
|||
|
||||
ctx.Strict("AIDL_CPP", "${aidlCmd}")
|
||||
|
||||
ctx.Strict("RS_GLOBAL_INCLUDES", "${config.RsGlobalIncludes}")
|
||||
|
||||
includeFlags, err := ctx.Eval("${config.CommonGlobalIncludes}")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
// Copyright 2017 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
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"strings"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
)
|
||||
|
||||
func init() {
|
||||
pctx.HostBinToolVariable("rsCmd", "llvm-rs-cc")
|
||||
}
|
||||
|
||||
var rsCppCmdLine = strings.Replace(`
|
||||
${rsCmd} -o ${outDir} -d ${outDir} -a ${out} -MD -reflect-c++ ${rsFlags} $in &&
|
||||
(echo '${out}: \' && cat ${depFiles} | awk 'start { sub(/( \\)?$$/, " \\"); print } /:/ { start=1 }') > ${out}.d &&
|
||||
touch $out
|
||||
`, "\n", "", -1)
|
||||
|
||||
var (
|
||||
rsCpp = pctx.AndroidStaticRule("rsCpp",
|
||||
blueprint.RuleParams{
|
||||
Command: rsCppCmdLine,
|
||||
CommandDeps: []string{"$rsCmd"},
|
||||
Depfile: "${out}.d",
|
||||
Deps: blueprint.DepsGCC,
|
||||
Description: "rsCpp $out",
|
||||
},
|
||||
"depFiles", "outDir", "rsFlags", "stampFile")
|
||||
)
|
||||
|
||||
// Takes a path to a .rs or .fs file, and returns a path to a generated ScriptC_*.cpp file
|
||||
// This has to match the logic in llvm-rs-cc in DetermineOutputFile.
|
||||
func rsGeneratedCppFile(ctx android.ModuleContext, rsFile android.Path) android.WritablePath {
|
||||
fileName := strings.TrimSuffix(rsFile.Base(), rsFile.Ext())
|
||||
return android.PathForModuleGen(ctx, "rs", "ScriptC_"+fileName+".cpp")
|
||||
}
|
||||
|
||||
func rsGeneratedDepFile(ctx android.ModuleContext, rsFile android.Path) android.WritablePath {
|
||||
fileName := strings.TrimSuffix(rsFile.Base(), rsFile.Ext())
|
||||
return android.PathForModuleGen(ctx, "rs", fileName+".d")
|
||||
}
|
||||
|
||||
func rsGenerateCpp(ctx android.ModuleContext, rsFiles android.Paths, rsFlags string) android.Paths {
|
||||
stampFile := android.PathForModuleGen(ctx, "rs", "rs.stamp")
|
||||
depFiles := make(android.WritablePaths, len(rsFiles))
|
||||
cppFiles := make(android.WritablePaths, len(rsFiles))
|
||||
for i, rsFile := range rsFiles {
|
||||
depFiles[i] = rsGeneratedDepFile(ctx, rsFile)
|
||||
cppFiles[i] = rsGeneratedCppFile(ctx, rsFile)
|
||||
}
|
||||
|
||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||
Rule: rsCpp,
|
||||
Output: stampFile,
|
||||
ImplicitOutputs: cppFiles,
|
||||
Inputs: rsFiles,
|
||||
Args: map[string]string{
|
||||
"rsFlags": rsFlags,
|
||||
"outDir": android.PathForModuleGen(ctx, "rs").String(),
|
||||
"depFiles": strings.Join(depFiles.Strings(), " "),
|
||||
},
|
||||
})
|
||||
|
||||
return android.Paths{stampFile}
|
||||
}
|
||||
|
||||
func rsFlags(ctx ModuleContext, flags Flags, properties *BaseCompilerProperties) Flags {
|
||||
targetApi := proptools.String(properties.Renderscript.Target_api)
|
||||
if targetApi == "" && ctx.sdk() {
|
||||
switch ctx.sdkVersion() {
|
||||
case "current", "system_current", "test_current":
|
||||
// Nothing
|
||||
default:
|
||||
targetApi = ctx.sdkVersion()
|
||||
}
|
||||
}
|
||||
|
||||
if targetApi != "" {
|
||||
flags.rsFlags = append(flags.rsFlags, "-target-api "+targetApi)
|
||||
}
|
||||
|
||||
flags.rsFlags = append(flags.rsFlags, "-Wall", "-Werror")
|
||||
flags.rsFlags = append(flags.rsFlags, properties.Renderscript.Flags...)
|
||||
if ctx.Arch().ArchType.Multilib == "lib64" {
|
||||
flags.rsFlags = append(flags.rsFlags, "-m64")
|
||||
} else {
|
||||
flags.rsFlags = append(flags.rsFlags, "-m32")
|
||||
}
|
||||
flags.rsFlags = append(flags.rsFlags, "${config.RsGlobalIncludes}")
|
||||
|
||||
rootRsIncludeDirs := android.PathsForSource(ctx, properties.Renderscript.Include_dirs)
|
||||
flags.rsFlags = append(flags.rsFlags, includeDirsToFlags(rootRsIncludeDirs))
|
||||
|
||||
flags.GlobalFlags = append(flags.GlobalFlags,
|
||||
"-I"+android.PathForModuleGen(ctx, "rs").String())
|
||||
|
||||
return flags
|
||||
}
|
|
@ -96,6 +96,7 @@ func flagsToBuilderFlags(in Flags) builderFlags {
|
|||
yaccFlags: strings.Join(in.YaccFlags, " "),
|
||||
protoFlags: strings.Join(in.protoFlags, " "),
|
||||
aidlFlags: strings.Join(in.aidlFlags, " "),
|
||||
rsFlags: strings.Join(in.rsFlags, " "),
|
||||
ldFlags: strings.Join(in.LdFlags, " "),
|
||||
libFlags: strings.Join(in.libFlags, " "),
|
||||
tidyFlags: strings.Join(in.TidyFlags, " "),
|
||||
|
|
Loading…
Reference in New Issue