Looking for info/help on implementing new moz.build targets

Even though I’ve read most of the documentation on the matter, I’m not quite sure I understand where to start with implementing a new target/flag for mach/moz.build.

Essentially, I’d like to create an option (let’s call it TSC, for simplicity’s sake) that, when added to a moz.build file, instructs mach (or rather make. As far as I understand it, mach would merely call make) to call the TypeScript compiler and recursively compile all .ts files in a directory.

Are there any good examples for such a behaviour?

Really just a personal interest. I know TypeScript is unlikely to make it to the official tree anytime soon.

Hi there! Adding a new moz.build symbol involves touching a couple of files. First, you need to add the name to context.py. That’s where things like SOURCES define the data types they accept. Second, you need to change TreeMetaDataEmitter in emitter.py to handle your new symbol. You probably want to put code in emit_from_context. Most moz.build symbols get mapped to data structures from data.py for consumption by build backends. Then, to cause the recursive make backend to output Makefile data for your new symbol you’ll want to add handling for it to RecursiveMakeBackend.consume_object. Most things write data out to backend_file, which is the backend.mk file that gets generated for each objdir directory corresponding to a srcdir directory with a moz.build file. Finally, you need to make the recursive make backend do something with this data. A few things in the recursive make backend write out make rules directly into the backend.mk, but a lot of them simply write out variable declarations and rely on rules in rules.mk to do the actual work.

Good luck!

1 Like