Magefiles - a makefile replacement using go

311 views
Skip to first unread message

Nate Finch

unread,
Sep 22, 2017, 11:02:33 PM9/22/17
to golang-nuts
https://github.com/magefile/mage

A mage file is any regular go file marked with a build target of "mage" and in package main.

// +build mage

package main


You may have any number of magefiles in the same directory. Mage doesn't care what they're named aside from normal go filename rules. All they need is to have the mage build target. Handily, this also excludes them from your regular builds, so they can live side by side with your normal go files. Magefiles may use any of Go's usual build constraints, so you can include and exclude magefiles based on OS, arch, etc, whether in the filename or in the +build line.

Targets

Any exported function that has no arguments and either no return values or a single error value is considered a mage target. If the function has an error return, errors returned from the function will print to stdout and cause the magefile to exit with an exit code of 1. Any functions that do not fit this pattern are not considered targets by mage.

Comments on the target function will become documentation accessible by running mage -l which will list all the build targets in this directory with the first sentence from their docs, or mage -h <target> which will show the full comment from the docs on the function.

Targets may be run just like make targets, i,e,

mage build

Check it out and let me know what you think.  More features forthcoming.

-Nate

snmed

unread,
Sep 23, 2017, 1:11:28 AM9/23/17
to golang-nuts
Hi Nate

Awesome, i never liked make files and fortunately i could use npm scripts to build front and backend. I'm glad to see an alternative to make files in go, i will give it a try.

Cheers Sandro

Henrik Johansson

unread,
Sep 23, 2017, 4:15:23 AM9/23/17
to snmed, golang-nuts
I just have a case where I was wondering if a Makefile could be the answer. Ill try mage instead and see what it can do!

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nate Finch

unread,
Sep 25, 2017, 12:01:54 PM9/25/17
to golang-nuts
Additional note - just landde a change to support makefile style dependency trees.  i.e. you can say x depnds on y and z, and z depends on y and Q, and all dependencies will be run exactly once, from leafs up to the root, and all in their own goroutines.

And there's a #mage channel on gopher slack if you want to chat about it :)
Reply all
Reply to author
Forward
0 new messages