Skip to content

Commit d4f78ee

Browse files
committed
feat: initial commit
0 parents  commit d4f78ee

13 files changed

Lines changed: 1201 additions & 0 deletions

File tree

.github/.licenserc.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
header:
2+
license:
3+
content:
4+
|
5+
# SPDX-License-Identifier: Apache-2.0 OR MIT
6+
# Copyright (c) Status Research & Development GmbH
7+
paths:
8+
- "**/*.nim"
9+
paths-ignore:
10+
- "**/lsquic_ffi.nim"
11+
- "prelude.nim"
12+
comment: on-failure

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @vacp2p/p2p
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Install Nim
2+
inputs:
3+
os:
4+
description: "Operating system to build for"
5+
required: true
6+
cpu:
7+
description: "CPU to build for"
8+
default: "amd64"
9+
nim_ref:
10+
description: "Nim version"
11+
default: "version-1-6"
12+
shell:
13+
description: "Shell to run commands in"
14+
default: "bash --noprofile --norc -e -o pipefail"
15+
16+
runs:
17+
using: "composite"
18+
steps:
19+
- name: Install build dependencies (Linux i386)
20+
shell: ${{ inputs.shell }}
21+
if: inputs.os == 'Linux' && inputs.cpu == 'i386'
22+
run: |
23+
sudo dpkg --add-architecture i386
24+
sudo apt-get update -qq
25+
sudo DEBIAN_FRONTEND='noninteractive' apt-get install \
26+
--no-install-recommends -yq gcc-multilib g++-multilib \
27+
libssl-dev:i386
28+
mkdir -p external/bin
29+
cat << EOF > external/bin/gcc
30+
#!/bin/bash
31+
exec $(which gcc) -m32 "\$@"
32+
EOF
33+
cat << EOF > external/bin/g++
34+
#!/bin/bash
35+
exec $(which g++) -m32 "\$@"
36+
EOF
37+
chmod 755 external/bin/gcc external/bin/g++
38+
echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH
39+
40+
- name: MSYS2 (Windows i386)
41+
if: inputs.os == 'Windows' && inputs.cpu == 'i386'
42+
uses: msys2/setup-msys2@v2
43+
with:
44+
path-type: inherit
45+
msystem: MINGW32
46+
install: >-
47+
base-devel
48+
git
49+
mingw-w64-i686-toolchain
50+
51+
- name: MSYS2 (Windows amd64)
52+
if: inputs.os == 'Windows' && inputs.cpu == 'amd64'
53+
uses: msys2/setup-msys2@v2
54+
with:
55+
path-type: inherit
56+
install: >-
57+
base-devel
58+
git
59+
mingw-w64-x86_64-toolchain
60+
61+
- name: Restore Nim DLLs dependencies (Windows) from cache
62+
if: inputs.os == 'Windows'
63+
id: windows-dlls-cache
64+
uses: actions/cache@v4
65+
with:
66+
path: external/dlls
67+
key: 'dlls'
68+
69+
- name: Install DLL dependencies (Windows)
70+
shell: ${{ inputs.shell }}
71+
if: >
72+
steps.windows-dlls-cache.outputs.cache-hit != 'true' &&
73+
inputs.os == 'Windows'
74+
run: |
75+
mkdir -p external
76+
curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip
77+
7z x external/windeps.zip -oexternal/dlls
78+
79+
- name: Path to cached dependencies (Windows)
80+
shell: ${{ inputs.shell }}
81+
if: >
82+
inputs.os == 'Windows'
83+
run: |
84+
echo '${{ github.workspace }}'"/external/dlls" >> $GITHUB_PATH
85+
86+
- name: Derive environment variables
87+
shell: ${{ inputs.shell }}
88+
run: |
89+
if [[ '${{ inputs.cpu }}' == 'amd64' ]]; then
90+
PLATFORM=x64
91+
elif [[ '${{ inputs.cpu }}' == 'arm64' ]]; then
92+
PLATFORM=arm64
93+
else
94+
PLATFORM=x86
95+
fi
96+
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV
97+
98+
ncpu=
99+
MAKE_CMD="make"
100+
case '${{ inputs.os }}' in
101+
'Linux')
102+
ncpu=$(nproc)
103+
;;
104+
'macOS')
105+
ncpu=$(sysctl -n hw.ncpu)
106+
;;
107+
'Windows')
108+
ncpu=$NUMBER_OF_PROCESSORS
109+
MAKE_CMD="mingw32-make"
110+
;;
111+
esac
112+
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1
113+
echo "ncpu=$ncpu" >> $GITHUB_ENV
114+
echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV
115+
echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH
116+
117+
- name: Restore Nim from cache
118+
id: nim-cache
119+
uses: actions/cache@v4
120+
with:
121+
path: '${{ github.workspace }}/nim'
122+
key: ${{ inputs.os }}-${{ inputs.cpu }}-nim-${{ inputs.nim_ref }}-cache-${{ env.cache_nonce }}
123+
124+
- name: Build Nim and Nimble
125+
shell: ${{ inputs.shell }}
126+
if: ${{ steps.nim-cache.outputs.cache-hit != 'true' }}
127+
run: |
128+
# We don't want partial matches of the cache restored
129+
rm -rf nim
130+
curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh
131+
env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} NIM_COMMIT=${{ inputs.nim_ref }} \
132+
QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \
133+
bash build_nim.sh nim csources dist/nimble NimBinaries

