Skip to content

nng-sys: upgrade to NNG 2.0.0-alpha.6#34

Merged
flxo merged 32 commits intonanomsg:mainfrom
flxo:nng-sys/nng-v2
Jan 16, 2026
Merged

nng-sys: upgrade to NNG 2.0.0-alpha.6#34
flxo merged 32 commits intonanomsg:mainfrom
flxo:nng-sys/nng-v2

Conversation

@flxo
Copy link
Collaborator

@flxo flxo commented Jan 12, 2026

bump NNG to 2.0.0-alpha.6

BREAKING CHANGES:

  • nng_init() must be called before using any NNG functions
  • nng_close() renamed to nng_socket_close()
  • nng_send_aio()/nng_recv_aio() renamed to nng_socket_send()/nng_socket_recv()
  • Many functions now return nng_err enum instead of c_int
  • ZeroTier transport removed (NNG_AF_ZT, nng_sockaddr_zt, nng_zt_*)
  • nanomsg compatibility layer removed (compat feature and headers)
  • NNG_FLAG_ALLOC removed
  • Many option getter/setter functions removed or renamed
  • TLS must now be configured via nng_tls_config_* functions
  • URL structure is now opaque with accessor functions

For the complete migration guide, see the migration guilde.

Changes:

  • Bump nng-sys version to 0.4.0+v2.0.0-alpha.6
  • Bump nng-sys/nng submodule to v2.0.0-alpha.6
  • Regenerate bindings for NNG 2.0 API
  • Simplify wrapper.h (now just nng.h and http.h)
  • Remove compat.h and supplemental.h
  • Update build.rs: remove compat feature handling, bump pkg-config to 2.0.0
  • Add NNG_AF_ABSTRACT to nng_sockaddr_family conversion
  • Update README with NNG 2.0 warning, migration guide, and fixed examples
  • Update tests for NNG 2.0 API (nng_init, nng_socket_close, nng_err)

Note: The links = "nng" attribute is temporarily commented out because anng and nng crates still depend on nng-sys version 0.3.0 from crates.io and cargo treats this as a conflict.

Summary by CodeRabbit

  • New Features

    • Adds broad NNG v2 support: typed error enums, URL/TLS/HTTP types, TLS config and HTTP client/server APIs, runtime initialization, and many new public helpers.
  • Bug Fixes & Improvements

    • Updates public APIs/constants to NNG v2 shape; removes legacy compat surfaces and modernizes option/return conventions.
  • CI / Chores

    • CI favors system NNG or builds/installs NNG from source; new install script and simplified workflow matrix.
  • Documentation

    • Migration notes, examples, and docs updated to reflect NNG v2.
  • Tests

    • Tests initialize runtime and validate version suffix compatibility.

✏️ Tip: You can customize this high-level summary in your review settings.

BREAKING CHANGES:
- nng_init() must be called before using any NNG functions
- nng_close() renamed to nng_socket_close()
- nng_send_aio()/nng_recv_aio() renamed to nng_socket_send()/nng_socket_recv()
- Many functions now return nng_err enum instead of c_int
- ZeroTier transport removed (NNG_AF_ZT, nng_sockaddr_zt, nng_zt_*)
- nanomsg compatibility layer removed (compat feature and headers)
- NNG_FLAG_ALLOC removed
- Many option getter/setter functions removed or renamed
- TLS must now be configured via nng_tls_config_* functions
- URL structure is now opaque with accessor functions

For the complete migration guide, see:
https://github.com/nanomsg/nng/blob/master/docs/ref/migrate/nng1.md

Changes:
- Bump nng-sys version to 0.4.0+v2.0.0-alpha.6
- Bump nng-sys/nng submodule to v2.0.0-alpha.6
- Regenerate bindings for NNG 2.0 API
- Simplify wrapper.h (now just nng.h and http.h)
- Remove compat.h and supplemental.h
- Update build.rs: remove compat feature handling, bump pkg-config to 2.0.0
- Add NNG_AF_ABSTRACT to nng_sockaddr_family conversion
- Update README with NNG 2.0 warning, migration guide, and fixed examples
- Update tests for NNG 2.0 API (nng_init, nng_socket_close, nng_err)

