| {{- /* Collect all the conditionals used by all targets in this directory */}} |
| {{- $AllConditionals := $.DecomposedConditionals}} |
| load("//src/tint:flags.bzl", "COPTS") |
| load("@bazel_skylib//lib:selects.bzl", "selects") |
| {{/* newline */}} |
| |
| {{- Eval "TargetIfNotEmpty" ($.Project.Target $ "lib")}} |
| {{- Eval "TargetIfNotEmpty" ($.Project.Target $ "test")}} |
| {{- Eval "TargetIfNotEmpty" ($.Project.Target $ "bench")}} |
| {{- Eval "TargetIfNotEmpty" ($.Project.Target $ "cmd")}} |
| {{- Eval "TargetIfNotEmpty" ($.Project.Target $ "test_cmd")}} |
| {{- Eval "TargetIfNotEmpty" ($.Project.Target $ "bench_cmd")}} |
| |
| {{- Eval "ConditionalRules" $AllConditionals}} |
| |
| |
| {{- /* |
| -------------------------------------------------------------------------------- |
| -- Emits a Bazel target if it contains any files |
| -------------------------------------------------------------------------------- |
| */ -}} |
| {{- define "TargetIfNotEmpty"}} |
| {{- if $}} |
| {{- if len $.SourceFiles}}{{Eval "Target" $}}{{end}} |
| {{- end}} |
| {{- end}} |
| |
| |
| {{- /* |
| -------------------------------------------------------------------------------- |
| -- Emits a Bazel target |
| -------------------------------------------------------------------------------- |
| */ -}} |
| {{- define "Target"}} |
| {{- $Conditionals := $.Conditionals}} |
| {{- if $.Kind.IsLib -}} |
| cc_library( |
| name = "{{$.Directory.Name}}", |
| {{- else if $.Kind.IsTest -}} |
| cc_library( |
| name = "test", |
| alwayslink = True, |
| {{- else if $.Kind.IsBench -}} |
| cc_library( |
| name = "bench", |
| alwayslink = True, |
| {{- else if $.Kind.IsCmd -}} |
| cc_binary( |
| name = "cmd", |
| {{- else if $.Kind.IsTestCmd -}} |
| cc_binary( |
| name = "test_cmd", |
| {{- else if $.Kind.IsBenchCmd -}} |
| cc_binary( |
| name = "bench_cmd", |
| {{- end}} |
| srcs = [ |
| {{- range $File := $.UnconditionalSourceFiles}} |
| {{- if or (not $.Kind.IsLib) (HasSuffix $File.Name ".cc")}} |
| "{{TrimPrefix $File.Name $.Directory.Path}}", |
| {{- end}} |
| {{- end}} |
| ] |
| {{- if $Conditionals.HasSourceFiles}} |
| {{- range $Cond := $Conditionals}} + select({ |
| {{- if $Cond.SourceFiles}} |
| ":{{Eval "ConditionTarget" $Cond.Condition}}": [ |
| {{- range $File := $Cond.SourceFiles}} |
| "{{TrimPrefix $File.Name $.Directory.Path}}", |
| {{- end}} |
| ], |
| {{- end}} |
| "//conditions:default": [], |
| }) |
| {{- end}} |
| {{- end}}, |
| {{- if $.Kind.IsLib}} |
| hdrs = [ |
| {{- range $File := $.UnconditionalSourceFiles}} |
| {{- if not (HasSuffix $File.Name ".cc")}} |
| "{{TrimPrefix $File.Name $.Directory.Path}}", |
| {{- end}} |
| {{- end}} |
| ], |
| {{- end}} |
| deps = [ |
| {{- /* Emit unconditional internal dependencies */}} |
| {{- range $Dep := $.Dependencies.UnconditionalInternal}} |
| "{{Eval "Dependency" $Dep}}", |
| {{- end}} |
| |
| {{- /* Emit unconditional external dependencies */}} |
| {{- range $Dep := $.Dependencies.UnconditionalExternal}} |
| {{Eval "ExternalDependencyTarget" $Dep}} |
| {{- end}} |
| ] |
| {{- if $Conditionals.HasDependencies}} |
| {{- range $Cond := $Conditionals}} + select({ |
| {{- if or $Cond.InternalDependencies $Cond.ExternalDependencies}} |
| ":{{Eval "ConditionTarget" $Cond.Condition}}": [ |
| {{- range $Dep := $Cond.InternalDependencies}} |
| "{{Eval "Dependency" $Dep}}", |
| {{- end}} |
| {{- range $Dep := $Cond.ExternalDependencies}} |
| {{Eval "ExternalDependencyTarget" $Dep}} |
| {{- end}} |
| ], |
| {{- end}} |
| "//conditions:default": [], |
| }) |
| {{- end}} |
| {{- end}}, |
| copts = COPTS, |
| visibility = ["//visibility:public"], |
| ) |
| {{/* newline */}} |
| {{- end}} |
| |
| |
| {{- /* |
| -------------------------------------------------------------------------------- |
| -- Emits a dependency target name |
| -------------------------------------------------------------------------------- |
| */ -}} |
| {{- define "Dependency" -}} |
| {{- if $.Kind.IsLib -}}//src/tint/{{$.Directory.Path}} |
| {{- else if $.Kind.IsTest -}}//src/tint/{{$.Directory.Path}}:test |
| {{- else if $.Kind.IsBench -}}//src/tint/{{$.Directory.Path}}:bench |
| {{- else if $.Kind.IsCmd -}}//src/tint/{{$.Directory.Path}}:cmd |
| {{- else if $.Kind.IsTestCmd -}}//src/tint/{{$.Directory.Path}}:test_cmd |
| {{- else if $.Kind.IsBenchCmd -}}//src/tint/{{$.Directory.Path}}:bench_cmd |
| {{- end}} |
| {{- end}} |
| |
| |
| {{- /* |
| -------------------------------------------------------------------------------- |
| -- Emits comma separated, quoted external dependency target name(s) with a trailing comma |
| -- External target names are declared in tools/src/cmd/gen/build/externals.json |
| -------------------------------------------------------------------------------- |
| */ -}} |
| {{- define "ExternalDependencyTarget"}} |
| {{- if eq $.Name "abseil" -}}"@abseil_cpp//absl/strings", |
| {{- else if eq $.Name "glslang-res-limits" -}}{{/* unsupported */}} |
| {{- else if eq $.Name "glslang" -}}{{/* unsupported */}} |
| {{- else if eq $.Name "gmock" -}}"@gtest", |
| {{- else if eq $.Name "google-benchmark" -}}"@benchmark", |
| {{- else if eq $.Name "gtest" -}}"@gtest", |
| {{- else if eq $.Name "jsoncpp" -}}{{/* unsupported */}} |
| {{- else if eq $.Name "langsvr" -}}{{/* unsupported */}} |
| {{- else if eq $.Name "metal" -}}{{/* unsupported */}} |
| {{- else if eq $.Name "spirv-headers" -}}"@spirv_headers//:spirv_cpp11_headers", "@spirv_headers//:spirv_c_headers", |
| {{- else if eq $.Name "spirv-opt-internal" -}}"@spirv_tools//:spirv_tools_opt", |
| {{- else if eq $.Name "spirv-tools" -}}"@spirv_tools", |
| {{- else if eq $.Name "thread" -}}{{/* unsupported */}} |
| {{- else if eq $.Name "winsock" -}}{{/* unsupported */}} |
| {{- else -}}{{Error (printf "unhandled external dependency '%v'" $.Name)}} |
| {{- end}} |
| {{- end}} |
| |
| |
| {{- /* |
| -------------------------------------------------------------------------------- |
| -- Emits all the conditional rules required by the targets |
| -------------------------------------------------------------------------------- |
| */ -}} |
| {{- define "ConditionalRules"}} |
| {{- if $.Unarys}} |
| {{- range $Unary := $.Unarys}} |
| alias( |
| name = "{{Eval "ConditionTarget" $Unary}}", |
| actual = "//src/tint:{{$Unary.Var}}_{{not $Unary.Negate}}", |
| ) |
| {{/* newline */}} |
| {{- end}} |
| {{- end}} |
| {{- if $.Ors}} |
| {{- range $Ors := $.Ors}} |
| selects.config_setting_group( |
| name = "{{Eval "ConditionTarget" $Ors}}", |
| match_any = [ |
| {{- range $Unary := $Ors}} |
| "{{Eval "ConditionTarget" $Unary}}", |
| {{- end}} |
| ], |
| ) |
| {{/* newline */}} |
| {{- end}} |
| {{- end}} |
| {{- if $.Ands}} |
| {{- range $Ands := $.Ands}} |
| selects.config_setting_group( |
| name = "{{Eval "ConditionTarget" $Ands}}", |
| match_all = [ |
| {{- range $Ors := $Ands}} |
| ":{{Eval "ConditionTarget" $Ors}}", |
| {{- end}} |
| ], |
| ) |
| {{- end}} |
| {{/* newline */}} |
| {{- end}} |
| {{- end}} |
| |
| |
| {{- /* |
| -------------------------------------------------------------------------------- |
| -- Emits a target name for a condition expression |
| -------------------------------------------------------------------------------- |
| */ -}} |
| {{- define "ConditionTarget" -}} |
| {{- $C := $.String}} |
| {{- $C := Replace $C " && " "_and_"}} |
| {{- $C := Replace $C " || " "_or_"}} |
| {{- $C := Replace $C "!" "not_"}} |
| {{- $C := Replace $C "(" "_"}} |
| {{- $C := Replace $C ")" "_"}} |
| {{- $C := Replace $C " " "_"}} |
| {{- $C}} |
| {{- end}} |