Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
712f6d2
first draft
lchenut Jan 24, 2023
c219b5d
add tests
lchenut Jan 24, 2023
452f91b
add fatal in case of enum without 0
lchenut Jan 24, 2023
64f7113
fix & replace unrecognized value behaviour
lchenut Jan 24, 2023
d7ba7a1
Merge remote-tracking branch 'origin/master' into add-enum-support
lchenut Jan 25, 2023
0095fbd
Show line on parsing failure
Menduist Jan 27, 2023
fdb84ce
better proto2 parsing
Menduist Jan 27, 2023
853bfe0
First draft conformance tests
lchenut Jan 31, 2023
0937f9b
add a lot of stuff
lchenut Feb 6, 2023
3fbaa98
adding conformance protofiles
lchenut Feb 6, 2023
e06f826
add table/ref and clear conformance_nim
lchenut Feb 9, 2023
488ccb7
Add conformance test's nimble task
lchenut Feb 10, 2023
5acc4c0
Add conformance jobs
lchenut Feb 10, 2023
b93f4ea
Add cmake installation
lchenut Feb 13, 2023
a809ce3
Add brew update
lchenut Feb 13, 2023
d70f90d
Add protobuf 2 conformance test
lchenut Feb 13, 2023
6393cb3
Fix conformance.yml (1)
lchenut Feb 13, 2023
86b4180
Remove duplicate file
lchenut Feb 13, 2023
a41766c
Fix CI
lchenut Feb 13, 2023
7e3bdd2
Fix CI in nim 1.2
lchenut Feb 14, 2023
f0bef09
Add expected failure list
lchenut Feb 14, 2023
edfd961
Add a log option to import_proto3
lchenut Feb 15, 2023
783244c
Update workflows os
lchenut Feb 16, 2023
1a52b6a
Hide map and ref behind a ConformanceTest flag
lchenut Feb 16, 2023
60ff290
Various fix
lchenut Feb 16, 2023
b211634
Readded the pragma proto3 to the enum
lchenut Feb 17, 2023
8ac2d17
Pin conformance tests versions
Menduist Feb 17, 2023
faba393
Make conformance tests for linux only
lchenut Feb 17, 2023
3592b13
Hide enum behind flag + use stew logger
lchenut Feb 21, 2023
9553d39
Change type generated log
lchenut Feb 21, 2023
b70cb9b
fix if / when
lchenut Feb 21, 2023
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ jobs:
include:
- target:
os: linux
builder: ubuntu-18.04
builder: ubuntu-20.04
shell: bash
- target:
os: macos
builder: macos-10.15
builder: macos-12
shell: bash
- target:
os: windows
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
- name: Restore Nim DLLs dependencies (Windows) from cache
if: runner.os == 'Windows'
id: windows-dlls-cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: external/dlls-${{ matrix.target.cpu }}
key: 'dlls-${{ matrix.target.cpu }}'
Expand Down
101 changes: 101 additions & 0 deletions .github/workflows/conformance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Conformance Test

on:
workflow_dispatch:
types: [run]
pull_request:

concurrency: # Cancel stale PR builds (but not push builds)
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
build:
strategy:
fail-fast: false
matrix:
target:
- os: linux
cpu: amd64
- os: linux
cpu: i386

branch: [version-1-4, version-1-6, devel]
include:
- target:
os: linux
builder: ubuntu-20.04
shell: bash

defaults:
run:
shell: ${{ matrix.shell }}

name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (Nim ${{ matrix.branch }})'
runs-on: ${{ matrix.builder }}
continue-on-error: ${{ matrix.branch == 'devel' }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install build dependencies (Linux i386)
if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
run: |
sudo dpkg --add-architecture i386
sudo apt-fast update -qq
sudo DEBIAN_FRONTEND='noninteractive' apt-fast 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: Derive environment variables
run: |
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
PLATFORM=x64
else
PLATFORM=x86
fi
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV

ncpu=
MAKE_CMD="make"
case '${{ runner.os }}' in
'Linux')
ncpu=$(nproc)
;;
esac
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1
echo "ncpu=$ncpu" >> $GITHUB_ENV
echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV

- name: Install CMake
run: |
if [ "${{ runner.os }}" == "Linux" ]; then
sudo apt-get install cmake
fi

- name: Build Nim and Nimble
run: |
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=${{ matrix.branch }} \
QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \
bash build_nim.sh nim csources dist/nimble NimBinaries
echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH

- name: Run tests
run: |
nim --version
nimble --version
nimble install -y --depsOnly
env NIMLANG="c" nimble conformance_test
env NIMLANG="cpp" nimble conformance_test
17 changes: 17 additions & 0 deletions protobuf_serialization.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,20 @@ task test, "Run all tests":
echo " \x1B[0;31m[FAILED]\x1B[0;37m ", path.split(DirSep)[^1]
exec "exit 1"