Note: The `links = "nng"` attribute is temporarily commented out because
anng and nng crates still depend on nng-sys 0.3.0 from crates.io.
@flxo flxo marked this pull request as draft January 12, 2026 09:57
@coderabbitai
Copy link

coderabbitai bot commented Jan 12, 2026

📝 Walkthrough

Walkthrough

Upgrade nng-sys to a v0.4 pre-release targeting NNG 2.0-alpha: regenerate large bindings (HTTP/TLS/URL/error API surface), remove legacy compat/supplemental wiring and local path overrides, add CI matrix flag/steps to optionally build/install NNG, and add an install script for the nng submodule.

Changes

Cohort / File(s) Summary
CI Build Configuration
\.github/workflows/build-configurations.yml, \.github/workflows/check.yml
Add matrix.install_nng flag, remove some vendored matrix entries, reorder package installs, add conditional "Build and install NNG" step invoking .github/scripts/install-nng.sh, and switch to per-crate cargo hack checks.
Install Script
\.github/scripts/install-nng.sh
New script to cmake-build & install NNG from nng-sys/nng with OS-specific install prefixes, parallel build logic, sudo install, and ldconfig on Linux.
Top-level Manifests
nng/Cargo.toml, anng/Cargo.toml
Remove local path = "../nng-sys" path dependency entries and add TODO/commented path to prefer registry-based dependency until nng-sys v0.4 is adopted.
nng-sys Manifest
nng-sys/Cargo.toml
Bump package version to v0.4 pre-release metadata, add author entry, comment out links = "nng", and drop compat / supplemental feature flags.
Submodule Pointer
nng-sys/nng
Advance nng submodule pointer to a newer commit targeting NNG 2.0-alpha.
Bindings Regeneration
nng-sys/src/bindings.rs
Large public API changes: bump NNG version constants, add nng_err enum and many TLS/HTTP/URL types/functions, rename and change many signatures to return nng_err, remove/rename legacy constants, and expand public surface (HTTP/TLS/URL/id-map).
Build Script
nng-sys/build.rs
Remove compat/supplemental rerun hints and NNG_ENABLE_COMPAT emission, raise pkg-config minimum to 2.0.0, adjust vendored/MSVC stats handling, and simplify binding generation paths.
Headers / Wrapper
nng-sys/src/wrapper.h, nng-sys/src/compat.h, nng-sys/src/supplemental.h
Replace many explicit protocol includes with a single <nng/http.h>, remove nanomsg compat include and several supplemental includes.
Library Examples & Tests
nng-sys/src/lib.rs, nng-sys/tests/tests.rs
Add nng_init() runtime init in examples/tests, replace nng_close with nng_socket_close, and update tests to assert runtime release-suffix matches compile-time suffix.

Sequence Diagram(s)

sequenceDiagram
  participant GH as "GitHub Actions"
  participant Matrix as "Job Matrix"
  participant PM as "Package Manager (apt / brew)"
  participant Script as ".github/scripts/install-nng.sh"
  participant Sub as "nng-sys/nng (submodule)"
  participant CMake as "CMake / Build"
  participant Cargo as "cargo / cargo-hack"

  GH->>Matrix: start job
  Matrix->>PM: install base packages
  alt matrix.install_nng == true
    Matrix->>Script: run install-nng.sh
    Script->>Sub: cd into submodule
    Script->>CMake: configure & build NNG
    CMake-->>Script: produce shared libs
    Script->>PM: sudo install & ldconfig (Linux)
  end
  Matrix->>Cargo: run per-crate cargo-hack checks & builds
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Poem

🐇 I hopped through bindings, tugged a thread or two,

TLS and HTTP danced into view.
CI learned to build from the submodule tree,
CMake hummed softly, libraries set free.
Tiny paws applaud this version-new debut.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main change: upgrading nng-sys to NNG 2.0.0-alpha.6, which is reflected throughout all modified files including version bumps, API changes, and documentation updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.



📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54c850e and a9f48ea.

