Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Release 1.0.2

See merge request ii887522/nitro!37
  • Loading branch information
ii887522 committed Jan 12, 2021
2 parents 5d757f4 + 8c758c3 commit 1a3bbb6
Show file tree
Hide file tree
Showing 38 changed files with 1,238 additions and 1,203 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 2
trim_trailing_whitespace = true
30 changes: 15 additions & 15 deletions .github/workflows/lockdown.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: 'Repo Lockdown'

on:
issues:
types: opened
pull_request:
types: opened
issues:
types: opened
pull_request:
types: opened

jobs:
lockdown:
runs-on: ubuntu-latest
steps:
- uses: dessant/repo-lockdown@v2.0.0
with:
github-token: ${{ github.token }}
issue-labels: 'off-topic'
issue-comment: 'This repository does not accept issues, see the README for more details.'
skip-closed-issue-comment: true
pr-comment: 'This repository does not accept pull requests, see the README for more details.'
skip-closed-pr-comment: true
lockdown:
runs-on: ubuntu-latest
steps:
- uses: dessant/repo-lockdown@v2.0.0
with:
github-token: ${{ github.token }}
issue-labels: 'off-topic'
issue-comment: 'This repository does not accept issues, see the README for more details.'
skip-closed-issue-comment: true
pr-comment: 'This repository does not accept pull requests, see the README for more details.'
skip-closed-pr-comment: true
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cpplint.cpplintPath": "",
"cpplint.lintMode": "workspace",
"cpplint.lineLength": 256
}
56 changes: 34 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,60 @@ It is a general purpose C++ library that can help developers create various kind
- [Build custom-node docker image](https://gitlab.com/ii887522/nitro#build-custom-node-docker-image)
- [Build ms-build-tools docker image](https://gitlab.com/ii887522/nitro#build-ms-build-tools-docker-image)
- [Install dependencies](https://gitlab.com/ii887522/nitro#install-dependencies)
- [Set correct cpplint executable path in .vscode/settings.json](https://gitlab.com/ii887522/nitro#set-correct-cpplint-executable-path-in-vscode/settings-json)
- [Build project](https://gitlab.com/ii887522/nitro#build-project)
- [Deploy project](https://gitlab.com/ii887522/nitro#deploy-project)

## For developers reading this in GitHub
Please go to https://gitlab.com/ii887522/nitro to start contributing instead.

## Prerequisites
- [Docker Desktop](https://www.docker.com/products/docker-desktop) using Windows containers
- [Visual Studio Code](https://code.visualstudio.com/)
- Docker
- EditorConfig for VS Code
- Markdown All in One
- Remote - WSL
- C/C++
- cpplint
- Docker
- EditorConfig for VS Code
- Markdown All in One
- Remote - WSL
- YAML
- [Visual Studio Community 2019](https://visualstudio.microsoft.com/) and later
- Extensions:
- Markdown Editor
- EditorConfig Language Service
- Workloads:
- Desktop development with C++
- Individual components:
- JavaScript and TypeScript language support
- Git for Windows
- Extensions:
- Markdown Editor
- EditorConfig Language Service
- Workloads:
- Desktop development with C++
- Individual components:
- JavaScript and TypeScript language support
- Git for Windows
- [Python 3.9.1](https://www.python.org/downloads/) and later

## Update .NET Framework SDK version used by ms-build-tools to match your OS
1. Left click on the start button at the bottom left corner of your desktop.

<img src="docs/start-button.png" alt="Start button" width="770" /><br /><br />
<img src="docs/start-button.png" alt="Start button" width="770" /><br /><br />

2. Left click on the settings button at the left side of the start menu.

<img src="docs/settings.png" alt="Settings" width="770" /><br /><br />
<img src="docs/settings.png" alt="Settings" width="770" /><br /><br />

3. Left click on the system button at the top left corner of settings window.

<img src="docs/system.png" alt="System" width="770" /><br /><br />
<img src="docs/system.png" alt="System" width="770" /><br /><br />

4. Left click on the about button at the bottom left corner of settings window.

<img src="docs/about.png" alt="About" width="770" /><br /><br />
<img src="docs/about.png" alt="About" width="770" /><br /><br />

5. Take note of the version shown in the settings window. You will need it to search for appropriate tags later.

<img src="docs/version.png" alt="Version" width="770" /><br /><br />
<img src="docs/version.png" alt="Version" width="770" /><br /><br />

6. Go to https://hub.docker.com/_/microsoft-dotnet-framework-sdk/ and find Full Tag Listing section.
7. Copy a tag that contains the version you have taken note of under Full Tag Listing section.
6. Go to https://hub.docker.com/_/microsoft-dotnet-framework-sdk/ and find the Full Tag Listing section.
7. Copy a tag that contains the version you have taken note of under the Full Tag Listing section.
8. Finally, inside the repository, navigate to `ms-build-tools/Dockerfile`. Then, paste to replace the tag as highlighted and shown in the screenshot below and save it.

<img src="docs/tag.png" alt="Tag" width="770" /><br /><br />
<img src="docs/tag.png" alt="Tag" width="770" /><br /><br />

## Build custom-node docker image
```sh
Expand All @@ -76,12 +82,18 @@ cd ..
install
```

### Build project
## Set correct cpplint executable path in `.vscode/settings.json`
1. In the explorer panel of Visual Studio Code, navigate to `env\Scripts\` or `env/bin/` in the project directory and find the cpplint executable.
2. Right click on the cpplint executable and click on Copy Path to copy its absolute path.
3. In the explorer panel of Visual Studio Code, navigate to `.vscode/settings.json` in the project directory and open it.
4. Finally, paste the absolute path as a string value of `"cpplint.cpplintPath"` in `settings.json` and save it.

## Build project
```sh
build
```

### Deploy project
## Deploy project
```sh
deploy <access-token>
```
5 changes: 1 addition & 4 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
docker run --rm --name nitro_debug_x86_builder -w C:\nitro -v %CD%:C:\nitro ms-build-tools msbuild C:\nitro\nitro\nitro.sln /p:Configuration=Debug /p:Platform=x86
docker run --rm --name nitro_debug_x64_builder -w C:\nitro -v %CD%:C:\nitro ms-build-tools msbuild C:\nitro\nitro\nitro.sln /p:Configuration=Debug /p:Platform=x64
docker run --rm --name nitro_release_x86_builder -w C:\nitro -v %CD%:C:\nitro ms-build-tools msbuild C:\nitro\nitro\nitro.sln /p:Configuration=Release /p:Platform=x86
docker run --rm --name nitro_release_x64_builder -w C:\nitro -v %CD%:C:\nitro ms-build-tools msbuild C:\nitro\nitro\nitro.sln /p:Configuration=Release /p:Platform=x64
env\Scripts\activate && cpplint --recursive --linelength=256 nitro\src\ && env\Scripts\deactivate && docker run --rm --name nitro_debug_x86_builder -w C:\nitro -v %CD%:C:\nitro ms-build-tools msbuild C:\nitro\nitro\nitro.sln /p:Configuration=Debug /p:Platform=x86 && docker run --rm --name nitro_debug_x64_builder -w C:\nitro -v %CD%:C:\nitro ms-build-tools msbuild C:\nitro\nitro\nitro.sln /p:Configuration=Debug /p:Platform=x64 && docker run --rm --name nitro_release_x86_builder -w C:\nitro -v %CD%:C:\nitro ms-build-tools msbuild C:\nitro\nitro\nitro.sln /p:Configuration=Release /p:Platform=x86 && docker run --rm --name nitro_release_x64_builder -w C:\nitro -v %CD%:C:\nitro ms-build-tools msbuild C:\nitro\nitro\nitro.sln /p:Configuration=Release /p:Platform=x64
5 changes: 1 addition & 4 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
docker run --rm --name nitro_debug_x86_builder -w C:/nitro -v $PWD:C:/nitro ms-build-tools msbuild C:/nitro/nitro/nitro.sln /p:Configuration=Debug /p:Platform=x86
docker run --rm --name nitro_debug_x64_builder -w C:/nitro -v $PWD:C:/nitro ms-build-tools msbuild C:/nitro/nitro/nitro.sln /p:Configuration=Debug /p:Platform=x64
docker run --rm --name nitro_release_x86_builder -w C:/nitro -v $PWD:C:/nitro ms-build-tools msbuild C:/nitro/nitro/nitro.sln /p:Configuration=Release /p:Platform=x86
docker run --rm --name nitro_release_x64_builder -w C:/nitro -v $PWD:C:/nitro ms-build-tools msbuild C:/nitro/nitro/nitro.sln /p:Configuration=Release /p:Platform=x64
source env/bin/activate && cpplint --recursive --linelength=256 nitro/src/ && source env/bin/deactivate && docker run --rm --name nitro_debug_x86_builder -w C:/nitro -v $PWD:C:/nitro ms-build-tools msbuild C:/nitro/nitro/nitro.sln /p:Configuration=Debug /p:Platform=x86 && docker run --rm --name nitro_debug_x64_builder -w C:/nitro -v $PWD:C:/nitro ms-build-tools msbuild C:/nitro/nitro/nitro.sln /p:Configuration=Debug /p:Platform=x64 && docker run --rm --name nitro_release_x86_builder -w C:/nitro -v $PWD:C:/nitro ms-build-tools msbuild C:/nitro/nitro/nitro.sln /p:Configuration=Release /p:Platform=x86 && docker run --rm --name nitro_release_x64_builder -w C:/nitro -v $PWD:C:/nitro ms-build-tools msbuild C:/nitro/nitro/nitro.sln /p:Configuration=Release /p:Platform=x64
6 changes: 3 additions & 3 deletions deploy.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docker run --rm --name nitro_bundler -w C:\nitro -v %CD%:C:\nitro mcr.microsoft.com/windows/servercore:20H2 cmd /c "mkdir libs && cd libs && mkdir nitro-1.0.1 && cd nitro-1.0.1 && mkdir include && cd include && xcopy ..\..\..\nitro\src\main\ .\ /s && cd .. && mkdir lib && cd lib && mkdir x86 && cd x86 && mkdir Debug && cd Debug && copy ..\..\..\..\..\nitro\Debug\nitro.lib .\ && cd .. && mkdir Release && cd Release && copy ..\..\..\..\..\nitro\Release\nitro.lib .\ && cd .. && cd .. && mkdir x64 && cd x64 && mkdir Debug && cd Debug && copy ..\..\..\..\..\nitro\x64\Debug\nitro.lib .\ && cd .. && mkdir Release && cd Release && copy ..\..\..\..\..\nitro\x64\Release\nitro.lib .\ && cd .. && cd .. && cd .. && cd .. && cd .."
docker run --rm --name nitro_zipper -w C:\nitro\libs -v %CD%\libs:C:\nitro\libs kiazhi/nanoserver.7-zip:1709-18.05 7z a nitro-1.0.1.zip nitro-1.0.1\
docker run --rm --name nitro_publisher -v %CD%\libs:C:\nitro\libs stefanscherer/curl-windows:7.58.0 --header "PRIVATE-TOKEN: %1" --upload-file C:\nitro\libs\nitro-1.0.1.zip https://gitlab.com/api/v4/projects/23530641/packages/generic/nitro/1.0.1/nitro-1.0.1.zip
docker run --rm --name nitro_bundler -w C:\nitro -v %CD%:C:\nitro mcr.microsoft.com/windows/servercore:20H2 cmd /c "mkdir libs && cd libs && mkdir nitro-1.0.2 && cd nitro-1.0.2 && mkdir include && cd include && xcopy ..\..\..\nitro\src\main\ .\ /s && cd .. && mkdir lib && cd lib && mkdir x86 && cd x86 && mkdir Debug && cd Debug && copy ..\..\..\..\..\nitro\Debug\nitro.lib .\ && cd .. && mkdir Release && cd Release && copy ..\..\..\..\..\nitro\Release\nitro.lib .\ && cd .. && cd .. && mkdir x64 && cd x64 && mkdir Debug && cd Debug && copy ..\..\..\..\..\nitro\x64\Debug\nitro.lib .\ && cd .. && mkdir Release && cd Release && copy ..\..\..\..\..\nitro\x64\Release\nitro.lib .\ && cd .. && cd .. && cd .. && cd .. && cd .."
docker run --rm --name nitro_zipper -w C:\nitro\libs -v %CD%\libs:C:\nitro\libs kiazhi/nanoserver.7-zip:1709-18.05 7z a nitro-1.0.2.zip nitro-1.0.2\
docker run --rm --name nitro_publisher -v %CD%\libs:C:\nitro\libs stefanscherer/curl-windows:7.58.0 --header "PRIVATE-TOKEN: %1" --upload-file C:\nitro\libs\nitro-1.0.2.zip https://gitlab.com/api/v4/projects/23530641/packages/generic/nitro/1.0.2/nitro-1.0.2.zip
docker run --rm --name nitro_cleaner -w C:\nitro -v %CD%:C:\nitro mcr.microsoft.com/windows/servercore:20H2 cmd /c "rmdir libs /s /q"
6 changes: 3 additions & 3 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docker run --rm --name nitro_bundler -w C:/nitro -v $PWD:C:/nitro mcr.microsoft.com/windows/servercore:20H2 cmd /c "mkdir libs && cd libs && mkdir nitro-1.0.1 && cd nitro-1.0.1 && mkdir include && cd include && xcopy ..\..\..\nitro\src\main\ .\ /s && cd .. && mkdir lib && cd lib && mkdir x86 && cd x86 && mkdir Debug && cd Debug && copy ..\..\..\..\..\nitro\Debug\nitro.lib .\ && cd .. && mkdir Release && cd Release && copy ..\..\..\..\..\nitro\Release\nitro.lib .\ && cd .. && cd .. && mkdir x64 && cd x64 && mkdir Debug && cd Debug && copy ..\..\..\..\..\nitro\x64\Debug\nitro.lib .\ && cd .. && mkdir Release && cd Release && copy ..\..\..\..\..\nitro\x64\Release\nitro.lib .\ && cd .. && cd .. && cd .. && cd .. && cd .."
docker run --rm --name nitro_zipper -w C:/nitro/libs -v $PWD/libs:C:/nitro/libs kiazhi/nanoserver.7-zip:1709-18.05 7z a nitro-1.0.1.zip nitro-1.0.1\
docker run --rm --name nitro_publisher -v $PWD/libs:C:/nitro/libs stefanscherer/curl-windows:7.58.0 --header "PRIVATE-TOKEN: %1" --upload-file C:\nitro\libs\nitro-1.0.1.zip https://gitlab.com/api/v4/projects/23530641/packages/generic/nitro/1.0.1/nitro-1.0.1.zip
docker run --rm --name nitro_bundler -w C:/nitro -v $PWD:C:/nitro mcr.microsoft.com/windows/servercore:20H2 cmd /c "mkdir libs && cd libs && mkdir nitro-1.0.2 && cd nitro-1.0.2 && mkdir include && cd include && xcopy ..\..\..\nitro\src\main\ .\ /s && cd .. && mkdir lib && cd lib && mkdir x86 && cd x86 && mkdir Debug && cd Debug && copy ..\..\..\..\..\nitro\Debug\nitro.lib .\ && cd .. && mkdir Release && cd Release && copy ..\..\..\..\..\nitro\Release\nitro.lib .\ && cd .. && cd .. && mkdir x64 && cd x64 && mkdir Debug && cd Debug && copy ..\..\..\..\..\nitro\x64\Debug\nitro.lib .\ && cd .. && mkdir Release && cd Release && copy ..\..\..\..\..\nitro\x64\Release\nitro.lib .\ && cd .. && cd .. && cd .. && cd .. && cd .."
docker run --rm --name nitro_zipper -w C:/nitro/libs -v $PWD/libs:C:/nitro/libs kiazhi/nanoserver.7-zip:1709-18.05 7z a nitro-1.0.2.zip nitro-1.0.2\
docker run --rm --name nitro_publisher -v $PWD/libs:C:/nitro/libs stefanscherer/curl-windows:7.58.0 --header "PRIVATE-TOKEN: $1" --upload-file C:\nitro\libs\nitro-1.0.2.zip https://gitlab.com/api/v4/projects/23530641/packages/generic/nitro/1.0.2/nitro-1.0.2.zip
docker run --rm --name nitro_cleaner -w C:/nitro -v $PWD:C:/nitro mcr.microsoft.com/windows/servercore:20H2 cmd /c "rmdir libs /s /q"
4 changes: 3 additions & 1 deletion install.cmd
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
docker run --rm --name nitro_installer -w C:\nitro -v %CD%:C:\nitro nitro-custom-node ncu.cmd -u && npm.cmd install
python -m pip install virtualenv
virtualenv env
env\Scripts\activate && python -m pip install cpplint && env\Scripts\deactivate && docker run --rm --name nitro_installer -w C:\nitro -v %CD%:C:\nitro nitro-custom-node ncu.cmd -u && npm.cmd install
4 changes: 3 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
docker run --rm --name nitro_installer -w C:/nitro -v $PWD:C:/nitro nitro-custom-node ncu.cmd -u && npm.cmd install
python -m pip install virtualenv
virtualenv env
source env/bin/activate && python -m pip install cpplint && source env/bin/deactivate && docker run --rm --name nitro_installer -w C:/nitro -v $PWD:C:/nitro nitro-custom-node ncu.cmd -u && npm.cmd install
12 changes: 6 additions & 6 deletions ms-build-tools/Install.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ setlocal enabledelayedexpansion

call %*
if "%ERRORLEVEL%"=="3010" (
exit /b 0
exit /b 0
) else (
if not "%ERRORLEVEL%"=="0" (
set ERR=%ERRORLEVEL%
call C:\TEMP\collect.exe -zip:C:\vslogs.zip
if not "%ERRORLEVEL%"=="0" (
set ERR=%ERRORLEVEL%
call C:\TEMP\collect.exe -zip:C:\vslogs.zip

exit /b !ERR!
)
exit /b !ERR!
)
)
119 changes: 57 additions & 62 deletions nitro/src/main/Allocator/linear_allocator.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Copyright ii887522

#ifdef LINEAR_ALLOCATOR

#ifndef II887522_NITRO_LINEAR_ALLOCATOR_H
#define II887522_NITRO_LINEAR_ALLOCATOR_H
#ifndef NITRO_SRC_MAIN_ALLOCATOR_LINEAR_ALLOCATOR_H_
#define NITRO_SRC_MAIN_ALLOCATOR_LINEAR_ALLOCATOR_H_

#include "../Functions/math_ext.h"
#include <new>
#include <algorithm>
#include "../Functions/math_ext.h"

using ii887522::nitro::min;
using std::bad_alloc;
Expand All @@ -15,89 +18,81 @@ using std::bad_alloc;
using std::cout;
#endif

namespace ii887522::nitro
{
enum class Term : unsigned int
{
LONG, SHORT
};
namespace ii887522::nitro {

static char longTermData[LONG_TERM_ALLOCATOR_SIZE];
static size_t longTermDataSize{ 0u };
enum class Term : unsigned int {
LONG, SHORT
};

static char longTermData[LONG_TERM_ALLOCATOR_SIZE];
static size_t longTermDataSize{ 0u };
#ifdef SHORT_TERM_ALLOCATOR_SIZE
static char shortTermData[SHORT_TERM_ALLOCATOR_SIZE];
static size_t shortTermDataSize{ 0u };
static char shortTermData[SHORT_TERM_ALLOCATOR_SIZE];
static size_t shortTermDataSize{ 0u };
#endif
static Term term{ Term::LONG };

constexpr static size_t getAlignedDataSize(const size_t dataSize, const size_t size)
{
const auto alignmentRequirement{ min(size, alignof(max_align_t)) };
return (dataSize / alignmentRequirement + 1u) * alignmentRequirement;
}

// Not Thread Safe
static void* longTermAlloc(const size_t size)
{
longTermDataSize = getAlignedDataSize(longTermDataSize, size);
const auto result{ longTermData + longTermDataSize };
longTermDataSize += size;
static Term term{ Term::LONG };

constexpr static size_t getAlignedDataSize(const size_t dataSize, const size_t size) {
const auto alignmentRequirement{ min(size, alignof(max_align_t)) };
return (dataSize / alignmentRequirement + 1u) * alignmentRequirement;
}

// Not Thread Safe
static void* longTermAlloc(const size_t size) {
longTermDataSize = getAlignedDataSize(longTermDataSize, size);
const auto result{ longTermData + longTermDataSize };
longTermDataSize += size;
#ifdef _DEBUG
cout << "Long term data usage: " << longTermDataSize << " bytes\n";
cout << "Long term data usage: " << longTermDataSize << " bytes\n";
#endif
return result;
}

return result;
}

// Not Thread Safe
static void* shortTermAlloc(const size_t size)
{
// Not Thread Safe
static void* shortTermAlloc(const size_t size) {
#ifdef SHORT_TERM_ALLOCATOR_SIZE
shortTermDataSize = getAlignedDataSize(shortTermDataSize, size);
const auto result{ shortTermData + shortTermDataSize };
shortTermDataSize += size;
shortTermDataSize = getAlignedDataSize(shortTermDataSize, size);
const auto result{ shortTermData + shortTermDataSize };
shortTermDataSize += size;
#ifdef _DEBUG
cout << "Short term data usage: " << shortTermDataSize << " bytes\n";
cout << "Short term data usage: " << shortTermDataSize << " bytes\n";
#endif
return result;
return result;
#else
size;
return nullptr;
size;
return nullptr;
#endif
}
}

#ifdef SHORT_TERM_ALLOCATOR_SIZE
constexpr void beginShortTermAlloc()
{
term = Term::SHORT;
}

constexpr void endShortTermAlloc()
{
shortTermDataSize = 0u;
term = Term::LONG;
}
#endif
constexpr void beginShortTermAlloc() {
term = Term::SHORT;
}

constexpr void endShortTermAlloc() {
shortTermDataSize = 0u;
term = Term::LONG;
}
#endif

} // namespace ii887522::nitro

using ii887522::nitro::Term;
using ii887522::nitro::term;
using ii887522::nitro::longTermAlloc;
using ii887522::nitro::shortTermAlloc;

// Not Thread Safe
void* operator new(const size_t size)
{
switch (term)
{
case Term::LONG: return longTermAlloc(size);
case Term::SHORT: return shortTermAlloc(size);
}
throw bad_alloc{ };
void* operator new(const size_t size) {
switch (term) {
case Term::LONG: return longTermAlloc(size);
case Term::SHORT: return shortTermAlloc(size);
}
throw bad_alloc{ };
}

// Not Thread Safe
void operator delete(void*const) { }

#endif
#endif
#endif // NITRO_SRC_MAIN_ALLOCATOR_LINEAR_ALLOCATOR_H_
Loading

0 comments on commit 1a3bbb6

Please sign in to comment.