Remove cmake (#11)

* Tests: Dockerfile: Remove cmake from deps.

* Tests: Dockerfile: Replace manual libplum building with nimble task.

* Build libplum without cmake.

* Use {.compile.} to compile libplum as part of tha package; remove separate build task.

* Rewrite flags construction, pass flags to compile, remove passC.

* Add localPassC.

* Combine libplum units to libplum_units.c.

* Tests: Dockerfile: Add the units file to the image.

* Add missing flags.

* CI: Remove redundant cmake invocations.

* Remove redundant nimble task invocation.
This commit is contained in:
Constantine Molchanov 2026-07-07 12:02:45 +04:00 committed by GitHub
parent 433e48789d
commit eae41079b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 47 additions and 31 deletions

View File

@ -25,9 +25,6 @@ jobs:
- name: Unit tests
# same reason as integration tests: nimble exits with code 0 even on failure.
run: |
cmake -B vendor/libplum/build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF vendor/libplum
cmake --build vendor/libplum/build
cp vendor/libplum/build/libplum.a vendor/libplum/libplum.a
nim c -o:tests/test_plum tests/test_plum.nim
./tests/test_plum

View File

@ -13,20 +13,10 @@ requires "nim >= 1.6.0",
"chronos >= 4.2.0 & < 5.0.0",
"unittest2"
proc compileStaticLibraries() =
withDir "vendor/libplum":
exec("cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF")
exec("cmake --build build")
cpFile("build/libplum.a", "libplum.a")
task format, "format Nim code using nph":
exec "nph libplum/ tests/"
task buildBundledLibs, "build bundled libraries":
compileStaticLibraries()
task test, "run tests":
compileStaticLibraries()
exec("nimble setup")
exec("nim c -o:tests/test_plum tests/test_plum.nim")
exec("./tests/test_plum")
@ -40,6 +30,3 @@ task testIntegration, "run miniupnpd integration tests in Docker / Podman":
exec(docker & " run --rm --cap-add=NET_ADMIN -e TEST_MINIUPNP_PCP=1" & flags & " " & packageName)
exec(docker & " run --rm --cap-add=NET_ADMIN -e TEST_MINIUPNP_UPNP=1" & flags & " " & packageName)
exec(docker & " run --rm --cap-add=NET_ADMIN -e TEST_MINIUPNP_NATPMP=1" & flags & " " & packageName)
before install:
compileStaticLibraries()

View File

@ -6,21 +6,37 @@
# This file may not be copied, modified, or distributed except according to
# those terms.
import std/[os, strutils]
import std/[os, sequtils, strutils]
const
rootPath = currentSourcePath.parentDir().parentDir().replace('\\', '/')
libplumPath = rootPath & "/vendor/libplum"
includePath = libplumPath & "/include/plum"
libraryPath = libplumPath & "/libplum.a"
{.passc: "-I" & includePath & " -DPLUM_STATIC".}
{.passl: libraryPath.}
srcPath = libplumPath & "/src"
includes = @["-I" & includePath, "-I" & srcPath]
defs = @["-DPLUM_STATIC", "-DPLUM_EXPORTS", "-DRELEASE=1", "-D_GNU_SOURCE"]
pdefs =
when defined(windows):
@["-DWIN32_LEAN_AND_MEAN"]
else:
@[]
flags* = (includes & defs & pdefs).mapIt(it.quoteShell()).join(" ")
{.localPassC: flags.}
when defined(windows):
{.passl: "-lws2_32 -liphlpapi -lbcrypt".}
else:
{.passl: "-lpthread".}
{.compile(rootPath & "/libplum_units.c", flags).}
{.compile(srcPath & "/http.c", flags).}
{.compile(srcPath & "/upnp.c", flags).}
const
PLUM_ERR_SUCCESS* = cint(0)
PLUM_ERR_INVALID* = cint(-1)

View File

@ -10,7 +10,9 @@ import std/atomics
import chronos
import chronos/threadsync
import results
import ./libplum
import libplum
{.localPassC: libplum.flags.}
# libplum declares some parameters as `const T*` in C (read-only pointer).
# Nim has no equivalent, so the generated C code drops the `const`, causing

22
libplum_units.c Normal file
View File

@ -0,0 +1,22 @@
// Copyright (c) 2026 Status Research & Development GmbH
// Licensed under either of
// * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
// * MIT license ([LICENSE-MIT](LICENSE-MIT))
// at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.
#include "./vendor/libplum/src/addr.c"
#include "./vendor/libplum/src/client.c"
#include "./vendor/libplum/src/dummytls.c"
#include "./vendor/libplum/src/log.c"
#include "./vendor/libplum/src/natpmp.c"
#include "./vendor/libplum/src/net.c"
#include "./vendor/libplum/src/noprotocol.c"
#include "./vendor/libplum/src/pcp.c"
#include "./vendor/libplum/src/plum.c"
#include "./vendor/libplum/src/random.c"
#include "./vendor/libplum/src/tcp.c"
#include "./vendor/libplum/src/timestamp.c"
#include "./vendor/libplum/src/udp.c"
#include "./vendor/libplum/src/util.c"

View File

@ -1,7 +1,7 @@
FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \
cmake gcc make git curl ca-certificates xz-utils \
gcc make git curl ca-certificates xz-utils \
libc-dev \
iproute2 \
&& rm -rf /var/lib/apt/lists/*
@ -34,19 +34,11 @@ RUN curl -fsSL "https://nim-lang.org/download/nim-${NIM_VERSION}-linux_x64.tar.x
# Install nim deps (cached layer)
WORKDIR /app
COPY libplum.nimble .
COPY libplum_units.c .
COPY libplum/ libplum/
COPY vendor/ vendor/
RUN nimble setup -y
# Build libplum static library
RUN rm -rf vendor/libplum/build && \
cmake -B vendor/libplum/build \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
vendor/libplum && \
cmake --build vendor/libplum/build && \
cp vendor/libplum/build/libplum.a vendor/libplum/libplum.a
# Compile test binaries (protocol x memory manager)
COPY tests/ tests/
RUN nim c -d:miniupnp_protocol=pcp --mm:orc --threads:on -o:tests/test_pcp_orc tests/test_plum.nim && \