MacOS setup to code and compile ZooBC (Article)

In this tutorial we’re gonna try to set up and compile the ZooBC code. 

Install Golang 

  1. First thing first, we need to go to www.golang.org/dl. As you can see, it comes in several versions but as this tutorial is for MacOS, we’re gonna choose the one for MacOS. 

  1. So after you click the desired option, it will automatically download a package inside your computer. Once the software is being downloaded, we can simply click the folder. Before we start the installation, you will be asked to put in information on the password of the administrator. I want to emphasize that you need to be the administrator user and not the regular user if you want to install and code the system in Golang. 

Let’s code 

  1. You need to open your terminal, and you can find it on Application, then click the Utilities folder and once the terminal is launched we can start to execute the command below to see if the golang has been installed.

$ go version

  1. Now we need to create a few folder to get ready and set up a correct structure how to work with go by doing this command:

$ mkdir ~/go ; mkdir ~/go/src ; mkdir ~/go/bin ; mkdir ~/go/pkg ; mkdir ~/go/src/zoobc

In this command, it’s gonna create the folder go  in the user main directory and inside it’s gonna be several other folders where we are going to download the ZooBC code. Once this step is done lets us move into seeing up the environment in your computer so it’s gonna be ready for the golang. 

Set the Environment Variable 

  1. Let’s execute the command below to see which shell that you are using.  

$ ps -p $$


Here, I’m using -zsh, and if you are using bash then the file is gonna be different. 

  1. Let’s look for the zettashell, let’s do:

$ pico ~/.zshenv

Once you’ve opened the zettashell, paste this command below and save it:

export GOPATH=~/go

export PATH=~/go/bin:$PATH

To run the program properly, you will need to always load your shell with those variables

  1. If you are using bash , the command would take this form:

$ pico ~/.bash_profile

Same like before, paste this command below and save it:

export GOPATH=~/go

export PATH=~/go/bin:$PATH

So, no matter which command you use, it’s gonna close the terminal and reopen it to see if your code loads this variable. Next, you need to open your text editor. In this tutorial, I’m going to use the visual studio code, so if you haven’t installed it yet, let me show you how. 

Installing Visual Studio Code 

  1. Open your browser and go to their website to download the App:  https://code.visualstudio.com/download
  1. As we are using MacOs, we are gonna choose the option for the MacOs 

Once the App has been installed, click on the zip file and simply drag the Visual Studio code into the application folder. So once it’s on the application, just click its icon to open the App. 

Installing Golang

  1. Let’s go back to our terminal to install the module for the Golang. First, we need to enter to the directory of go by using the following command:

$ cd ~/go/ 

  1. Then, execute this command to install the Golangci 

$ cd curl -sfL https://install.goreleaser.com/github… | sh -s v1.23.8

And to see the if the installation is going well, we can simply use the command below:

$ ./bin/golangci-lint –version

Installing Docker and Go xgo 

Docker is a tool that allows you to run several different things. Once we’ve decided to use this as a cross-compiler so once we’ve created a binary code for our application, we are going to use “xgo” in  Docker to create a Windows or Linux version. 

1. To download the Application, simply go to the website Download Docker and choose the one for the MacOs. Once the downloading is finished, just drag the file into the Application folder. 

And once it’s on the Application folder, just double click the icon to open it.

2. It then will ask you to put in the Administration password. In this case, you can simply enter your password and let Docker run. So once you’ve started the engine of Docker , you can simply close the UI . 

3. Lets move to the terminal and install the xgo by using command:

$ go get github.com/karalabe/xgo

In the beginning, the system will warn you that because the command line developers of Apple are not installed in this computer, so the installation of the XGO has failed. And to fix this, you can just click “allow the installation” for the command line 

And once the command line of the developer tools has successfully been installed, then we can 

go back to the terminal and execute the same command line to install the xgo. 

$ go get github.com/karalabe/xgo

Now we are going to get Docker to pull this xgo by using the following command:

$ docker pull karalabe/xgo-latest

At this point we need to create some links for the xgo for the Golangci so we can execute them from other places as well: 

4. Execute the command below to check if the directory user for the local bin exists:

$ cd /usr/local/bin/

If nothing  exists, you can simply just make the directory by using command:

$ mkdir /usr/local/bin/

5. And once you are inside the directory, let’s execute the command to create the link: 

$ sudo ln -s ~/go/bin/golangci-lint /usr/local/bin/golangci-lint

Because we use the command “sudo” we need to enter the following administrator password

6. For the second command below, you don’t need to enter your password because the shell has already remembered it. 

$ sudo ln -s ~/go/bin/xgo /usr/local/bin/xgo

Copy the ZooBC Repo

  1. Next, open your visual studio code and let’s clone the repo by just copying and pasting this repo address below: 

$ https://github.com/zoobc/zoobc-core.git

Don’t forget to make sure to put the repository on the correct file directory or folder, and once you are finally able to open the code, the Visual Studio code will ask you to install Golang. Just click install, because this will be very helpful when we are coding the system.

2. Go back to the terminal, then  go inside the directory where we save our repository 

$ ~/go/src/zoobc/zoobc.core

Then, download the mod for the Go so that we can use all the functionalities from there:

$ go mod download

next, we also need to download the sub module from the repository 

$ git submodule update –init –recursive –remote

Once it’s done, it’s crucial to execute this command below:

$ go mod tidy

Compiling the ZooBC 

Let’s say we make some changes to the code and wants to compile it, what you need to do is go to the terminal and do a common “make test”

  1. Execute the command:

$ make test

Once the “make test” command works, you can execute the following command below

$ go build -o zoobc

Now, we use the “xgo” command to test for all the operating systems, so this command will compile for windows, darwin, Linux 

$ make VERSION=v1.10.1 core-common-os

2. There are 2 ways to compile the ZooBC; the first one is the core node and the second one is the  command utilities. To perform the second action, you need to input a distribution directory command. 

$ cd dist

Then, expand the view to see all the files inside using the command:

$ ls -alsh

And, as you can see, there are 3 folders inside, namely Darwin, Windows, linux. 

3. Now, go inside the Darwin folder 

$ cd darwin 

List the files inside:

$ ls -alsh

4. Then, let’s run and check the daemon status by using the following command:

$  sudo ./zoobc daemon status

And you can see that the services have yet to be installed. So, let’s go back by using the following command:

$  cd ../

5. Install the “make” version 

$   make VERSION=v1.10.1 cmd-common-os

And let’s test if the binary code is correct using the following command:

$   ./zcmd -h

And now that everything has been installed and ready, to summarize if next time you want to compile the system you need to 

  1. Make sure if docker is running
  2. Simple run the visual studio 

At this point, we are finished setting up the code and compiling the ZooBC.  You can also follow the step-by-step instruction through our YouTube Tutorial 10 – MacOS setup to code and compile ZooBC