Skip to content

build: Vendor the nanoarrow C library - #635

Open
krlmlr wants to merge 5 commits into
mainfrom
claude/arrow-vendor-nanoarrow
Open

krlmlr wants to merge 5 commits into
mainfrom
claude/arrow-vendor-nanoarrow

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

This PR bundles the nanoarrow 0.9.0 C library in src/vendor/nanoarrow/ and compiles and links it into the package. No code calls it yet, so the PR changes no behavior. It is the groundwork for native Arrow support, coordinated in #631: the next steps can then build Arrow arrays and streams in C without a runtime dependency on the nanoarrow R package's C API.

What changes: src/vendor/nanoarrow/ holds nanoarrow.c, nanoarrow.h and nanoarrow.hpp from the CRAN sources of nanoarrow 0.9.0, plus LICENSE.txt and NOTICE.txt from the release tag apache-arrow-nanoarrow-0.9.0 and a README.md. The only delta against upstream is the line #define NANOARROW_NAMESPACE RPostgres in nanoarrow.h (upstream: RPkg), so the symbols carry an RPostgres prefix and cannot collide with the copies in nanoarrow, arrow, or RSQLite. src/Makevars.in and src/Makevars.win build vendor/nanoarrow/nanoarrow.o, link it into the shared object, and pass -DNANOARROW_DLL= so that the library's symbols stay hidden. In src/Makevars.in the object has an explicit recipe that passes $(C_VISIBILITY) and -DNANOARROW_DLL= itself, so its symbols stay hidden even without PKG_CFLAGS, which #647 drops; src/Makevars.win needs no such recipe because the Windows export list comes from $(OBJECTS) alone. The object goes through PKG_LIBS rather than OBJECTS, which keeps it out of the symbol scan that builds the Windows export list. Both Makevars files hook a step into shlib-clean that removes the object, because R CMD INSTALL --preclean removes only $(OBJECTS). src/custom.cmake adds the vendored sources and NANOARROW_DLL= for IDE builds, since the generated CMakeLists.txt lists only the top-level sources. .Rbuildignore keeps the object out of the tarball, and .covrignore keeps the vendored code out of coverage. inst/COPYRIGHTS and inst/licenses/ install the Apache-2.0 terms and NOTICE with the package. inst/COPYRIGHTS also records the bundled Boost subset, which had no record so far. DESCRIPTION gets Copyright: See file COPYRIGHTS. and lists the Apache Software Foundation as cph. The fetch path (src/PqResultImpl.*, PqColumn*, DbColumn*) is untouched.

This mirrors r-dbi/RSQLite#857, with the same layout, namespace patch, licence files and update procedure. Its review findings are applied up front: the licence and NOTICE are installed with the package, the object depends on the header in Makevars, and the README gives a verifiable update procedure. RSQLite's LGPL-2.1 compatibility question does not arise here, because RPostgres is MIT-licensed, which can be combined with Apache-2.0 code. As in RSQLite#857, LinkingTo: nanoarrow is left out for now (see the question comment below).

To update the vendored copy, follow src/vendor/nanoarrow/README.md: copy the three sources from the new nanoarrow CRAN tarball, restore the namespace line, copy the licence files to both places, then check that the diff against upstream is just the namespace line and that nm -D --defined-only src/RPostgres.so | grep -i arrow prints nothing.

Tested locally on Ubuntu 24.04 with gcc 13.3 and R 4.5.3. R CMD build and R CMD check --no-manual against a local PostgreSQL 16 gave [ FAIL 0 | WARN 0 | SKIP 11 | PASS 9182 ] and one NOTE about a hidden .git, which is the .git file of the git worktree the check ran from, not something the package ships. The tarball contains no .o file. nm -D --defined-only shows no exported symbol containing "arrow"; the 75 nanoarrow functions are present as local RPostgresArrow* symbols. The shared object grows by about 210 KB. R CMD INSTALL --preclean in the checkout recompiles nanoarrow.o, and CMake configures and compiles nanoarrow.c once the stale logging.cpp entry, which is already on main, is left out. A local merge with #647's branch also exports no arrow symbol, and R CMD check --no-manual --no-tests on it reports no PKG_*FLAGS NOTE. CI on Windows and macOS has not run yet.