.github/workflows/lint.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: lint
2+
3+
on:
4+
pull_request:
5+
merge_group:
6+
7+
jobs:
8+
lint:
9+
name: lint
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 2 # In PR, has extra merge commit: ^1 = PR, ^2 = base
16+
17+
- name: Check NPH formatting
18+
uses: arnetheduck/nph-action@v1
19+
with:
20+
version: 0.7.0
21+
options: "./. *.nim*"
22+
fail: true
23+
suggest: true
24+
25+
- name: Check License Header
26+
uses: apache/skywalking-eyes/header@v0.8.0
27+
with:
28+
config: .github/.licenserc.yaml

.github/workflows/pr_lint.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "Conventional Commits"
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- edited
8+
- reopened
9+
- synchronize
10+
merge_group:
11+
12+
jobs:
13+
main:
14+
name: Validate PR title
15+
runs-on: ubuntu-latest
16+
permissions:
17+
pull-requests: write
18+
steps:
19+
- if: github.event_name == 'merge_group'
20+
run: echo "Skipping PR title validation for merge_group"
21+
- uses: amannn/action-semantic-pull-request@v5
22+
if: github.event_name == 'pull_request'
23+
id: lint_pr_title
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
- uses: marocchino/sticky-pull-request-comment@v2
27+
# When the previous steps fails, the workflow would stop. By adding this
28+
# condition you can continue the execution with the populated error message.
29+
if: github.event_name == 'pull_request' && always() && (steps.lint_pr_title.outputs.error_message != null)
30+
with:
31+
header: pr-title-lint-error
32+
message: |
33+
Pull requests titles must follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/)
34+
35+
# Delete a previous comment when the issue has been resolved
36+
- if: ${{ github.event_name == 'pull_request' && steps.lint_pr_title.outputs.error_message == null }}
37+
uses: marocchino/sticky-pull-request-comment@v2
38+
with:
39+
header: pr-title-lint-error
40+
delete: true

