Building and testing Golang projects can become cumbersome as the complexity of a project grows. Developers often find themselves using long, repetitive commands to build, test, and deploy their code. Fortunately, the mmake
tool simplifies this process by allowing developers to define and run custom Makefile targets with ease. In this article, we’ll explore how to use mmake
in Golang projects to streamline your build process.
Mmake
(short for “Modern Make”) is a command-line tool developed by Tobias G. Müller that aims to improve the developer experience when working with Makefiles. It provides a more readable and maintainable alternative to traditional Makefiles, using a simple and expressive syntax.
Key features of mmake
include:
go get
First, you’ll need to install mmake
on your system. You can do this by running the following go get
command:
go get -u github.com/tj/mmake/cmd/mmake
Now, let’s create a simple Golang project to demonstrate mmake
in action:
mkdir my-golang-project
cd my-golang-project
// main.go
package main
import "fmt"
func main() {
fmt.Println("Hello, Mmake!")
}
.mmakefile.yml
file in the project root:.mmakefile.yml
build:
description: "Build the project"
script: "go build -o my-golang-project"
run:
description: "Run the project"
script: "./my-golang-project"
test:
description: "Run tests"
script: "go test"
In this .mmakefile.yml
, we’ve defined three tasks: build
, run
, and test
. Each task has a description
and a script
to be executed when the task runs.
Now that we have a basic project set up, let’s see how to use mmake
to execute our tasks.
mmake help
You should see output similar to the following:
Tasks:
build Build the project
run Run the project
test Run tests
mmake build
This will execute the go build -o my-golang-project
command defined in the build
task.
mmake run
This will execute the ./my-golang-project
command defined in the run
task, and you should see the output Hello, Mmake!
.
mmake test
Since we don’t have any tests defined yet, the output will show that no tests were executed.
In this article, we’ve explored how to use mmake
to simplify building, running, and testing Golang projects. By leveraging the power of mmake
, you can streamline your development process and improve the maintainability of your build scripts.