Skip to contents

Checks each step of the RZig workflow in a package and reports what is present, what is missing and what would make the installation fail:

Usage

rzig_status(path, build = FALSE, lib = NULL)

Arguments

path

Path to the package root.

build

If TRUE, also compile and install the package with build_zig() when every other check passes.

lib

With build = TRUE, the library to install into; see build_zig().

Value

An object of class rzig_status: a data frame with the columns step, ok and detail, one row per check, with the attributes path, package and, with build = TRUE, build (the rzig_build object).

Details

  • DESCRIPTION: the package name and a valid version.

  • Scaffold: the files written by use_rzig(), framework sources that match the installed rzig, and executable configure and cleanup scripts. Build files that differ from the rzig templates (configure, the Makevars, entry.c, build.zig, build.zig.zon, tools/) are noted, since a package may extend them.

  • Zig source: src/rzig/src/main.zig with the registration block and the panic handler of rzig.

  • Exports: the exported functions found by scan_exports(), with every argument and return type that the boundary rejects, more than 32 arguments, misuse of rzig.Mut([]f64), error sets other than rzig.Error, and R functions of the same name elsewhere in R/. An export that masks a function of base R (for example log) is noted.

  • Bindings: whether the files written by document() match the exports.

  • Zig compiler: a compiler of a supported release series (find_zig()).

  • C toolchain: the C compiler of R, make and the R headers.

  • Build (only with build = TRUE): the result of build_zig().

Every check except the build runs in R without compiling anything.

Examples

package_path <- tempfile("rzig-status-", tmpdir = tempdir())
dir.create(package_path)
writeLines(c("Package: examplepkg", "Version: 0.0.1"),
  file.path(package_path, "DESCRIPTION"))
use_rzig(package_path)
#> Generated RZig bindings for examplepkg: 1 exported function
#> Created RZig scaffold for package examplepkg
rzig_status(package_path)
#> RZig status of package examplepkg
#>   [ok] DESCRIPTION   package examplepkg
#>                      R CMD check also requires Title, Description, License,
#>                        Authors@R
#>                      SystemRequirements does not name Zig; state the
#>                        supported series, for example "Zig 0.16.x or 0.17.x"
#>   [ok] Scaffold      build files and framework sources present
#>   [ok] Zig source    src/rzig/src/main.zig
#>   [ok] Exports       1 function: hello_zig
#>   [ok] Bindings      generated files match the exports
#>   [ok] Zig compiler  /home/runner/work/_temp/0beafb3f-08c9-475d-9a85-dbeb3ad24ddb/zig-x86_64-linux-0.16.0/zig
#>                        (version 0.16.0)
#>   [ok] C toolchain   C compiler gcc
main <- file.path(package_path, "src", "rzig", "src", "main.zig")
cat("/// @export\npub fn half(x: f32) f32 {\n    return x / 2;\n}\n",
  file = main, append = TRUE)
rzig_status(package_path)
#> RZig status of package examplepkg
#>   [ok] DESCRIPTION   package examplepkg
#>                      R CMD check also requires Title, Description, License,
#>                        Authors@R
#>                      SystemRequirements does not name Zig; state the
#>                        supported series, for example "Zig 0.16.x or 0.17.x"
#>   [ok] Scaffold      build files and framework sources present
#>   [ok] Zig source    src/rzig/src/main.zig
#>   [--] Exports       `half`, argument `x`: type f32 is not supported; use f64
#>                      `half`: return type f32 is not supported
#>   [--] Bindings      out of date: manifest.zig, R/rzig-wrappers.R, NAMESPACE,
#>                        man/half.Rd; run document()
#>   [ok] Zig compiler  /home/runner/work/_temp/0beafb3f-08c9-475d-9a85-dbeb3ad24ddb/zig-x86_64-linux-0.16.0/zig
#>                        (version 0.16.0)
#>   [ok] C toolchain   C compiler gcc
#> 2 of 7 checks failed: Exports, Bindings
unlink(package_path, recursive = TRUE)