@main applied to extension fails from command line

I have a macro @Application that among other things applies @main to the declaration. Since this is a macro, it applies the @main in an extension.

@main extension MyApplication: Application { ... }

When running the program in Xcode, it works fine. When building with swift build -v however, I get the following error:

error: 'main' attribute cannot be used in a module that contains top-level code

The file isn't called main.swift so that isn't the issue - is @main not working on an extension on cli expected behavior?