Coordinated in #631. Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g

https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g


Generated by Claude Code

Bundle nanoarrow 0.9.0 in `src/vendor/nanoarrow/` and link it into the package, with no code calling it yet.
The symbols carry the `RPostgres` namespace prefix, and `-DNANOARROW_DLL=` keeps them out of the shared object's exports.
`inst/COPYRIGHTS` and `inst/licenses/` install the Apache-2.0 terms, and DESCRIPTION lists the ASF as copyright holder.
`src/vendor/nanoarrow/README.md` describes how to update the copy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Question: add LinkingTo: nanoarrow now or with the first code that needs it?

The plan for this step named LinkingTo: nanoarrow (for nanoarrow/r.h, which wraps Arrow structs in R external pointers), but r-dbi/RSQLite#857, the model for this PR, deliberately leaves it out, and nothing in this PR includes nanoarrow/r.h yet. Adding it now makes the nanoarrow R package a build-time requirement for every installation of RPostgres, from source and on CRAN, without anything using it. Leaving it out keeps this PR a pure vendoring step, and the PR that first returns an Arrow stream to R adds the LinkingTo entry together with the include. Kirill decides; if nobody decides, the PR stays as it is and the entry comes with the first user of nanoarrow/r.h.

  • Leave it out here, add it with the first code that includes nanoarrow/r.h, as RSQLite#857 does (recommended)
  • Add LinkingTo: nanoarrow in this PR

Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Question: one copy of the nanoarrow licence and NOTICE, or two?

LICENSE.txt and NOTICE.txt sit both next to the sources in src/vendor/nanoarrow/ and, as nanoarrow-LICENSE.txt and nanoarrow-NOTICE.txt, in inst/licenses/, so that they are installed with the package and ship in binaries. The same choice is open on r-dbi/RSQLite#857. Keeping both mirrors upstream's layout next to the sources, at the cost of an extra copy step in the update procedure, which includes a diff check that the copies agree. Kirill decides; if nobody decides, both copies stay.

  • Keep both copies, with the update step and its check (recommended)
  • Keep only the copies in inst/licenses/, and point to them from src/vendor/nanoarrow/README.md
  • Keep both, and add a CI step that fails when they differ

Generated by Claude Code

krlmlr and others added 2 commits November 29, 2026 11:57
`R CMD INSTALL --preclean` runs `make shlib-clean`, which removes only `$(OBJECTS)`,
so both Makevars files now hook a step into it that removes `vendor/nanoarrow/nanoarrow.o`.
`src/custom.cmake`, which the generated `CMakeLists.txt` includes,
adds the vendored sources and `NANOARROW_DLL=` for IDE builds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
The implicit rule took `-fvisibility=hidden` from `PKG_CFLAGS`,
so dropping that variable from `src/Makevars.in` would export the library's symbols.
The recipe now passes `$(C_VISIBILITY)` and `-DNANOARROW_DLL=` itself.
`src/Makevars.win` needs no change,
because the Windows export list is built from `$(OBJECTS)` only and the object is linked via `PKG_LIBS`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
Resolves the conflict in `.Rbuildignore` by keeping the entries from both sides.
The explicit recipe for `nanoarrow.o` keeps its symbols hidden
now that `main` no longer sets `PKG_CFLAGS` (#647).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

I merged main into the branch (26285aa). The only conflict was in .Rbuildignore, where I kept the entries from both sides.

#647 has since removed PKG_CFLAGS from src/Makevars.in on main, so I checked the merged build:

  • nanoarrow.o is still compiled with $(C_VISIBILITY) by its explicit recipe;
  • nm -D --defined-only shows no exported nanoarrow symbol;
  • the built tarball has no .o file;
  • R CMD check --no-tests reports only the NOTE about the worktree's .git.

Generated by Claude Code

This branch has not been deployed

No deployments
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