//mojo:defs.bzl
Import these rules in your BUILD.bazel
files.
To load for example the mojo_binary
rule:
mojo_binary
mojo_binary(name, deps, srcs, compile_flags, compile_string_flags, defines, includes, runtime_data)
Creates an executable.
Example:
Attributes
Name | Description |
---|---|
name | Name , required.A unique name for this target. |
deps | List of labels , optional, defaults to [] .The dependencies for this target. Use ll_library targets here. Other targets won’t work. |
srcs | List of labels , optional, defaults to [] .Compilable source files for this target. Allowed file extensions: [".mojo", ".🔥"] .Place headers in the hdrs attribute. |
compile_flags | List of strings , optional, defaults to [] .Flags for the compiler. Pass a list of strings here. For instance ["-O3", "-std=c++20"] .Split flag pairs -Xclang -somearg into separate flags ["-Xclang", "-somearg"] .Unavailable to downstream targets. |
compile_string_flags | List of labels , optional, defaults to [] .Flags for the compiler in the form of string_flag s.Splits the values of each string_flag along colons like so:
Useful for externally configurable build attributes, such as generated flags from Nix environments. |
defines | List of strings , optional, defaults to [] .Defines for this target. Pass a list of strings here. For instance ["MYDEFINE_1", "MYDEFINE_2"] .Unavailable to downstream targets. |
includes | List of strings , optional, defaults to [] .Include paths, relative to the target workspace. Uses -iquote .Useful if you need custom include prefix stripping for dynamic paths, for instance the ones generated by bzlmod . Instead of compile_flags = ["-iquoteexternal/mydep.someversion/include"] , use includes = ["include"] to add the path to the workspace automatically.Expands paths starting with $(GENERATED) to the workspace location in the GENDIR path.Unavailable to downstream targets. |
runtime_data | List of labels , optional, defaults to [] .Extra files made available during test time. |
mojo_library
mojo_library(name, deps, srcs, compile_flags, compile_string_flags, defines, includes)
Creates a Mojo package.
Example:
Attributes
Name | Description |
---|---|
name | Name , required.A unique name for this target. |
deps | List of labels , optional, defaults to [] .The dependencies for this target. Use ll_library targets here. Other targets won’t work. |
srcs | List of labels , optional, defaults to [] .Compilable source files for this target. Allowed file extensions: [".mojo", ".🔥"] .Place headers in the hdrs attribute. |
compile_flags | List of strings , optional, defaults to [] .Flags for the compiler. Pass a list of strings here. For instance ["-O3", "-std=c++20"] .Split flag pairs -Xclang -somearg into separate flags ["-Xclang", "-somearg"] .Unavailable to downstream targets. |
compile_string_flags | List of labels , optional, defaults to [] .Flags for the compiler in the form of string_flag s.Splits the values of each string_flag along colons like so:
Useful for externally configurable build attributes, such as generated flags from Nix environments. |
defines | List of strings , optional, defaults to [] .Defines for this target. Pass a list of strings here. For instance ["MYDEFINE_1", "MYDEFINE_2"] .Unavailable to downstream targets. |
includes | List of strings , optional, defaults to [] .Include paths, relative to the target workspace. Uses -iquote .Useful if you need custom include prefix stripping for dynamic paths, for instance the ones generated by bzlmod . Instead of compile_flags = ["-iquoteexternal/mydep.someversion/include"] , use includes = ["include"] to add the path to the workspace automatically.Expands paths starting with $(GENERATED) to the workspace location in the GENDIR path.Unavailable to downstream targets. |
mojo_test
mojo_test(name, deps, srcs, compile_flags, compile_string_flags, defines, includes, runtime_data)
Testable wrapper around mojo_binary
.
Consider using this rule over Skylib’s native_test
targets to propagate shared
libraries to the test invocations.
Example:
Attributes
Name | Description |
---|---|
name | Name , required.A unique name for this target. |
deps | List of labels , optional, defaults to [] .The dependencies for this target. Use ll_library targets here. Other targets won’t work. |
srcs | List of labels , optional, defaults to [] .Compilable source files for this target. Allowed file extensions: [".mojo", ".🔥"] .Place headers in the hdrs attribute. |
compile_flags | List of strings , optional, defaults to [] .Flags for the compiler. Pass a list of strings here. For instance ["-O3", "-std=c++20"] .Split flag pairs -Xclang -somearg into separate flags ["-Xclang", "-somearg"] .Unavailable to downstream targets. |
compile_string_flags | List of labels , optional, defaults to [] .Flags for the compiler in the form of string_flag s.Splits the values of each string_flag along colons like so:
Useful for externally configurable build attributes, such as generated flags from Nix environments. |
defines | List of strings , optional, defaults to [] .Defines for this target. Pass a list of strings here. For instance ["MYDEFINE_1", "MYDEFINE_2"] .Unavailable to downstream targets. |
includes | List of strings , optional, defaults to [] .Include paths, relative to the target workspace. Uses -iquote .Useful if you need custom include prefix stripping for dynamic paths, for instance the ones generated by bzlmod . Instead of compile_flags = ["-iquoteexternal/mydep.someversion/include"] , use includes = ["include"] to add the path to the workspace automatically.Expands paths starting with $(GENERATED) to the workspace location in the GENDIR path.Unavailable to downstream targets. |
runtime_data | List of labels , optional, defaults to [] .Extra files made available during test time. |