9.5.2 @:autoBuild

If a class has the :autoBuild metadata, the compiler generates :build metadata on all extending classes. If an interface has the :autoBuild metadata, the compiler generates :build metadata on all implementing classes and all extending interfaces. Note that :autoBuild does not imply :build on the class/interface itself.

import haxe.macro.Context;
import haxe.macro.Expr;

class AutoBuildingMacro {
  macro static public function fromInterface():Array<Field> {
    trace("fromInterface: " + Context.getLocalType());
    return null;

  macro static public function fromBaseClass():Array<Field> {
    trace("fromBaseClass: " + Context.getLocalType());
    return null;
interface I {}

interface I2 extends I {}

class Base {}

class Main extends Base implements I2 {
  static public function main() {}

This outputs during compilation:

  fromInterface: TInst(I2,[])
  fromInterface: TInst(Main,[])
  fromBaseClass: TInst(Main,[])

It is important to keep in mind that the order of these macro executions is undefined, which is detailed in Build Order.

Related content