Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs build readme #3930

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions docs/build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
## Overview

Prebid Server contains at least one module that requires CGo which introduces both build and runtime dependencies.
To build, you need a C compiler, preferably gcc.
To run, you may require one or more runtime dependencies, most notably libatomic.

## Examples (Build --> Target)
For a containerized example, see the Dockerfile.
Here are some manual build examples, including some cross-compilation use cases, that have been tested:

### darwin amd64 --> darwin amd64
`GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build`

Running the built binary on mac amd64:
`./prebid-server --stderrthreshold=WARNING -v=2`

### darwin amd64 --> darwin arm64
`GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build`

Running the built binary on mac arm64:
`./prebid-server --stderrthreshold=WARNING -v=2`

### darwin amd64 --> windows amd64
<b>Build (mac)</b>
Install mingw-w64 which consists of a gcc compiler port you can use to generate windows binaries:
`brew install mingw-w64`

`GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC="x86_64-w64-mingw32-gcc" go build`

<b>Run (windows)</b>
Running the built binary on windows:
`.\prebid-server.exe --sderrthreshold=WARNING =v=2`

You may receive the following errors or something similar:
```
"The code execution cannot proceed because libatomic-1.dll was not found."
"The code execution cannot proceed because libwinpthread-1.dll was not found."
```

To resolve these errors, copy the following files from mingw-64 on your mac to `C:/windows/System32` and re-run:
`/usr/local/Cellar/mingw-w64/12.0.0_1/toolchain-x86_64/x86_64-w64-mingw32/lib/libatomic-1.dll`
`/usr/local/Cellar/mingw-w64/12.0.0_1/toolchain-x86_64/x86_64-w64-mingw32/bin/libwinpthread-1.dll`

### windows amd64 --> windows amd64
<b>Build</b>
`set CGO_ENABLED=1`
`set GOOS=windows`
`set GOARCH=amd64`
`go build . && .\prebid-server.exe --stderrthreshold=WARNING -v=2`

You may receive the following error or something similar:
```
# runtime/cgo
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%
```

To resolve the error, install MSYS2:
1) Download the installer (https://www.msys2.org/)
2) Run the installer and follow the steps of the installation wizard
3) Run MSYS2 which will open an MSYS2 terminal for you
4) In the MSYS2 terminal, install windows/amd64 gcc toolchain: `pacman -S --needed base-devel mingw-w64-x86_64-gcc`
5) Enter `Y` when prompted whether to proceed with the installation
6) Add the path of your MinGW-w64 `bin` folder to the Windows `PATH` environment variable by using the following steps:
- In the Windows search bar, type <b>Settings</b> to open your Windows Settings.
- Search for <b>Edit environment variables for your account</b>.
- In your <b>User variables</b>, select the `Path` variable and then select <b>Edit</b>.
- Select </b>New and add the MinGW-w64 destination folder you recorded during the installation process to the list. If you used the default settings above, then this will be the path: `C:\msys64\ucrt64\bin`.
- Select <b>OK</b>, and then select <b>OK</b> again in the <b>Environment Variables</b> window to update the `PATH` environment variable. You have to reopen any console windows for the updated `PATH` environment variable to be available.
7) Confirm gcc installed: `gcc --version`

<b>Run</b>
Running the built binary on windows:
`go build . && .\prebid-server.exe --stderrthreshold=WARNING -v=2`

You may receive the following errors or something similar:
```
"The code execution cannot proceed because libatomic-1.dll was not found."
"The code execution cannot proceed because libwinpthread-1.dll was not found."
```
To resolve these errors, copy the following files from MSYS2 installation to `C:/windows/System32` and re-run:
`C:\mysys64\mingw64\bin\libatomic-1.dll`
`C:\mysys64\mingw64\bin\libwinpthread-1.dll`

### linux amd64 --> linux amd64
<b>Build</b>
`GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build`

You may receive the following error or something similar:
```
# runtime/cgo
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH
```
To resolve the error, install gcc and re-build:
`sudo apt-get install -y gcc`

<b>Run</b>
Running the built binary on Linux:
`./prebid-server --stderrthreshold=WARNING -v=2`

You may receive the following error or something similar:
```
... error while loading shared libraries: libatomic.so.1: cannot open shared object file ...
```
To resolve the error, install libatomic1 and re-run:
`sudo apt-get install -y libatomic1`
Loading