Skip to content
This repository was archived by the owner on Aug 9, 2025. It is now read-only.

Building

tbeck edited this page Sep 17, 2023 · 1 revision

Learn how to compile the go-module and it's components


Requirements

There are prerequisites for building the module. You can find them here.

Build from source

Make sure you have installed all requirements.

At first clone this repository:

git clone --recurse-submodules https://github.com/timo972/altv-go.git

Either follow the automatic build (make) or the manuall build guides.

Automatic build

requires make

To build the runtime and the c-api run the following command:

make

More infos on outputs below

Manuall build

If you do not have make installed, you can run the following commands manually:

To build the runtime:

./scripts/build-runtime.sh

You can find the built runtime library in the folder ./runtime/bin/libruntime.so (linux) or ./runtime/bin/Release/go-module.dll (windows). See how to use your local build for more information.

To build the c-api:

./scripts/build-capi.sh

You can find the built c-api library in the folder ./internal/c-api/lib/linux/libcapi.a (linux) or ./internal/c-api/lib/win32/libcapi.a (windows). However usually you do not need to touch the built c-api library.

Check / Test capi go api

Run go tests:

go test -v

If this command succeeds everything is compatible and built correctly and you can start using your local version of altv-go.

Using your local altv-go api

To use your local version of the altv-go package, you need to add the following line to the go.mod file of your resource:

replace github.com/timo972/altv-go => ../relative/path/to/your/altv-go

This tells go to use the local version of the package instead of the one hosted on github.

Build the runtime (detailed)

Building the runtime is as easy as running the following command:

cd ./runtime
# create build and output folder
mkdir build
mkdir bin

cd build

# start build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ ..
cmake --build . --config Release

See more about runtime build here.

Build the c-api (detailed)

Building the c-api constists of two parts:

  • Generation of the c-api header & source file
  • Actual build of the c-api using cmake

Generation of the c-api header & source file

Generate the c-api header & source files using cmd/gencapi:

go run cmd/gencapi/*.go -cout=./internal/c-api/build/out/capi.c -hout=./internal/c-api/build/out/capi.h -hout=./internal/c-api/lib/capi.h  ./runtime/src/capi

Build the c-api shared library

This will generate the c-api header & source file in the folder ./internal/c-api/build/out/ and copy the header file to ./internal/c-api/lib/capi.h.

Build the c-api using cmake:

cd ./internal/c-api
# create build and output folder
mkdir build
mkdir bin

cd build

# start build
cmake ..
cmake --build .

See how to test the build below.

Checking the build

To check if the build was successful, you can run the following command:
go test -v
This will run all tests in the root go package and errors in case the capi is not built correctly or incompatible with the go api.

Clone this wiki locally