Skip to content

Commit

Permalink
Update docs and add building scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cfnptr committed Oct 12, 2024
1 parent cedcaf9 commit e6d3d58
Show file tree
Hide file tree
Showing 19 changed files with 687 additions and 26 deletions.
25 changes: 19 additions & 6 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

env:
BUILD_TYPE: Release
VCPKG_ROOT: C:/vcpkg
VCPKG_CACHE: Windows-openssl_3.3.2

jobs:
build:
Expand All @@ -18,17 +18,30 @@ jobs:
with:
submodules: true

- name: Install Ubuntu OpenSSL
- name: Set vcpkg environment variable
if: matrix.os == 'windows-latest'
shell: bash
run: echo "VCPKG_ROOT=$VCPKG_INSTALLATION_ROOT" >> $GITHUB_ENV

- name: Cache vcpkg packages
uses: actions/cache@v4
if: matrix.os == 'windows-latest'
id: vcpkg-cache
with:
path: C:/vcpkg/installed
key: ${{env.VCPKG_CACHE}}

- name: Install Ubuntu packages
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install libssl-dev

- name: Install macOS OpenSSL
- name: Install macOS packages
if: matrix.os == 'macos-latest'
run: brew update && brew install openssl

- name: Install Windows OpenSSL
if: matrix.os == 'windows-latest'
run: vcpkg install openssl
- name: Install Windows packages
if: ${{matrix.os == 'windows-latest' && steps.vcpkg-cache.outputs.cache-hit != 'true'}}
run: vcpkg install openssl:x64-windows-static

- name: Create build environment
run: cmake -E make_directory ${{runner.workspace}}/build
Expand Down
102 changes: 102 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Build instructions

## Operating Systems