task conformance_test, "Run conformance tests":
let
pwd = thisDir()
conformance = pwd / "conformance"
test = pwd / "tests" / "conformance"

if not system.dirExists(conformance):
exec "git clone -b v22.0 --recurse-submodules https://github.com/protocolbuffers/protobuf/ " & conformance

withDir conformance:
exec "cmake . -Dprotobuf_BUILD_CONFORMANCE=ON"
exec "make conformance_test_runner"

exec "cp " & conformance / "conformance_test_runner" & " " & test
withDir test:
exec "nim c -d:ConformanceTest conformance_nim.nim"
exec "./conformance_test_runner --failure_list failure_list.txt conformance_nim"
9 changes: 7 additions & 2 deletions protobuf_serialization/codec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type
# EndGroup = 4 # Not used
Fixed32 = 5

SomePBInt* = int32 | int64 | uint32 | uint64

FieldHeader* = distinct uint32

# Scalar types used in `.proto` files
Expand All @@ -54,19 +56,20 @@ type
sfixed64* = distinct int64 ## fixed-width signed integer

pbool* = distinct bool
penum* = distinct int32

pstring* = distinct string ## UTF-8-encoded string
pbytes* = distinct seq[byte] ## byte sequence

SomeScalar* =
pint32 | pint64 | puint32 | puint64 | sint32 | sint64 | pbool |
pint32 | pint64 | puint32 | puint64 | sint32 | sint64 | pbool | penum |
fixed64 | sfixed64 | pdouble |
pstring | pbytes |
fixed32 | sfixed32 | pfloat

# Mappings of proto type to wire type
SomeVarint* =
pint32 | pint64 | puint32 | puint64 | sint32 | sint64 | pbool
pint32 | pint64 | puint32 | puint64 | sint32 | sint64 | pbool | penum
SomeFixed64* = fixed64 | sfixed64 | pdouble
SomeLengthDelim* = pstring | pbytes # Also messages and packed repeated fields
SomeFixed32* = fixed32 | sfixed32 | pfloat
Expand Down Expand Up @@ -116,6 +119,7 @@ func toUleb(x: sint32): uint32 =
template toUleb(x: pint64): uint64 = cast[uint64](x)
template toUleb(x: pint32): uint32 = cast[uint32](x)
template toUleb(x: pbool): uint8 = cast[uint8](x)
template toUleb(x: penum): uint64 = cast[uint32](x)

template fromUleb(x: uint64, T: type puint64): T = puint64(x)
template fromUleb(x: uint64, T: type pbool): T = pbool(x != 0)
Expand All @@ -130,6 +134,7 @@ template fromUleb(x: uint64, T: type sint32): T =

template fromUleb(x: uint64, T: type pint64): T = cast[T](x)
template fromUleb(x: uint64, T: type pint32): T = cast[T](x)
template fromUleb(x: uint64, T: type penum): T = cast[T](x)

template toBytes*(x: SomeVarint): openArray[byte] =
toBytes(toUleb(x), Leb128).toOpenArray()
Expand Down
13 changes: 12 additions & 1 deletion protobuf_serialization/files/decldef.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type
ReservedType* = enum
String, Number, Range
ProtoType* = enum
Field, Enum, EnumVal, ReservedBlock, Reserved, Message, File, Imported, Oneof, Package, ProtoDef
Field, Enum, EnumVal, ReservedBlock, Reserved, Message, File, Imported, Oneof, Package, ProtoDef, Extend
Presence* = enum
Singular, Repeated, Optional, Required
ProtoNode* = ref object
Expand Down Expand Up @@ -62,6 +62,9 @@ type
definedEnums*: seq[ProtoNode]
fields*: seq[ProtoNode]
nested*: seq[ProtoNode]
of Extend:
extending*: string
extendedFields*: seq[ProtoNode]
of Package:
packageName*: string
messages*: seq[ProtoNode]
Expand Down Expand Up @@ -148,6 +151,14 @@ proc `$`*(node: ProtoNode): string =
messages &= $message & "\n"
data &= messages[0..^2].indent(1, " ")
result &= data.indent(1, " ")
of Extend:
result = "Extension of $1 with fields:".format(node.extending)
var data = ""
var fields = "\n"
for field in node.extendedFields:
fields &= $field & "\n"
data &= fields[0..^2].indent(1, " ")
result &= data.indent(1, " ")
of File:
result = "Protobuf file with syntax $1\n".format(
node.syntax)
Expand Down
Loading