📒 Files selected for processing (1)
  • .github/workflows/check.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/check.yml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: ubuntu / beta / updated
  • GitHub Check: ubuntu / stable / features
  • GitHub Check: nng-sys on Windows --features vendored

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Build NNG from nng-sys/nng submodule instead of Debian packages (v1.x)
- Update linux-sys 'system + bindgen' job to build NNG from source
- Update linux-nng job to build NNG from source
- Update macOS jobs to build NNG from submodule (consolidate to 2 configs)
- Remove compat and supplemental test jobs (features don't exist in NNG 2.0)
@flxo
Copy link
Collaborator Author

flxo commented Jan 12, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 12, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

WORKAROUND: MSVC doesn't allow empty structs in C (error C2016), and
NNG has a bug where nng/src/core/stats.h defines an empty nni_stat_item
struct when NNG_ENABLE_STATS is OFF.

Until this is fixed upstream, we must always enable stats when building
with MSVC to avoid the empty struct compilation error.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
nng-sys/build.rs (2)

253-275: Empty include paths can cause bindgen failure when system defaults succeed.

The pipeline failure ('nng/http.h' file not found) stems from this code path. When try_compile_probe_without_paths() succeeds but CFLAGS is empty or lacks -I flags, include_dirs will be empty. While cc::Build can find headers via system default paths, bindgen requires explicit -I flags.

Proposed fix: probe for common system include paths
     if try_compile_probe_without_paths() {
         // Success! The system compiler can find NNG without any help.
-        // No need to emit link-search or metadata paths.
         println!("cargo:warning=found NNG via system compiler defaults");
         let mut include_dirs = Vec::new();
         let cflags = get_env_var("CFLAGS").unwrap_or_default();
         let mut cflags = cflags.split_whitespace();
         while let Some(flag) = cflags.next() {
             if let Some(mut path) = flag.strip_prefix("-I") {
                 if path.is_empty() {
                     // -I $path
                     let Some(next_path) = cflags.next() else {
                         break;
                     };
                     path = next_path;
                 } else {
                     // -I$path
                 }
                 include_dirs.push(path.into());
             }
         }
+        // If no explicit include paths found, check common system locations
+        if include_dirs.is_empty() {
+            for candidate in &["/usr/include", "/usr/local/include"] {
+                let nng_header = Path::new(candidate).join("nng/nng.h");
+                if nng_header.exists() {
+                    include_dirs.push(PathBuf::from(candidate));
+                    break;
+                }
+            }
+        }
         return Some((LibrarySource::Manual, include_dirs));
     }

319-336: The pkg-config version check will fail to detect NNG 2.0.0-alpha.6.

The change at line 323 uses .atleast_version("2.0.0"), but pkg-config treats pre-release versions (e.g., "2.0.0-alpha.6") as less than the final release version. This causes the try_pkg_config() probe to fail silently, forcing the build to fall back to system compiler defaults or the vendored source. This is likely the root cause of the pipeline failure reporting 'nng/http.h' file not found.

Update line 323 to either:

  • .atleast_version("2.0.0-alpha") to match pre-release versions, or
  • .atleast_version("1.99.0") to accept all 2.0 pre-releases
nng-sys/src/lib.rs (1)

9-46: Check nng_init return value in the example.

The example should check the return value of nng_init, which returns nng_err. Use assert_eq!(nng_err::NNG_OK, nng_init(null_mut())); as shown in the test suite.

nng-sys/tests/tests.rs (1)

12-49: Call nng_init() before nng_version() in the version test; fix version parsing to handle dotted suffixes; remove debug statement.

verify_runtime_version_matches_constants() violates NNG 2.0's documented requirement that nng_init() must be called before any NNG function. This test calls nng_version() without initialization, which can cause flakiness or undefined behavior.

Additionally:

  • Line 86–87: split('.') with hard-coded 3-part expectation breaks for versions with dotted suffixes (e.g., "1.0.0alpha.6"). Use splitn(3, '.') instead.
  • Line 102: Remove the dbg!(&runtime_suffix); statement.
Proposed fix
 mod tests {
-
     use nng_sys::*;
     use std::{
         ffi::{CStr, CString},
         os::raw::c_char,
         ptr::null_mut,
+        sync::Once,
     };
 
+    static NNG_INIT: Once = Once::new();
+
+    fn ensure_nng_init() {
+        NNG_INIT.call_once(|| unsafe {
+            assert_eq!(nng_err::NNG_OK, nng_init(core::ptr::null()));
+        });
+    }
+
     #[test]
     fn basic() {
-        unsafe {
-            // Initialize NNG (required in NNG 2.0)
-            assert_eq!(nng_err::NNG_OK, nng_init(null_mut()));
+        ensure_nng_init();
+        unsafe {
 
             let url = CString::new("inproc://nng_sys/tests/basic").unwrap();
             let url = url.as_bytes_with_nul().as_ptr() as *const c_char;
     #[test]
     fn verify_runtime_version_matches_constants() {
+        ensure_nng_init();
         unsafe {
-            let parts: Vec<&str> = version_str.split('.').collect();
-            assert_eq!(parts.len(), 3, "Version string should have 3 parts");
-
-            let runtime_major: u32 = parts[0].parse().expect("a valid major version");
-            let runtime_minor: u32 = parts[1].parse().expect("a valid minor version");
-            // The patch part may contain a suffix like "0dev", so extract only the numeric prefix
-            let patch_numeric: String = parts[2]
+            let mut parts = version_str.splitn(3, '.');
+            let runtime_major: u32 = parts.next().unwrap().parse().expect("a valid major version");
+            let runtime_minor: u32 = parts.next().unwrap().parse().expect("a valid minor version");
+            let patch_and_suffix = parts.next().unwrap_or("");
+
+            // The patch part may contain a suffix like "0dev" or "0alpha.6"
+            let patch_numeric: String = patch_and_suffix
                 .chars()
                 .take_while(|c| c.is_ascii_digit())
                 .collect();
             let runtime_patch: u32 = patch_numeric.parse().expect("a valid patch version");
-            let runtime_suffix: String = parts[2]
+            let runtime_suffix: String = patch_and_suffix
                 .chars()
                 .skip_while(|c| c.is_ascii_digit())
                 .collect();
-
-            dbg!(&runtime_suffix);
🤖 Fix all issues with AI agents
In @.github/workflows/build-configurations.yml:
- Around line 19-56: The workflow misses an apt-get update before installs,
fails to export the NNG installation location after building the submodule, and
the linux-nng job installs Ubuntu libnng1/libnng-dev (NNG 1.x) which is
incompatible with nng-sys 0.4.0 (NNG 2.0.0-alpha.6). Fix by: add a sudo apt-get
update step before any apt installs in each matrix entry (e.g., for "system +
bindgen" and others), after building NNG from submodule write the install prefix
into $GITHUB_ENV (export NNG_DIR or NNG_INCLUDE_DIR/NNG_LIB_DIR) so build.rs
sees /usr or /usr/local, and update the "linux-nng" job to either build the
submodule NNG (set build_nng true/use same build steps as the submodule entries)
or change the job to document/explicitly test NNG 1.x compatibility if that is
intentional.

In @nng-sys/README.md:
- Around line 9-19: Update the README examples that call nng_init(null_mut()) to
check the returned nng_err rather than ignoring it: replace the bare
nng_init(null_mut()) calls in the examples with an assertion or conditional that
compares the result to nng_err::NNG_OK (e.g., assert_eq!(nng_err::NNG_OK,
nng_init(null_mut())) or an if/expect that logs/returns on error), so both
example blocks referencing nng_init(null_mut()) follow the same error-checking
pattern used in tests/tests.rs.

In @nng-sys/src/bindings.rs:
- Around line 23-31: NNG_OPT_UDP_BOUND_PORT is incorrectly set to the TCP
string; update the constant NNG_OPT_UDP_BOUND_PORT so its byte string is
"udp-bound-port\0" (matching the UDP option name and length) instead of the
current "tcp-bound-port\0" to avoid silent misconfiguration when querying UDP
options.
🧹 Nitpick comments (2)
nng-sys/build.rs (2)

448-477: Consider validating include paths before invoking bindgen.

When include_dirs is empty, bindgen will fail with cryptic clang errors. Adding early validation would provide a clearer error message.

Suggested validation
 fn generate_bindings(include_dirs: &[PathBuf]) {
+    // Validate that we have include paths with NNG headers
+    let has_nng_header = include_dirs.iter().any(|dir| dir.join("nng/nng.h").exists());
+    if !has_nng_header && !include_dirs.is_empty() {
+        println!("cargo:warning=include paths don't contain nng/nng.h, bindgen may fail");
+    }
+
     let mut builder = bindgen::Builder::default()

75-82: Stale comment references removed features.

The comment on line 77 mentions compat and supplemental features, but these were removed as part of the NNG 2.0 migration. Consider updating or removing this comment.

     // 6. Regenerate bindings if they aren't guaranteed to match pre-generated ones.
     // For example, the system-provided library could be a newer or older version.
-    // We don't need to check for `compat` or `supplemental` directly here as they imply `bindgen`.
     if cfg!(feature = "bindgen") || !matches!(source, LibrarySource::Vendored) {
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ee5bd2 and 7e06eda.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (13)
  • .github/workflows/build-configurations.yml
  • anng/Cargo.toml
  • nng-sys/Cargo.toml
  • nng-sys/README.md
  • nng-sys/build.rs
  • nng-sys/nng
  • nng-sys/src/bindings.rs
  • nng-sys/src/compat.h
  • nng-sys/src/lib.rs
  • nng-sys/src/supplemental.h
  • nng-sys/src/wrapper.h
  • nng-sys/tests/tests.rs
  • nng/Cargo.toml
💤 Files with no reviewable changes (4)
  • anng/Cargo.toml
  • nng/Cargo.toml
  • nng-sys/src/supplemental.h
  • nng-sys/src/compat.h
🧰 Additional context used
🧬 Code graph analysis (2)
nng-sys/tests/tests.rs (1)
nng-sys/src/bindings.rs (2)
  • nng_init (1686-1686)
  • nng_socket_close (275-275)
nng-sys/src/bindings.rs (3)
nng/src/socket.rs (1)
  • nng_socket (530-532)
nng/src/aio.rs (1)
  • nng_aio (448-450)
nng/src/pipe.rs (1)
  • nng_pipe (97-99)
🪛 GitHub Actions: check
nng-sys/build.rs

[error] 482-482: unable to generate bindings: ClangDiagnostic("src/wrapper.h:2:10: fatal error: 'nng/http.h' file not found")"

nng-sys/src/wrapper.h

[error] 2-2: fatal error: 'nng/http.h' file not found

nng-sys/Cargo.toml

[error] 1-1: Build failed due to missing NNG headers required for bindings generation.

🪛 LanguageTool
nng-sys/README.md

[style] ~101-~101: ‘prior to’ might be wordy. Consider a shorter alternative.
Context: ...xist. Note: Versions of this crate prior to 0.3.0 used a different scheme (`<NNG_...

(EN_WORDINESS_PREMIUM_PRIOR_TO)

🔇 Additional comments (6)
nng-sys/nng (2)

1-1: The submodule commit hash has been verified and correctly matches the v2.0.0-alpha.6 release tag.


1-1: File path is incorrect; the version is in nng-sys/Cargo.toml line 3, not nng-sys/nng.

The stability concern about NNG v2.0.0-alpha.6 is valid and already documented prominently in nng-sys/README.md with a dedicated "⚠️ NNG 2.0 Alpha" section that explains breaking changes and includes a migration guide for users upgrading from NNG 1.x. As of January 2026, NNG 2.0.0 has not been released as a stable version; the latest stable release remains v1.11 (June 2025). Developers should review the README migration guide before adopting this crate.

Likely an incorrect or invalid review comment.

nng-sys/src/bindings.rs (1)

3-6: Generated NNG 2.x surface looks consistent (init params + nng_err model).

The move to an nng_err enum plus explicit nng_init/nng_fini entrypoints matches the stated upstream breaking changes; just ensure the generated signatures align with the exact NNG revision you vendored.

Also applies to: 96-134, 1674-1690

nng-sys/src/lib.rs (1)

159-170: NNG_AF_ABSTRACT conversion addition looks right.

nng-sys/Cargo.toml (1)

3-3: Re-enable links = "nng" once downstream crates are updated to nng-sys v0.4.0.

The links = "nng" attribute is appropriately commented out for now due to workspace compatibility constraints with downstream crates (anng and nng), but should be re-enabled before this version ships broadly to avoid potential linker conflicts in downstream workspaces. The pkg-config = "0.3.32" dependency is compatible with the current build.rs implementation.

Likely an incorrect or invalid review comment.

nng-sys/src/wrapper.h (1)

1-2: The nng/http.h include is correct and intentional for NNG 2.0.0-alpha.6—no fix needed.

The wrapper.h file was recently updated as part of the NNG 2.0.0-alpha.6 upgrade (commit 62c0403). The simplified header file now includes only <nng/nng.h> and <nng/http.h>, which is intentional. The bindings have been successfully generated with 94 HTTP-related functions and types, confirming that http.h is available and correctly included. No CI failures are reported in any workflow configurations or logs.

Likely an incorrect or invalid review comment.

Felix Obenhuber added 4 commits January 12, 2026 17:13
On macOS, /usr/local/lib is not in the default library search path.
When we install NNG to /usr/local, the linker can't find libnng
unless we explicitly tell Rust where to look.

Add RUSTFLAGS=-L native=/usr/local/lib to the macOS system nng job.
Create .github/scripts/build-nng.sh to handle OS-specific NNG build
from the submodule. This reduces duplication between Linux and macOS
jobs - the script auto-detects the OS and handles:
- Install prefix (/usr on Linux, /usr/local on macOS)
- Parallel job count (nproc vs sysctl -n hw.ncpu)
- ldconfig on Linux only
Replace apt-installed libnng1/libnng-dev packages with building NNG from
the nng-sys/nng submodule. This ensures the hack job tests against the
exact NNG version tracked in the repository when checking all feature
combinations.
@flxo flxo force-pushed the nng-sys/nng-v2 branch 2 times, most recently from dde2598 to 016df71 Compare January 14, 2026 12:13
nng-sys v0.4 targets NNG v2, while nng and anng still depend on
nng-sys v0.3 (NNG v1). Running feature-powerset on the entire
workspace fails since these packages require incompatible NNG versions.

This workaround runs cargo hack on each package individually:
- nng-sys: Install NNG v2 from submodule, set NNG_DIR=/usr
- nng/anng: Use vendored NNG v1 (builds from source, no NNG_DIR needed)
@flxo flxo marked this pull request as ready for review January 14, 2026 13:44
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.github/workflows/build-configurations.yml:
- Around line 121-127: The GitHub Actions job sets RUSTFLAGS to add
/usr/local/lib but doesn't expose header search paths, so update the job's env
block (the same section that defines RUSTFLAGS) to also set either CFLAGS:
-I/usr/local/include or NNG_INCLUDE_DIR: /usr/local/include so install-nng.sh /
build.rs can find headers; modify the env map alongside RUSTFLAGS to include one
of those keys (CFLAGS or NNG_INCLUDE_DIR) to ensure header discovery on macOS.
♻️ Duplicate comments (1)
.github/workflows/build-configurations.yml (1)

61-66: Missing apt-get update before package installation.

The apt-get install command runs without a prior apt-get update, which can cause intermittent failures on GitHub runners when package indices are stale.

✏️ Suggested fix
       - name: Install dependencies
         run: |
+          sudo apt-get update
           sudo apt-get install -y ${{ matrix.apt }}
🧹 Nitpick comments (5)
.github/scripts/install-nng.sh (2)

10-16: Consider adding a fallback for CPU count detection.

If nproc or sysctl fails or is unavailable, JOBS will be empty. While make -j"" typically defaults to sequential builds, explicitly setting a fallback improves robustness.

🔧 Suggested improvement
 # OS-specific settings
 if [[ "$OSTYPE" == "darwin"* ]]; then
     PREFIX="/usr/local"
-    JOBS=$(sysctl -n hw.ncpu)
+    JOBS=$(sysctl -n hw.ncpu 2>/dev/null || echo 2)
 else
     PREFIX="/usr"
-    JOBS=$(nproc)
+    JOBS=$(nproc 2>/dev/null || echo 2)
 fi

18-20: Optional: Use Ninja for faster builds.

Since ninja-build is already installed in the workflow (line 123 of check.yml), you could leverage it for faster parallel builds.

⚡ Optional: Use Ninja generator
-cmake -DCMAKE_INSTALL_PREFIX="$PREFIX" -DBUILD_SHARED_LIBS=ON \
-      -DNNG_TESTS=OFF -DNNG_TOOLS=OFF ..
-make -j"$JOBS"
+cmake -G Ninja -DCMAKE_INSTALL_PREFIX="$PREFIX" -DBUILD_SHARED_LIBS=ON \
+      -DNNG_TESTS=OFF -DNNG_TOOLS=OFF ..
+ninja
nng-sys/build.rs (2)

75-78: Stale comment references removed features.

The comment on line 77 mentions compat and supplemental features, but these were removed as part of the NNG 2.0 upgrade. The comment should be updated to reflect the current feature set.

✏️ Suggested fix
    // 6. Regenerate bindings if they aren't guaranteed to match pre-generated ones.
    // For example, the system-provided library could be a newer or older version.
-   // We don't need to check for `compat` or `supplemental` directly here as they imply `bindgen`.
    if cfg!(feature = "bindgen") || !matches!(source, LibrarySource::Vendored) {

145-152: Consider removing debug print statement.

The println!("version: {version}") on line 146 will output to cargo build logs for every build. If this was added for debugging, consider removing it or gating it behind a verbose flag.

✏️ Suggested fix
 fn parse_version(version: &str) -> (u64, u64, u64) {
-    println!("version: {version}");
     let mut it = version.split('_');
     let major = it.next().unwrap().parse::<u64>().unwrap();
     let minor = it.next().unwrap().parse::<u64>().unwrap();
     let patch = it.next().unwrap().parse::<u64>().unwrap();
     (major, minor, patch)
 }
nng-sys/tests/tests.rs (1)

46-47: Consider asserting return values for consistency.

Other NNG calls in this test use assert_eq!(0, ...) to verify success. While socket close failures during test teardown are unlikely to cause issues, checking the return value would be consistent with the rest of the test.

✏️ Suggested fix
-            nng_socket_close(req_socket);
-            nng_socket_close(rep_socket);
+            assert_eq!(0, nng_socket_close(req_socket));
+            assert_eq!(0, nng_socket_close(rep_socket));
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e06eda and 32324ef.

📒 Files selected for processing (8)
  • .github/scripts/install-nng.sh
  • .github/workflows/build-configurations.yml
  • .github/workflows/check.yml
  • anng/Cargo.toml
  • nng-sys/Cargo.toml
  • nng-sys/build.rs
  • nng-sys/tests/tests.rs
  • nng/Cargo.toml
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: flxo
Repo: nanomsg/nng-rs PR: 34
File: nng-sys/src/bindings.rs:23-31
Timestamp: 2026-01-13T10:08:20.101Z
Learning: In NNG 2.0 (nng-sys 0.4.0+v2.0.0-alpha.6), the C header nng.h defines NNG_OPT_UDP_BOUND_PORT as a macro alias to NNG_OPT_TCP_BOUND_PORT, so both Rust constants correctly point to the same string value b"tcp-bound-port\0" in the generated bindings.
📚 Learning: 2026-01-13T10:08:20.101Z
Learnt from: flxo
Repo: nanomsg/nng-rs PR: 34
File: nng-sys/src/bindings.rs:23-31
Timestamp: 2026-01-13T10:08:20.101Z
Learning: In NNG 2.0 (nng-sys 0.4.0+v2.0.0-alpha.6), the C header nng.h defines NNG_OPT_UDP_BOUND_PORT as a macro alias to NNG_OPT_TCP_BOUND_PORT, so both Rust constants correctly point to the same string value b"tcp-bound-port\0" in the generated bindings.

Applied to files:

  • nng-sys/build.rs
🧬 Code graph analysis (1)
nng-sys/tests/tests.rs (1)
nng-sys/src/bindings.rs (2)
  • nng_init (1686-1686)
  • nng_socket_close (275-275)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: nng-sys on Windows --features vendored
  • GitHub Check: ubuntu / stable / features
🔇 Additional comments (13)
anng/Cargo.toml (1)

29-33: LGTM! Temporary workaround for the NNG v1/v2 transition.

The TODO comment clearly documents why the path dependency is commented out. This is a reasonable approach while anng still depends on nng-sys v0.3 (NNG v1) and cannot yet migrate to v0.4 (NNG v2).

nng/Cargo.toml (1)

29-33: LGTM! Consistent with the anng workaround.

Same temporary approach as anng/Cargo.toml, keeping the path dependency commented until the crate is migrated to nng-sys v0.4.

.github/workflows/check.yml (1)

123-150: Well-documented workaround for the NNG v1/v2 transition.

The extensive comments clearly explain the rationale for per-package cargo hack invocations. The workflow correctly:

  1. Installs NNG v1 system libs for nng/anng feature-powerset checks (including non-vendored combinations)
  2. Removes NNG v1 before installing NNG v2
  3. Runs nng-sys checks against NNG v2 from the submodule

The TODO on lines 130-133 provides a clear path for reverting once the migration is complete.

nng-sys/Cargo.toml (2)

18-29: Temporary workaround acknowledged, but be aware of the implications.

The detailed comment explains the Cargo limitation well. However, commenting out links = "nng" removes Cargo's protection against duplicate native library linking. During this transition period where both nng-sys 0.3 and 0.4 coexist in the workspace, ensure that:

  1. CI jobs don't accidentally link both versions in the same binary
  2. The links attribute is restored once nng and anng migrate to v0.4

The current per-package cargo-hack approach in CI (check.yml) correctly isolates the builds, so this should be safe for now.


1-17: Version bump and author addition look correct.

The version 0.4.0+v2.0.0-alpha.6 appropriately reflects the major API change (NNG 2.0) with the upstream version as build metadata. The rust-version = "1.82.0" requirement aligns with the use of unsafe extern blocks in generated bindings.

nng-sys/build.rs (2)

319-336: LGTM!

The pkg-config version bump to 2.0.0 correctly ensures system NNG discovery only succeeds for NNG 2.x installations, preventing accidental linkage against incompatible NNG 1.x libraries.


385-396: LGTM!

The MSVC workaround is well-documented with the upstream issue reference. The conditional logic correctly enables stats when either the feature is explicitly requested or when targeting MSVC to avoid the empty struct compilation error.

nng-sys/tests/tests.rs (3)

14-16: LGTM!

The nng_init(null_mut()) call is correctly added at the start of the test, fulfilling the NNG 2.0 requirement that initialization must occur before using any NNG functions.


67-73: LGTM!

The version string construction correctly incorporates NNG_RELEASE_SUFFIX using CStr::from_bytes_with_nul_unchecked. Since this is a compile-time constant from the generated bindings, the safety invariants (null-terminated, valid content) are upheld. Using to_string_lossy provides additional safety for display.


91-115: LGTM!

The patch version parsing correctly handles release suffixes (e.g., "0dev" → patch=0, suffix="dev"). The logic cleanly splits numeric and suffix portions, and the suffix comparison mirrors the construction approach for consistency.

.github/workflows/build-configurations.yml (3)

74-92: LGTM!

The explicit comment clarifies that the nng crate has not yet been upgraded to NNG v2, so this job intentionally tests against system-provided NNG 1.x. This cleanly separates testing concerns between nng-sys (NNG 2.0) and nng (NNG 1.x).


19-56: LGTM!

The build_nng matrix flag cleanly distinguishes between system NNG builds (from submodule) and vendored builds. The matrix structure is well-organized and maintainable.


137-142: LGTM!

The macOS dependency installation and conditional NNG build steps follow the same clear pattern as Linux. Homebrew's auto-update behavior means no explicit update step is needed.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@flxo flxo requested a review from jonhoo January 14, 2026 13:52
@flxo flxo merged commit 28cbe87 into nanomsg:main Jan 16, 2026
25 of 26 checks passed
@flxo flxo deleted the nng-sys/nng-v2 branch January 16, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants