GN(1)

πŸ¦‹ GN(1) β€” User Commands, but make it a group chat πŸ¦‹

okay so this is the gn manual page, filed under User Commands in section 1, and bestie it is long. like, "grab a snack" long. πŸ“

the good news? you never have to memorize any of this, because everything on this page has its own little help page. type:

gn help <command>

for commands, gn help <function> for target declarations and buildfile functions, and gn help <variable> for variables. iykyk πŸ’…


✨ NAME ✨

gn β€” Documentation for GN


πŸŽ€ DESCRIPTION πŸŽ€

this whole section is literally just the index of everything gn can do, so let's go section by section, no skipping. 🌸

πŸ’… Commands πŸ’…

type gn help <command> for more help on any of these, bestie. here's the whole squad:

  • analyze β€” works out which targets are affected by a list of files. detective mode, no cap πŸ”
  • args β€” shows you the arguments your build declares, or configures them for you. yes, you can actually set them from here.
  • check β€” checks your header dependencies.
  • clean β€” cleans the output directory. wipe it. self care ✨
  • clean_stale β€” same energy, but it only cleans the stale output files out of the output directory. it's selective, we respect it.
  • desc β€” shows a whole lot of insightful information about a target or a config. it's giving gossip column but for your build πŸ‘€
  • edit β€” edits BUILD.gn files straight from the command line.
  • format β€” formats .gn files. they were doing their best before, but now they're pretty.
  • gen β€” generates ninja files. this is the main character moment πŸŽ€
  • help β€” "does what you think." that's the entire description. no notes, iconic.
  • ls β€” lists matching targets.
  • meta β€” lists target metadata collection results.
  • outputs β€” tells you which files a source or a target make.
  • path β€” finds the paths between two targets. connect the dots πŸ¦‹
  • refs β€” finds stuff that references a target or a file.
  • suggest β€” suggests fixes to the build graph based on includes. bestie advice fr fr 🫢

🧚 Target declarations 🧚

type gn help <function> for more help on any of these. these are the things you use to declare targets:

  • action β€” declares a target that runs a script a single time. one and done.
  • action_foreach β€” declares a target that runs a script over a set of files.
  • bundle_data β€” [iOS/macOS] declares a target without output. yes, a target with no output. it exists, that's the vibe.
  • copy β€” declares a target that copies files. exactly what it says πŸ’…
  • create_bundle β€” [iOS/macOS] builds an iOS or macOS bundle.
  • executable β€” declares an executable target.
  • generated_file β€” declares a generated_file target.
  • group β€” declares a named group of targets.
  • loadable_module β€” declares a loadable module target.
  • rust_library β€” declares a Rust library target.
  • rust_proc_macro β€” declares a Rust procedural macro target.
  • shared_library β€” declares a shared library target.
  • source_set β€” declares a source set target.
  • static_library β€” declares a static library target.
  • target β€” declares a target with the given programmatic type. the wildcard one, lowkey powerful.

🌈 Buildfile functions 🌈

type gn help <function> for more help. this is the function section in its full glory:

  • assert β€” asserts that an expression is true at generation time. if it's not true, it's not happening.
  • config β€” defines a configuration object.
  • declare_args β€” declares build arguments.
  • defined β€” returns whether an identifier is defined.
  • exec_script β€” synchronously runs a script and returns the output.
  • expand_directory β€” expands a source directory and returns files.
  • filter_exclude β€” removes values that match a set of patterns. bye πŸ’€
  • filter_include β€” removes values that do not match a set of patterns. keep only the ones that match.
  • filter_labels_exclude β€” removes labels that match a set of patterns.
  • filter_labels_include β€” removes labels that do not match a set of patterns.
  • foreach β€” iterates over a list.
  • forward_variables_from β€” copies variables from a different scope.
  • get_label_info β€” gets an attribute from a target's label.
  • get_path_info β€” extracts parts of a file or directory name.
  • get_target_outputs β€” [file list] gets the list of outputs from a target.
  • getenv β€” gets an environment variable.
  • import β€” imports a file into the current scope.
  • label_matches β€” returns whether a label matches any of a list of patterns.
  • len β€” returns the length of a string or a list.
  • not_needed β€” marks variables from scope as not needed. not me ignoring my problems πŸ™ˆ
  • path_exists β€” returns whether the given path exists.
  • pool β€” defines a pool object.
  • print β€” prints to the console.
  • print_stack_trace β€” prints a stack trace.
  • process_file_template β€” does template expansion over a list of files.
  • read_file β€” reads a file into a variable.
  • rebase_path β€” rebases a file or directory to another location.
  • set_default_toolchain β€” sets the default toolchain name.
  • set_defaults β€” sets default values for a target type.
  • split_list β€” splits a list into N different sub-lists.
  • string_hash β€” calculates a stable hash of the given string.
  • string_join β€” concatenates a list of strings with a separator.
  • string_replace β€” replaces substring in the given string.
  • string_split β€” splits string into a list of strings.
  • template β€” defines a template rule.
  • tool β€” specifies arguments to a toolchain tool.
  • toolchain β€” defines a toolchain.
  • write_file β€” writes a file to disk.

⭐ Built-in predefined variables ⭐

type gn help <variable> for more help. these ones come free with the build, no assembly required:

  • current_cpu β€” [string] the processor architecture of the current toolchain.
  • current_os β€” [string] the operating system of the current toolchain.
  • current_toolchain β€” [string] label of the current toolchain.
  • default_toolchain β€” [string] label of the default toolchain.
  • generate_modulemap β€” [string] mode for generating modulemaps.
  • gn_version β€” [number] the version of gn. your girl has a number πŸ‘‘
  • host_cpu β€” [string] the processor architecture that GN is running on.
  • host_os β€” [string] the operating system that GN is running on.
  • invoker β€” [string] the invoking scope inside a template.
  • python_path β€” [string] absolute path of Python.
  • root_build_dir β€” [string] directory where build commands are run.
  • root_gen_dir β€” [string] directory for the toolchain's generated files.
  • root_out_dir β€” [string] root directory for toolchain output files.
  • target_cpu β€” [string] the desired cpu architecture for the build.
  • target_gen_dir β€” [string] directory for a target's generated files.
  • target_name β€” [string] the name of the current target.
  • target_os β€” [string] the desired operating system for the build.
  • target_out_dir β€” [string] directory for target output files.

πŸ’œ Variables you set in targets πŸ’œ

type gn help <variable> for more help. these are the ones you get to write, so go off:

  • aliased_deps β€” [scope] set of crate-dependency pairs.
  • all_dependent_configs β€” [label list] configs to be forced on dependents.
  • allow_circular_includes_from β€” [label list] permit includes from deps.
  • arflags β€” [string list] arguments passed to static_library archiver.
  • args β€” [string list] arguments passed to an action.
  • asmflags β€” [string list] flags passed to the assembler.
  • assert_no_deps β€” [label pattern list] ensure no deps on these targets.
  • bridge_header β€” [string] path to C/Objective-C compatibility header.
  • bundle_contents_dir β€” expansion of {{bundle_contents_dir}} in create_bundle.
  • bundle_deps_filter β€” [label list] a list of labels that are filtered out.
  • bundle_executable_dir β€” expansion of {{bundle_executable_dir}} in create_bundle
  • bundle_resources_dir β€” expansion of {{bundle_resources_dir}} in create_bundle.
  • bundle_root_dir β€” expansion of {{bundle_root_dir}} in create_bundle.
  • c_additional_outputs β€” [string list] additional outputs for the compiler.
  • cflags β€” [string list] flags passed to all C compiler variants.
  • cflags_c β€” [string list] flags passed to the C compiler.
  • cflags_cc β€” [string list] flags passed to the C++ compiler.
  • cflags_objc β€” [string list] flags passed to the Objective C compiler.
  • cflags_objcc β€” [string list] flags passed to the Objective C++ compiler.
  • check_includes β€” [boolean] controls whether a target's files are checked.
  • check_includes_strict β€” [boolean] controls whether strict include checking is enforced. strict queen πŸ’…
  • collect_validations_metadata β€” [bool] collect metadata values from validations deps.
  • complete_static_lib β€” [boolean] links all deps into a static library.
  • configs β€” [label list] configs applying to this target or config.
  • contents β€” contents to write to file.
  • crate_name β€” [string] the name for the compiled crate.
  • crate_root β€” [string] the root source file for a binary or library.
  • crate_type β€” [string] the type of linkage to use on a shared_library.
  • data β€” [file list] runtime data file dependencies.
  • data_deps β€” [label list] non-linked dependencies.
  • data_keys β€” [string list] keys from which to collect metadata.
  • defines β€” [string list] C preprocessor defines.
  • depfile β€” [string] file name for input dependencies for actions.
  • deps β€” [label list] private linked dependencies.
  • externs β€” [scope] set of Rust crate-dependency pairs.
  • framework_dirs β€” [directory list] additional framework search directories.
  • frameworks β€” [name list] name of frameworks that must be linked.
  • friend β€” [label pattern list] allow targets to include private headers. friendship is a permission system 🫢
  • gen_deps β€” [label list] declares targets that should generate when this one does.
  • include_dirs β€” [directory list] additional include directories.
  • inputs β€” [file list] additional compile-time dependencies.
  • ldflags β€” [string list] flags passed to the linker.
  • lib_dirs β€” [directory list] additional library directories.
  • libs β€” [string list] additional libraries to link.
  • metadata β€” [scope] metadata of this target.
  • mnemonic β€” [string] prefix displayed when ninja runs this action.
  • module_name β€” [string] the name for the compiled module.
  • output_conversion β€” data format for generated_file targets.
  • output_dir β€” [directory] directory to put output file in.
  • output_extension β€” [string] value to use for the output's file extension.
  • output_name β€” [string] name for the output file other than the default.
  • output_prefix_override β€” [boolean] don't use prefix for output name.
  • outputs β€” [file list] output files for actions and copy targets.
  • partial_info_plist β€” [filename] path plist from asset catalog compiler.
  • pool β€” [string] label of the pool used by binary targets and actions.
  • post_processing_args β€” [string list] args for the post-processing script.

(and that's only part 1, bestie β€” part 2 is right there, don't move πŸ’œ)

  • post_processing_manifest β€” [file] bestie, this is the name of the generated bundle manifest πŸŽ€
  • post_processing_outputs β€” [file list] the outputs of the post-processing step
  • post_processing_script β€” [file name] the script for the post-processing step
  • post_processing_sources β€” [file list] the sources for the post-processing step
  • precompiled_header β€” [string] header file to precompile
  • precompiled_header_type β€” [string] literally just "gcc" or "msvc", pick one πŸ’…
  • precompiled_source β€” [file name] source file to precompile
  • product_type β€” [string] the product type for the bundle
  • public β€” [file list] declare public header files for a target
  • public_configs β€” [label list] configs applied to dependents
  • public_deps β€” [label list] declare public dependencies
  • public_inputs β€” [file list] declare public inputs
  • rebase β€” [boolean] rebase collected metadata as files
  • response_file_contents β€” [string list] contents of .rsp file for actions
  • rustflags β€” [string list] flags passed to the Rust compiler πŸ¦€
  • script β€” [file name] script file for actions
  • sources β€” [file list] source files for a target
  • swiftflags β€” [string list] flags passed to the swift compiler
  • target_xcode_platform β€” [string] the desired platform for the build
  • testonly β€” [boolean] declares a target must only be used for testing
  • transparent β€” [bool] true if the bundle is transparent
  • validations β€” [label list] validation dependencies
  • visibility β€” [label list] a list of labels that can depend on a target
  • walk_keys β€” [string list] key(s) for managing the metadata collection walk
  • weak_frameworks β€” [name list] name of frameworks that must be weak linked
  • weak_libraries β€” [file list] file of libraries that must be weak linked
  • write_runtime_deps β€” writes the target's runtime_deps to the given path
  • xcasset_compiler_flags β€” [string list] flags passed to xcassets compiler
  • xcode_extra_attributes β€” [scope] extra attributes for Xcode projects
  • xcode_test_application_name β€” [string] name for Xcode test target

🫢 Other help topics 🫢

these are the other pages in the GN lore, bestie. run gn help <topic> and go off πŸ’–

  • all β€” print all the help at once (the whole buffet, no cap)
  • buildargs β€” how build arguments work
  • dotfile β€” info about the toplevel .gn file
  • execution β€” build graph and execution overview
  • grammar β€” language and grammar for GN build files
  • input_conversion β€” processing input from exec_script and read_file
  • file_pattern β€” matching more than one file
  • label_pattern β€” matching more than one label
  • labels β€” about labels
  • metadata_collection β€” about metadata and its collection
  • ninja_rules β€” how Ninja build rules are named
  • nogncheck β€” annotating includes for checking
  • output_conversion β€” specifies how to transform a value to output
  • runtime_deps β€” how runtime dependency computation works
  • source_expansion β€” map sources to outputs for scripts
  • switches β€” show available command-line switches

and that's a wrap on the whole page, bestie πŸŽ€βœ¨ you just read gn 2598 (the build is f90c3d9df882, iconic, no notes πŸ’…), dated October 2026. go build something gorgeous πŸŒˆπŸ¦‹ fr fr πŸ’–

πŸ“¦ where this page comes from