8#include "flutter/fml/backtrace.h"
9#include "flutter/fml/command_line.h"
10#include "flutter/fml/file.h"
11#include "flutter/fml/mapping.h"
32 return reflector_options;
38 std::shared_ptr<fml::Mapping> source_file_mapping,
47 Compiler(std::move(source_file_mapping),
options, sksl_reflector_options);
49 std::cerr <<
"Compilation to SkSL failed." << std::endl;
58 const std::shared_ptr<fml::Mapping>& source_file_mapping) {
62 std::shared_ptr<RuntimeStageData::Shader> sksl_shader;
64 sksl_shader =
CompileSkSL(source_file_mapping, switches);
84 std::cerr <<
"Compilation failed." << std::endl;
85 std::cerr <<
compiler.GetErrorMessages() << std::endl;
89 auto reflector =
compiler.GetReflector();
90 if (reflector ==
nullptr) {
91 std::cerr <<
"Could not create reflector." << std::endl;
95 auto stage_data = reflector->GetRuntimeStageShaderData();
97 std::cerr <<
"Runtime stage information was nil." << std::endl;
106 if (!stage_data_mapping) {
107 std::cerr <<
"Runtime stage data could not be created." << std::endl;
114 std::cerr <<
"Could not write file to " << switches.
sl_file_name
132 auto sl_file_name = std::filesystem::absolute(
133 std::filesystem::current_path() / switches.
sl_file_name);
137 std::cerr <<
"Could not write file to " << switches.
sl_file_name
154 auto reflection_json_name = std::filesystem::absolute(
159 *
compiler.GetReflector()->GetReflectionJSON())) {
160 std::cerr <<
"Could not write reflection json to "
167 auto reflection_header_name =
168 std::filesystem::absolute(std::filesystem::current_path() /
173 *
compiler.GetReflector()->GetReflectionHeader())) {
174 std::cerr <<
"Could not write reflection header to "
181 auto reflection_cc_name =
182 std::filesystem::absolute(std::filesystem::current_path() /
186 *
compiler.GetReflector()->GetReflectionCC())) {
187 std::cerr <<
"Could not write reflection CC to "
202 std::string result_file;
219 auto depfile_path = std::filesystem::absolute(
220 std::filesystem::current_path() / switches.
depfile_path.c_str());
223 *
compiler.CreateDepfileContents({result_file}))) {
224 std::cerr <<
"Could not write depfile to " << switches.
depfile_path
241 if (!switches.
AreValid(std::cerr)) {
242 std::cerr <<
"Invalid flags specified." << std::endl;
253 std::shared_ptr<fml::FileMapping> source_file_mapping =
255 if (!source_file_mapping) {
256 std::cerr <<
"Could not open input file." << std::endl;
260 if (switches.
iplr && !
OutputIPLR(switches, source_file_mapping)) {
279 std::cerr <<
"Compilation failed." << std::endl;
280 std::cerr <<
compiler.GetErrorMessages() << std::endl;
284 auto spriv_file_name = std::filesystem::absolute(
312int main(
int argc,
char const* argv[]) {
bool HasOption(std::string_view name, size_t *index=nullptr) const
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
const Reflector * GetReflector() const
std::string GetErrorMessages() const
std::shared_ptr< RuntimeStageData::Shader > GetRuntimeStageShaderData() const
std::shared_ptr< fml::Mapping > CreateMapping() const
void AddShader(const std::shared_ptr< Shader > &data)
std::shared_ptr< fml::Mapping > CreateJsonMapping() const
std::vector< TargetPlatform > PlatformsToCompile() const
A vector containing at least one valid platform.
std::string reflection_json_name
std::string reflection_header_name
std::string shader_bundle
std::shared_ptr< fml::UniqueFD > working_directory
SourceOptions CreateSourceOptions(std::optional< TargetPlatform > target_platform=std::nullopt) const
std::string reflection_cc_name
std::string spirv_file_name
bool AreValid(std::ostream &explain) const
static void PrintHelp(std::ostream &stream)
std::string source_file_name
TargetPlatform SelectDefaultTargetPlatform() const
#define FML_DCHECK(condition)
bool WriteAtomically(const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
void InstallCrashHandler()
CommandLine CommandLineFromPlatformOrArgcArgv(int argc, const char *const *argv)
bool Main(const fml::CommandLine &command_line)
bool SetPermissiveAccess(const std::filesystem::path &p)
Sets the file access mode of the file at path 'p' to 0644.
static bool OutputDepfile(const Compiler &compiler, const Switches &switches)
bool GenerateShaderBundle(Switches &switches)
Parses the JSON shader bundle configuration and invokes the compiler multiple times to produce a shad...
static Reflector::Options CreateReflectorOptions(const SourceOptions &options, const Switches &switches)
static bool OutputReflectionData(const Compiler &compiler, const Switches &switches, const SourceOptions &options)
static std::shared_ptr< RuntimeStageData::Shader > CompileSkSL(std::shared_ptr< fml::Mapping > source_file_mapping, const Switches &switches)
static bool OutputIPLR(const Switches &switches, const std::shared_ptr< fml::Mapping > &source_file_mapping)
std::string Utf8FromPath(const std::filesystem::path &path)
Converts a native format path to a utf8 string.
bool TargetPlatformBundlesSkSL(TargetPlatform platform)
bool TargetPlatformNeedsReflection(TargetPlatform platform)
static bool OutputSLFile(const Compiler &compiler, const Switches &switches)
std::string InferShaderNameFromPath(std::string_view path)
TargetPlatform target_platform
std::string entry_point_name
std::string header_file_name