2017-05-02 08:37:24 +08:00
|
|
|
// 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"
|
2018-11-19 12:57:21 +08:00
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
2017-05-02 08:37:24 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2018-11-19 12:57:21 +08:00
|
|
|
pctx.VariableFunc("rsCmd", func(ctx android.PackageVarContext) string {
|
|
|
|
if ctx.Config().UnbundledBuild() {
|
|
|
|
// Use RenderScript prebuilts for unbundled builds but not PDK builds
|
|
|
|
return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "bin/llvm-rs-cc")
|
|
|
|
} else {
|
2019-12-10 05:47:14 +08:00
|
|
|
return ctx.Config().HostToolPath(ctx, "llvm-rs-cc").String()
|
2018-11-19 12:57:21 +08:00
|
|
|
}
|
|
|
|
})
|
2017-05-02 08:37:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
"depFiles", "outDir", "rsFlags", "stampFile")
|
|
|
|
)
|
|
|
|
|
2019-07-16 10:08:37 +08:00
|
|
|
// Takes a path to a .rscript or .fs file, and returns a path to a generated ScriptC_*.cpp file
|
2017-05-02 08:37:24 +08:00
|
|
|
// 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")
|
|
|
|
}
|
|
|
|
|
2018-03-20 13:44:29 +08:00
|
|
|
func rsGeneratedHFile(ctx android.ModuleContext, rsFile android.Path) android.WritablePath {
|
|
|
|
fileName := strings.TrimSuffix(rsFile.Base(), rsFile.Ext())
|
|
|
|
return android.PathForModuleGen(ctx, "rs", "ScriptC_"+fileName+".h")
|
|
|
|
}
|
|
|
|
|
2017-05-02 08:37:24 +08:00
|
|
|
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")
|
2018-03-20 13:44:29 +08:00
|
|
|
depFiles := make(android.WritablePaths, 0, len(rsFiles))
|
|
|
|
genFiles := make(android.WritablePaths, 0, 2*len(rsFiles))
|
2019-06-13 12:55:09 +08:00
|
|
|
headers := make(android.Paths, 0, len(rsFiles))
|
2018-03-20 13:44:29 +08:00
|
|
|
for _, rsFile := range rsFiles {
|
|
|
|
depFiles = append(depFiles, rsGeneratedDepFile(ctx, rsFile))
|
2019-06-13 12:55:09 +08:00
|
|
|
headerFile := rsGeneratedHFile(ctx, rsFile)
|
|
|
|
genFiles = append(genFiles, rsGeneratedCppFile(ctx, rsFile), headerFile)
|
|
|
|
headers = append(headers, headerFile)
|
2017-05-02 08:37:24 +08:00
|
|
|
}
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-02 08:37:24 +08:00
|
|
|
Rule: rsCpp,
|
2017-05-10 04:45:28 +08:00
|
|
|
Description: "llvm-rs-cc",
|
2017-05-02 08:37:24 +08:00
|
|
|
Output: stampFile,
|
2018-03-20 13:44:29 +08:00
|
|
|
ImplicitOutputs: genFiles,
|
2017-05-02 08:37:24 +08:00
|
|
|
Inputs: rsFiles,
|
|
|
|
Args: map[string]string{
|
|
|
|
"rsFlags": rsFlags,
|
|
|
|
"outDir": android.PathForModuleGen(ctx, "rs").String(),
|
|
|
|
"depFiles": strings.Join(depFiles.Strings(), " "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2019-06-13 12:55:09 +08:00
|
|
|
return headers
|
2017-05-02 08:37:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func rsFlags(ctx ModuleContext, flags Flags, properties *BaseCompilerProperties) Flags {
|
2017-11-08 02:57:05 +08:00
|
|
|
targetApi := String(properties.Renderscript.Target_api)
|
2017-09-28 08:01:44 +08:00
|
|
|
if targetApi == "" && ctx.useSdk() {
|
2017-05-02 08:37:24 +08:00
|
|
|
switch ctx.sdkVersion() {
|
|
|
|
case "current", "system_current", "test_current":
|
|
|
|
// Nothing
|
|
|
|
default:
|
2017-10-17 15:34:51 +08:00
|
|
|
targetApi = android.GetNumericSdkVersion(ctx.sdkVersion())
|
2017-05-02 08:37:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CommonFlags = append(flags.Local.CommonFlags,
|
2017-05-09 00:16:34 +08:00
|
|
|
"-I"+android.PathForModuleGen(ctx, "rs").String(),
|
|
|
|
"-Iframeworks/rs",
|
|
|
|
"-Iframeworks/rs/cpp",
|
|
|
|
)
|
2017-05-02 08:37:24 +08:00
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|