24 Commits

Author SHA1 Message Date
Richard Ramos
1a2f84799c test 2025-07-11 13:59:30 -04:00
Richard Ramos
e0a9b3e8f5 test 2025-07-10 15:56:57 -04:00
Richard Ramos
b158eae7a2 test 2025-07-09 15:50:06 -04:00
Richard Ramos
eb8d03a585 test 2025-07-09 14:17:45 -04:00
Richard Ramos
cbbd6f2cea test 2025-07-09 14:10:03 -04:00
Richard Ramos
f215648e99 test 2025-07-09 14:08:30 -04:00
Richard Ramos
0fea0ccc60 test 2025-07-09 14:05:21 -04:00
Richard Ramos
d397b02d8c test 2025-07-09 13:56:14 -04:00
Richard Ramos
7b50e9721f test 2025-07-09 13:27:40 -04:00
Richard Ramos
2a473ad4c6 fix: .nimble 2025-07-09 13:10:38 -04:00
Richard Ramos
4ae842614f chore: split build into two scripts 2025-07-09 13:07:06 -04:00
Richard Ramos
a042da0724 aws-lc 2025-07-09 11:48:42 -04:00
Richard Ramos
d61584c55d remove picotls submodule 2025-07-09 11:43:22 -04:00
Richard Ramos
82dbdd4b06 feat: use boringssl 2025-07-09 11:41:37 -04:00
Richard Ramos
9456daa178 fix: no inline on windows 2025-03-24 21:02:14 -04:00
Richard Ramos
eb04494047 chore: v0.36.0 2025-03-11 17:01:36 -04:00
vladopajic
525d9cfe25 chore: remove absolute path prefix from comments (#16) 2025-03-11 11:15:45 -04:00
richΛrd
95412ee90a chore: add DNGTCP2_STATICLIB and expose unexported anon structs (#13) 2025-03-11 11:00:18 -04:00
vladopajic
98372a266e chore(docs): improved instructions for generating new version (#14) 2025-03-11 14:56:31 +01:00
Richard Ramos
b9dbc3ad58 chore: v0.35.0 2025-02-28 15:36:55 -04:00
richΛrd
0a746cef2e feat: wrap picotls backend (#10) 2025-02-28 14:22:43 -04:00
richΛrd
0ce4b13b1b chore: add license files 2025-01-16 10:57:40 -04:00
richΛrd
e7983b6a6e chore: use nimbus-common-workflow, add licenses and minor README.md formatting (#9) 2025-01-16 10:52:41 -04:00
diegomrsantos
6834f4756b chore: add nim 2 to ci (#8)
* add nim 2 to ci

* fix trigger

* remove ConvFromXtoItselfNotNeeded
2024-09-03 16:14:25 +02:00
23 changed files with 80971 additions and 3889 deletions

133
.github/actions/install_nim/action.yml vendored Normal file
View File

@@ -0,0 +1,133 @@
name: Install Nim
inputs:
os:
description: "Operating system to build for"
required: true
cpu:
description: "CPU to build for"
default: "amd64"
nim_ref:
description: "Nim version"
default: "version-1-6"
shell:
description: "Shell to run commands in"
default: "bash --noprofile --norc -e -o pipefail"
runs:
using: "composite"
steps:
- name: Install build dependencies (Linux i386)
shell: ${{ inputs.shell }}
if: inputs.os == 'Linux' && inputs.cpu == 'i386'
run: |
sudo dpkg --add-architecture i386
sudo apt-get update -qq
sudo DEBIAN_FRONTEND='noninteractive' apt-get install \
--no-install-recommends -yq gcc-multilib g++-multilib \
libssl-dev:i386
mkdir -p external/bin
cat << EOF > external/bin/gcc
#!/bin/bash
exec $(which gcc) -m32 "\$@"
EOF
cat << EOF > external/bin/g++
#!/bin/bash
exec $(which g++) -m32 "\$@"
EOF
chmod 755 external/bin/gcc external/bin/g++
echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH
- name: MSYS2 (Windows i386)
if: inputs.os == 'Windows' && inputs.cpu == 'i386'
uses: msys2/setup-msys2@v2
with:
path-type: inherit
msystem: MINGW32
install: >-
base-devel
git
mingw-w64-i686-toolchain
- name: MSYS2 (Windows amd64)
if: inputs.os == 'Windows' && inputs.cpu == 'amd64'
uses: msys2/setup-msys2@v2
with:
path-type: inherit
install: >-
base-devel
git
mingw-w64-x86_64-toolchain
- name: Restore Nim DLLs dependencies (Windows) from cache
if: inputs.os == 'Windows'
id: windows-dlls-cache
uses: actions/cache@v4
with:
path: external/dlls
key: 'dlls'
- name: Install DLL dependencies (Windows)
shell: ${{ inputs.shell }}
if: >
steps.windows-dlls-cache.outputs.cache-hit != 'true' &&
inputs.os == 'Windows'
run: |
mkdir external
curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip
7z x external/windeps.zip -oexternal/dlls
- name: Path to cached dependencies (Windows)
shell: ${{ inputs.shell }}
if: >
inputs.os == 'Windows'
run: |
echo '${{ github.workspace }}'"/external/dlls" >> $GITHUB_PATH
- name: Derive environment variables
shell: ${{ inputs.shell }}
run: |
if [[ '${{ inputs.cpu }}' == 'amd64' ]]; then
PLATFORM=x64
elif [[ '${{ inputs.cpu }}' == 'arm64' ]]; then
PLATFORM=arm64
else
PLATFORM=x86
fi
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV
ncpu=
MAKE_CMD="make"
case '${{ inputs.os }}' in
'Linux')
ncpu=$(nproc)
;;
'macOS')
ncpu=$(sysctl -n hw.ncpu)
;;
'Windows')
ncpu=$NUMBER_OF_PROCESSORS
MAKE_CMD="mingw32-make"
;;
esac
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1
echo "ncpu=$ncpu" >> $GITHUB_ENV
echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV
echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH
- name: Restore Nim from cache
id: nim-cache
uses: actions/cache@v4
with:
path: '${{ github.workspace }}/nim'
key: ${{ inputs.os }}-${{ inputs.cpu }}-nim-${{ inputs.nim_ref }}-cache-${{ env.cache_nonce }}
- name: Build Nim and Nimble
shell: ${{ inputs.shell }}
if: ${{ steps.nim-cache.outputs.cache-hit != 'true' }}
run: |
# We don't want partial matches of the cache restored
rm -rf nim
curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh
env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} NIM_COMMIT=${{ inputs.nim_ref }} \
QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \
bash build_nim.sh nim csources dist/nimble NimBinaries

View File

@@ -1,21 +1,124 @@
name: CI
name: Continuous Integration
on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
merge_group:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
platform:
- os: linux
cpu: amd64
- os: linux
cpu: i386
- os: linux-gcc-14
cpu: amd64
- os: macos
cpu: amd64
- os: macos-14
cpu: arm64
- os: windows
cpu: amd64
nim:
- ref: version-1-6
memory_management: refc
- ref: version-2-0
memory_management: refc
include:
- platform:
os: linux
builder: ubuntu-22.04
shell: bash
- platform:
os: linux-gcc-14
builder: ubuntu-24.04
shell: bash
- platform:
os: macos
builder: macos-13
shell: bash
- platform:
os: macos-14
builder: macos-14
shell: bash
- platform:
os: windows
builder: windows-2022
shell: msys2 {0}
defaults:
run:
shell: ${{ matrix.shell }}
name: '${{ matrix.platform.os }}-${{ matrix.platform.cpu }} (Nim ${{ matrix.nim.ref }})'
runs-on: ${{ matrix.builder }}
steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: iffy/install-nim@v5
with:
version: 1.6.20
- name: Build
run: nimble install -y
- name: Test
run: nimble test -y
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Setup Nim
uses: "./.github/actions/install_nim"
with:
os: ${{ matrix.platform.os }}
cpu: ${{ matrix.platform.cpu }}
shell: ${{ matrix.shell }}
nim_ref: ${{ matrix.nim.ref }}
- name: Restore deps from cache
id: deps-cache
uses: actions/cache@v3
with:
path: nimbledeps
# Using nim.ref as a simple way to differentiate between nimble using the "pkgs" or "pkgs2" directories.
# The change happened on Nimble v0.14.0. Also forcing the deps to be reinstalled on each os and cpu.
key: nimbledeps-${{ matrix.nim.ref }}-${{ matrix.builder }}-${{ matrix.platform.cpu }}-${{ hashFiles('.pinned') }} # hashFiles returns a different value on windows
- name: Install deps
if: ${{ steps.deps-cache.outputs.cache-hit != 'true' }}
run: |
TARGET_CPU=${{ matrix.platform.cpu }}
nimble install
- name: Install multilib support
if: ${{ matrix.platform.cpu == 'i386' && contains(matrix.platform.os, 'linux') }}
run: |
sudo apt-get update
sudo apt-get install -y gcc-multilib g++-multilib
- name: Use gcc 14
if : ${{ matrix.platform.os == 'linux-gcc-14'}}
run: |
# Add GCC-14 to alternatives
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 14
# Set GCC-14 as the default
sudo update-alternatives --set gcc /usr/bin/gcc-14
- name: Install deps (windows)
if : ${{ matrix.platform.os == 'windows'}}
run: |
pacman -S --noconfirm base-devel gcc
- name: Run tests
run: |
nim --version
nimble --version
gcc --version
TARGET_CPU=${{ matrix.platform.cpu }}
NIMFLAGS="${NIMFLAGS} --mm:${{ matrix.nim.memory_management }}"
nimble test --styleCheck:off --verbose --debug

13
.gitignore vendored
View File

@@ -1,13 +0,0 @@
*
!*/
!*.*
# ignore all cmake build files, except version.h
build/*
!build/lib/
build/lib/*
!build/lib/includes/
build/lib/includes/*
!build/lib/includes/ngtcp2/
build/lib/includes/ngtcp2/*
!build/lib/includes/ngtcp2/version.h

9
.gitmodules vendored
View File

@@ -1,3 +1,6 @@
[submodule "sources"]
path = sources
url = https://github.com/ngtcp2/ngtcp2.git
[submodule "libs/ngtcp2"]
path = libs/ngtcp2
url = https://github.com/ngtcp2/ngtcp2
[submodule "libs/aws-lc"]
path = libs/aws-lc
url = https://github.com/aws/aws-lc

5
CMakeLists.txt Normal file
View File

@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.0)
project(PrintArch NONE)
message(STATUS "CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}")

201
LICENSE-APACHEv2 Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2018 Status Research & Development GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

25
LICENSE-MIT Normal file
View File

@@ -0,0 +1,25 @@
nim-ngtcp2 is licensed under the MIT License
Copyright (c) 2025 Status Research & Development GmbH
-----------------------------------------------------
The MIT License (MIT)
Copyright (c) 2018 Status Research & Development GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

23
README.md Normal file
View File

@@ -0,0 +1,23 @@
ngtcp2 for Nim
==============
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
![Github action](https://github.com/status-im/nim-bearssl/workflows/CI/badge.svg)
<img src="https://img.shields.io/badge/nim-%3E%3D1.2.0-orange.svg?style=flat-square" />
Wrapper around the [ngtcp2](https://github.com/ngtcp2/ngtcp2) C library for
[Nim](https://nim-lang.org/).
Updating to a newer version
---------------------------
Follow these steps when updating the wrapper to a newer version of ngtcp2:
- update the git submodule in `libs/` to point to the new version
- `git submodule update --init --recursive`
- run `generate_wrapper.sh` (requires Nim, CMake and clang to be installed)
- increase the `version` property in the `ngtcp2.nimble` file
- commit the changes

View File

@@ -1,15 +0,0 @@
ngtcp2 for Nim
==============
Wrapper around the [ngtcp2](https://github.com/ngtcp2/ngtcp2) C library for
[Nim](https://nim-lang.org/).
Updating to a newer version
---------------------------
Follow these steps when updating the wrapper to a newer version of ngtcp2:
1. update the git submodule in `sources/` to point to the new version
2. run `build.sh` (requires Nim and CMake to be installed)
3. update the version in `ngtcp2.nimble`
4. commit the changes

View File

@@ -1,35 +0,0 @@
#!/bin/bash
root=$(dirname "$0")
# install nimterop, if not already installed
if ! [ -x "$(command -v toast)" ]; then
nimble install -y nimterop@2532ce0
fi
# run cmake on ngtcp2 sources
cmake -S "${root}/sources" -B "${root}/build"
# add prelude
cat "${root}/prelude.nim" > "${root}/ngtcp2.nim"
# dividing line
echo >> "${root}/ngtcp2.nim"
# assemble list of C files to be compiled
for file in `ls "${root}/sources/lib"/*.c`; do
compile="${compile} --compile=${file}"
done
# generate nim wrapper with nimterop
toast \
$compile \
--pnim \
--preprocess \
--noHeader \
--defines=NGTCP2_STATICLIB \
--replace=sockaddr=SockAddr,SockAddr_storage=Sockaddr_storage,socklen_t=SockLen \
--includeDirs="${root}/sources/lib/includes" \
--includeDirs="${root}/build/lib/includes" \
"${root}/sources/lib/includes/ngtcp2/ngtcp2.h" >> "${root}/ngtcp2.nim"
sed -i 's/\bpassC\b/passc/g' ngtcp2.nim

View File

@@ -0,0 +1,37 @@
#ifndef WINCOMPAT_H
#define WINCOMPAT_H
#include <stdint.h>
#define ssize_t int
#include <Winsock2.h>
#include <ws2tcpip.h>
#include <malloc.h>
#ifndef gettimeofday
#define gettimeofday wintimeofday
#ifndef __attribute__
#define __attribute__(X)
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct tzone {
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of DST correction */
};
int wintimeofday(struct timeval *tv, struct tzone *tz);
#ifndef strcasecmp
#define strcasecmp _stricmp
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
#endif /* WINCOMPAT_H */

55
build_libs.sh Executable file
View File

@@ -0,0 +1,55 @@
#!/bin/bash
set -euo pipefail
root=$(dirname "$0")
sources=${root}/libs
tmpdir=$(mktemp -d)
force_i386=false
# check args
for arg in "$@"; do
case "$arg" in
--i386)
force_i386=true
;;
*)
echo "unknown arg: $arg" >&2
exit 1
;;
esac
done
cmake_args=(
-DCMAKE_BUILD_TYPE=Release
-DBUILD_SHARED_LIBS=OFF
-DBUILD_TESTING=OFF
-DFIPS=OFF
-DBUILD_TOOL=OFF
-DDISABLE_GO=ON
)
# optionally inject i386 toolchain
if [ "$force_i386" = true ]; then
toolchain_file=$(mktemp)
cat > "$toolchain_file" <<EOF
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR i386)
set(CMAKE_C_FLAGS "\${CMAKE_C_FLAGS} -m32")
set(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -m32")
EOF
cmake_args+=("-DCMAKE_TOOLCHAIN_FILE=$toolchain_file")
fi
# build aws-lc
echo "TEST1"
mkdir -p ./libs/aws-lc/build
pushd ./libs/aws-lc/build
echo "TEST4"
cmake ../ "${cmake_args[@]}"
echo "TEST2"
make
echo "TEST3"
popd
cp ./libs/aws-lc/build/ssl/libssl.a ./build/.
cp ./libs/aws-lc/build/crypto/libcrypto.a ./build/.

View File

@@ -1,5 +1,15 @@
--styleCheck:usages
when not defined(windows):
# use the C++ linker profile because it's a C++ library
when defined(macosx):
switch("clang.linkerexe", "clang++")
else:
switch("gcc.linkerexe", "g++")
--styleCheck:
usages
if (NimMajor, NimMinor) < (1, 6):
--styleCheck:hint
--styleCheck:
hint
else:
--styleCheck:error
--styleCheck:
error

1
extras.nim Normal file
View File

@@ -0,0 +1 @@

14
generate_ngtcp2.nim Normal file
View File

@@ -0,0 +1,14 @@
import futhark
from os import parentDir, `/`
importc:
outputPath currentSourcePath.parentDir / "tmp_ngtcp2.nim"
path currentSourcePath.parentDir / "libs/ngtcp2/lib/includes"
path currentSourcePath.parentDir / "build/lib/includes"
path currentSourcePath.parentDir / "libs/ngtcp2/crypto/includes/"
path currentSourcePath.parentDir / "libs/aws-lc/include"
rename FILE, CFile # Rename `FILE` that STB uses to `CFile` which is the Nim equivalent
"ngtcp2/ngtcp2.h"
"ngtcp2/ngtcp2_crypto.h"
"ngtcp2/ngtcp2_crypto_boringssl.h"
"openssl/ssl.h"

49
generate_wrapper.sh Executable file
View File

@@ -0,0 +1,49 @@
#!/bin/bash
root=$(dirname "$0")
sources=${root}/libs
rm -f ngtcp2.nim
# assemble list of C files to be compiled
toCompile=()
for file in `ls "${sources}/ngtcp2/crypto"/*.c`; do
toCompile+=("$file")
done
for file in `ls "${sources}/ngtcp2/crypto/boringssl"/*.c`; do
toCompile+=("$file")
done
for file in `ls "${sources}/ngtcp2/lib"/*.c`; do
toCompile+=("$file")
done
# build aws-lc
tmpdir=$(mktemp -d)
cmake -S ./libs/aws-lc -B "$tmpdir" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DFIPS=OFF -DBUILD_TOOL=OFF -DDISABLE_GO=ON
cmake --build "$tmpdir" --target all
cp "$tmpdir"/ssl/libssl.a ./build/.
cp "$tmpdir"/crypto/libcrypto.a ./build/.
# futhark is required by generate_ngtcp2.nim
nimble install futhark@0.15.0
nim c --maxLoopIterationsVM:100000000 generate_ngtcp2.nim
cat "${root}/prelude.nim" > ngtcp2.nim
echo >> ngtcp2.nim # linebreak
for file in "${toCompile[@]}"; do
echo "{.compile: \"$file\".}" >> ngtcp2.nim
done
# removes absolute path prefix from comments "Generated based on"
sed -i 's/Generated based on.*\/nim-ngtcp2\/libs\//Generated based on \/nim-ngtcp2\/libs\//g' tmp_ngtcp2.nim
cat tmp_ngtcp2.nim >> ngtcp2.nim
echo >> ngtcp2.nim # linebreak
cat "${root}/extras.nim" >> ngtcp2.nim
rm -f tmp_ngtcp2.nim

1
libs/aws-lc Submodule

Submodule libs/aws-lc added at 8b52781470

1
libs/ngtcp2 Submodule

Submodule libs/ngtcp2 added at 048cdfd0c2

84017
ngtcp2.nim

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,33 @@
packageName = "ngtcp2"
version = "0.34.0"
version = "0.37.0"
author = "Status Research & Development GmbH"
description = "Nim wrapper around the ngtcp2 library"
license = "MIT"
installDirs = @["sources", "build"]
installDirs = @["libs", "build"]
installFiles = @["ngtcp2.nim"]
requires "nim >= 1.6.0"
template build() =
when defined(windows):
exec "./build_libs.sh"
else:
let targetCpu = getEnv("TARGET_CPU", hostCPU)
if targetCpu == "i386":
exec "./build_libs.sh --i386"
else:
exec "./build_libs.sh"
before install:
build()
task format, "Format nim code using nph":
exec "nimble install nph"
exec "nph ."
task test, "Run tests":
build()
when defined(windows):
exec "nim c -d:nimDebugDlOpen -r --threads:on tests/testNgtcp2.nim"
else:
exec "nim c -r --threads:on tests/testNgtcp2.nim"

View File

@@ -1,17 +1,41 @@
import os
import strformat
import strformat, strutils
# Socket definitions
import nativesockets
when defined(windows):
{.passl: "-lws2_32".}
# TODO: test this
{.push importc, cdecl, dynlib: "libcrypto.dll".}
{.push importc, cdecl, dynlib: "libssl.dll".}
else:
{.passC: "-DHAVE_UNISTD_H".}
const
topLevelPath = currentSourcePath.parentDir()
libsDir = topLevelPath.replace('\\', '/') & "/build/"
{.passl: libsDir & "/libssl.a".}
{.passl: libsDir & "/libcrypto.a".}
{.passc: "-DNGTCP2_STATICLIB".}
when defined(windows):
{.passl: "-lws2_32".}
{.passc: "-D_WINDOWS".}
{.passc: "-D__CRT__NO_INLINE".}
else:
{.passc: "-DHAVE_UNISTD_H".}
# C include directories
const root = currentSourcePath.parentDir
const sourceInclude = root/"sources"/"lib"/"includes"
const buildInclude = root/"build"/"lib"/"includes"
const libIncludes = root / "build" / "lib" / "includes"
const ngtcp2Crypto = root / "libs" / "ngtcp2" / "crypto"
const ngtcp2CryptoIncludes = root / "libs" / "ngtcp2" / "crypto" / "includes"
const ngtcp2Lib = root / "libs" / "ngtcp2" / "lib"
const ngtcp2LibIncludes = root / "libs" / "ngtcp2" / "lib" / "includes"
const awsLcInclude = root / "libs" / "aws-lc" / "include"
{.passc: fmt"-I{sourceInclude} -I{buildInclude}".}
{.passc: fmt"-I{libIncludes}".}
{.passc: fmt"-I{ngtcp2Crypto}".}
{.passc: fmt"-I{ngtcp2CryptoIncludes}".}
{.passc: fmt"-I{ngtcp2Lib}".}
{.passc: fmt"-I{ngtcp2LibIncludes}".}
{.passc: fmt"-I{awsLcInclude}".}

Submodule sources deleted from 5f8bd54ad7

View File

@@ -7,5 +7,15 @@ test "default settings":
check settings.max_tx_udp_payload_size > 0
var transport_params: ngtcp2_transport_params
ngtcp2_transport_params_default_versioned(NGTCP2_TRANSPORT_PARAMS_V1, addr transport_params)
ngtcp2_transport_params_default_versioned(
NGTCP2_TRANSPORT_PARAMS_V1, addr transport_params
)
check transport_params.active_connection_id_limit > 0
test "boringssl_instantiation":
let
clientMethod = TLS_client_method()
ssl_ctx = SSL_CTX_new(clientMethod)
ssl = SSL_new(ssl_ctx)
check ssl != nil