* [Window (10/11)](BUILDING.md#windows-1011)
* [Ubuntu (22.04/24.04)](BUILDING.md#ubuntu-22042404)
* [macOS (14/15)](BUILDING.md#macos-1415)
* [Build Project](BUILDING.md#build-project)


# Windows (10/11)

## 1. Install Visual Studio Community (Or any other IDE)

1. Download latest version from [visualstudio.microsoft.com](https://visualstudio.microsoft.com/downloads)
2. Launch downloaded Visual Studio installer
3. Select "Desktop development with C++" before installation
4. Add "C++ Clang tools for Windows" inside **Installation details** (optional)
5. Unselect "vcpkg package manager" inside **Installation details** we will use our own
6. Finally click **Install** button to begin installation

## 2. Install Git

* Download and install latest version from [git-cms.com](https://git-scm.com/downloads)

You may use default Git install options or chose any other default Git editor instead of **Vim**.

## 3. Install CMake

1. Download latest release version of installer from [cmake.org](https://cmake.org/download)
2. Select "Add CMake to the system PATH for the current user" during installation

## 5. Clone Repository

1. Open **Terminal** or **CMD** app to execute following commands
2. Change current working directory using ```cd``` command where to clone repository. (Google it)
3. Run ```git clone --recursive https://github.com/cfnptr/nets``` command to download repository
4. Run ```cd nets/``` to enter repository directory

Note! Use appropriate github link if Nets is used as a third-party library.

## 6. Install vcpkg package manager

1. Open **CMD** or **Terminal** app as Administrator. (Right click the app)
2. Run ```scripts/update-vcpkg.bat``` command from the repository *scripts/* directory

Or

1. Follow installation steps from [learn.microsoft.com](https://learn.microsoft.com/en-us/vcpkg/get_started/get-started) (Better to choose C:\vcpkg path)
2. Run ```vcpkg integrate install``` command using **Terminal** or **CMD** app to make packages available user-wide
3. Add **vcpkg** to the System Environment Variables. (Google it)

## 6. Install required packages

1. Run ```vcpkg install openssl:x64-windows-static``` using **Terminal** or **CMD** app


# Ubuntu (22.04/24.04)

## 1. Install Visual Studio Code (Or any other IDE)

1. Download and install latest version from [code.visualstudio.com](https://code.visualstudio.com/download)
2. Install "C/C++" And "CMake Tools" extensions inside **Visual Studio Code**

## 2. Install required packages

1. Run ```sudo apt-get update``` command using **Terminal** app
2. And ```sudo apt-get install git gcc g++ cmake libssl-dev```


# macOS (14/15)

## 1. Install Xcode (Or any other IDE)

1. Download and install latest version from **App Store** app
2. Run ```xcode-select --install``` command using **Terminal** app to install Xcode tools

## 2. Install required packages

1. Install **Homebrew** package manager from [brew.sh](https://brew.sh)
2. Run ```brew update``` command using **Terminal** app
3. And ```brew install git cmake openssl```


# Build Project

To build the project run one of the [scripts](scripts/) using **Terminal**, **Git Bash** or build it using **IDE**.

## Visual Studio (2022)

1. Open **Visual Studio 2022** IDE
2. Click "Open a local folder" and open the repository folder
3. Click **Build -> Build All** to build the project

## Visual Studio Code (VS Code)

1. Open **Visual Studio Code** IDE
2. Install "C/C++" And "CMake Tools" extensions
3. Click **File -> Open Folder...** and open the repository folder
4. Click **Yes** in "Would you like to configure project..."
5. Select one of the compiler **Kits** in the opened window
6. Click **Build** button at the bottom bar to build the project
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NETS ![CI](https://github.com/cfnptr/nets/actions/workflows/cmake.yml/badge.svg)
# Nets

A library providing generic interface for transferring data over a **network** across different platforms.

Expand All @@ -13,9 +13,12 @@ A library providing generic interface for transferring data over a **network** a

## Supported operating systems

* Ubuntu
* MacOS
* Windows
* Windows (10/11)
* Ubuntu (22.04/24.04)
* macOS (14/15)

This list includes only those systems on which functionality testing is conducted.
However, you can also compile it under any other Linux distribution or operating system.

## Build requirements

Expand All @@ -25,11 +28,7 @@ A library providing generic interface for transferring data over a **network** a
* [vcpkg](https://learn.microsoft.com/en-us/vcpkg/) (Windows only)
* [brew](https://brew.sh/) (macOS only)

### OpenSSL installation

* Ubuntu: sudo apt-get install libssl-dev
* macOS: brew install openssl
* Windows: vcpkg install openssl
Use building [instructions](BUILDING.md) to install all required tools and libraries.

### CMake options

Expand All @@ -46,10 +45,10 @@ A library providing generic interface for transferring data over a **network** a
git clone --recursive https://github.com/cfnptr/nets
```

## Usage examples
## Building ![CI](https://github.com/cfnptr/nets/actions/workflows/cmake.yml/badge.svg)

Datagram client / server example: [examples/datagram_example.c](https://github.com/cfnptr/nets/blob/main/examples/datagram_example.c)<br/>
HTTPS client (OpenSSL) example: [examples/https_example.c](https://github.com/cfnptr/nets/blob/main/examples/https_example.c)
* Windows: ```./scripts/build-release.bat```
* macOS / Ubuntu: ```./scripts/build-release.sh```

## Third-party

Expand Down
30 changes: 30 additions & 0 deletions scripts/build-debug-clang.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@ECHO OFF
CD /D "%~dp0"

cmake --version > nul

IF NOT %ERRORLEVEL% == 0 (
ECHO Failed to get CMake version, please check if it's installed.
EXIT /B %ERRORLEVEL%
)

ECHO Configuring project...

cmake -DCMAKE_BUILD_TYPE=Debug -T ClangCL -A x64 -S ../ -B ../build-debug-clang/

IF NOT %ERRORLEVEL% == 0 (
ECHO Failed to configure CMake project.
EXIT /B %ERRORLEVEL%
)

ECHO(
ECHO Building project...

cmake --build ../build-debug-clang/ --config Debug --parallel

IF NOT %ERRORLEVEL% == 0 (
ECHO Failed to build CMake project.
EXIT /B %ERRORLEVEL%
)

EXIT /B 0
53 changes: 53 additions & 0 deletions scripts/build-debug-clang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
cd "$(dirname "$BASH_SOURCE")"

cmake --version > /dev/null
status=$?

if [ $status -ne 0 ]; then
echo "Failed to get CMake version, please check if it's installed."
exit $status
fi

echo "Configuring project..."

if [[ "$OSTYPE" == "msys" ]]; then
cmake -DCMAKE_BUILD_TYPE=Debug -T ClangCL -A x64 -S ../ -B ../build-debug-clang/
elif [[ "$OSTYPE" == "darwin"* ]]; then
cmake -DCMAKE_BUILD_TYPE=Debug -S ../ -B ../build-debug-clang/
else
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -S ../ -B ../build-debug-clang/
fi

status=$?

if [ $status -ne 0 ]; then
echo "Failed to configure CMake project."
exit $status
fi

echo ""
echo "Building project..."

cmake --build ../build-debug-clang/ --config Debug --parallel
status=$?

if [ $status -ne 0 ]; then
echo "Failed to build CMake project."
exit $status
fi

if [[ "$OSTYPE" == "darwin"* ]]; then
echo ""
echo "Fixing up macOS bundle..."

cmake --install ../build-debug-clang/ --component FixupBundle
status=$?

if [ $status -ne 0 ]; then
echo "Failed to fix up macOS bundle."
exit $status
fi
fi

exit 0
30 changes: 30 additions & 0 deletions scripts/build-debug.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@ECHO OFF
CD /D "%~dp0"

cmake --version > nul

IF NOT %ERRORLEVEL% == 0 (
ECHO Failed to get CMake version, please check if it's installed.
EXIT /B %ERRORLEVEL%
)

ECHO Configuring project...

cmake -DCMAKE_BUILD_TYPE=Debug -S ../ -B ../build-debug/

IF NOT %ERRORLEVEL% == 0 (
ECHO Failed to configure CMake project.
EXIT /B %ERRORLEVEL%
)

ECHO(
ECHO Building project...

cmake --build ../build-debug/ --config Debug --parallel

IF NOT %ERRORLEVEL% == 0 (
ECHO Failed to build CMake project.
EXIT /B %ERRORLEVEL%
)

EXIT /B 0
46 changes: 46 additions & 0 deletions scripts/build-debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
cd "$(dirname "$BASH_SOURCE")"

cmake --version > /dev/null
status=$?

if [ $status -ne 0 ]; then
echo "Failed to get CMake version, please check if it's installed."
exit $status
fi

echo "Configuring project..."

cmake -DCMAKE_BUILD_TYPE=Debug -S ../ -B ../build-debug/
status=$?

if [ $status -ne 0 ]; then
echo "Failed to configure CMake project."
exit $status
fi

echo ""
echo "Building project..."

cmake --build ../build-debug/ --config Debug --parallel
status=$?

if [ $status -ne 0 ]; then
echo "Failed to build CMake project."
exit $status
fi

if [[ "$OSTYPE" == "darwin"* ]]; then
echo ""
echo "Fixing up macOS bundle..."

cmake --install ../build-debug/ --component FixupBundle
status=$?

if [ $status -ne 0 ]; then
echo "Failed to fix up macOS bundle."
exit $status
fi
fi

exit 0
30 changes: 30 additions & 0 deletions scripts/build-release-clang.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@ECHO OFF
CD /D "%~dp0"

cmake --version > nul

IF NOT %ERRORLEVEL% == 0 (
ECHO Failed to get CMake version, please check if it's installed.
EXIT /B %ERRORLEVEL%
)

ECHO Configuring project...

cmake -DCMAKE_BUILD_TYPE=Release -T ClangCL -A x64 -S ../ -B ../build-release-clang/

IF NOT %ERRORLEVEL% == 0 (
ECHO Failed to configure CMake project.
EXIT /B %ERRORLEVEL%
)

ECHO(
ECHO Building project...

cmake --build ../build-release-clang/ --config Release --parallel

IF NOT %ERRORLEVEL% == 0 (
ECHO Failed to build CMake project.
EXIT /B %ERRORLEVEL%
)

EXIT /B 0
Loading

0 comments on commit e6d3d58

Please sign in to comment.