.github/workflows/test.yml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
merge_group:
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
test:
17+
timeout-minutes: 90
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
platform:
22+
- os: linux
23+
cpu: amd64
24+
- os: linux
25+
cpu: i386
26+
- os: linux-gcc-14
27+
cpu: amd64
28+
- os: macos-14
29+
cpu: arm64
30+
- os: windows
31+
cpu: amd64
32+
nim:
33+
- ref: version-2-2
34+
memory_management: refc
35+
- ref: version-2-2
36+
memory_management: orc
37+
include:
38+
- platform:
39+
os: linux
40+
builder: ubuntu-22.04
41+
shell: bash
42+
- platform:
43+
os: linux-gcc-14
44+
builder: ubuntu-24.04
45+
shell: bash
46+
- platform:
47+
os: macos-14
48+
builder: macos-14
49+
shell: bash
50+
- platform:
51+
os: windows
52+
builder: windows-2022
53+
shell: bash
54+
55+
defaults:
56+
run:
57+
shell: ${{ matrix.shell }}
58+
59+
name: "${{ matrix.platform.os }}-${{ matrix.platform.cpu }} (Nim ${{ matrix.nim.ref }} --mm=${{ matrix.nim.memory_management }})"
60+
runs-on: ${{ matrix.builder }}
61+
steps:
62+
- name: Checkout
63+
uses: actions/checkout@v6
64+
with:
65+
submodules: "recursive"
66+
67+
- name: Restore llvm-mingw (Windows) from cache
68+
if: runner.os == 'Windows'
69+
id: windows-mingw-cache
70+
uses: actions/cache@v4
71+
with:
72+
path: external/mingw-${{ matrix.platform.cpu }}
73+
key: 'mingw-llvm-17-${{ matrix.platform.cpu }}'
74+
75+
- name: Install llvm-mingw dependency (Windows)
76+
if: >
77+
steps.windows-mingw-cache.outputs.cache-hit != 'true' &&
78+
runner.os == 'Windows'
79+
run: |
80+
mkdir -p external
81+
MINGW_BASE="https://github.com/mstorsjo/llvm-mingw/releases/download/20230905"
82+
MINGW_URL="$MINGW_BASE/llvm-mingw-20230905-ucrt-x86_64.zip"
83+
curl -L "$MINGW_URL" -o "external/mingw-${{ matrix.platform.cpu }}.zip"
84+
7z x -y "external/mingw-${{ matrix.platform.cpu }}.zip" -oexternal/mingw-${{ matrix.platform.cpu }}/
85+
mv external/mingw-${{ matrix.platform.cpu }}/**/* ./external/mingw-${{ matrix.platform.cpu }}
86+
87+
- name: Path to cached dependencies (Windows)
88+
if: >
89+
runner.os == 'Windows'
90+
run: |
91+
echo '${{ github.workspace }}'"/external/mingw-${{ matrix.platform.cpu }}/bin" >> $GITHUB_PATH
92+
echo "." >> $GITHUB_PATH
93+
94+
- name: Install nasm (Windows)
95+
if: runner.os == 'Windows'
96+
shell: pwsh
97+
run: |
98+
choco install nasm --no-progress -y
99+
"C:\Program Files\NASM" | Out-File -FilePath $Env:GITHUB_PATH -Encoding utf8 -Append
100+
101+
- name: Setup Nim
102+
uses: "./.github/actions/install_nim"
103+
with:
104+
os: ${{ matrix.platform.os }}
105+
cpu: ${{ matrix.platform.cpu }}
106+
shell: ${{ matrix.shell }}
107+
nim_ref: ${{ matrix.nim.ref }}
108+
109+
- name: Restore deps from cache
110+
id: deps-cache
111+
uses: actions/cache@v3
112+
with:
113+
path: nimbledeps
114+
# Using nim.ref as a simple way to differentiate between nimble using the "pkgs" or "pkgs2" directories.
115+
# The change happened on Nimble v0.14.0. Also forcing the deps to be reinstalled on each os and cpu.
116+
key: nimbledeps-${{ matrix.nim.ref }}-${{ matrix.builder }}-${{ matrix.platform.cpu }}-${{ hashFiles('.pinned') }} # hashFiles returns a different value on windows
117+
118+
119+
- name: Install deps
120+
if: ${{ steps.deps-cache.outputs.cache-hit != 'true' }}
121+
run: |
122+
nimble install
123+
124+
- name: Use gcc 14
125+
if: ${{ matrix.platform.os == 'linux-gcc-14'}}
126+
run: |
127+
# Add GCC-14 to alternatives
128+
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 14
129+
130+
# Set GCC-14 as the default
131+
sudo update-alternatives --set gcc /usr/bin/gcc-14
132+
133+
- name: Run tests
134+
run: |
135+
nim --version
136+
nimble --version
137+
gcc --version
138+
139+
export NIMFLAGS="${NIMFLAGS} --mm:${{ matrix.nim.memory_management }}"
140+
141+
if [[ '${{ runner.os }}' == 'Windows' ]]; then
142+
export NIMFLAGS="${NIMFLAGS} --cc:clang"
143+
fi
144+
145+
nimble test --styleCheck:off --verbose --debug

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "boringssl"]
2+
path = boringssl
3+
url = https://github.com/vacp2p/boringssl.git

0 commit comments

Comments
 (0)