Skip to content

Record what an executable was built with, alongside the executable? #1238

Description

@jgabry

Record what an executable was built with, alongside the executable?

Note: While working on #1235 I was reminded of several longstanding issues. I asked Claude to turn them into reports. This body has been rewritten to reflect the design settled in #1254. The original version and the review that followed are in this issue's edit history.


CmdStanR cannot tell what produced an existing executable. The binary reports a handful of STAN_* flags via <exe> info and nothing else. The user header, the include paths and the rest of cpp_options are not reported. Anything else lives only in the R object, so it is gone in the next session.

The fix is a JSON record written beside the executable at build time, .<exe>.cmdstanr.json. This issue is the record itself; #1255 is what acts on it. The contract is #1254 §4 ("Contract: the build record"), whose recorded/compared table is the single statement of what the record holds and which fields drive a rebuild. This issue does not restate it.

The live bug this fixes

R/model.R:732-733 asks Make's question:

file.mtime(exe) < file.mtime(self$stan_file())

That is exe versus source, correct only if mtimes move monotonically forward. Extracting a project tarball over an existing build:

source content is now DIFFERENT
exe mtime : 2026-08-27 10:19:38.476
stan mtime: 2026-03-15 09:00:00.000
exe < stan (rebuild?): FALSE   <-- no rebuild

cmdstanr reports "up to date" and runs the old binary against the new source. tar -x, unzip, cp -p, rsync -a and backup restores all preserve archival mtimes and all reach this. It is filed here rather than separately because it cannot be fixed before a record exists.

Stages (#1258 holds the full stage lists)

Stage 2: schema and helper tests. Behaviour-free: nothing writes a record beside a user's program until stage 3.

Stage 3: transactional record writing.

Measurements

  • Hashing the executable: 8.5 ms, against 28.6 ms merely to spawn <exe> info.
  • Hashing six realistic source files: 0.31 ms, against a rebuild floor of 6.7 s for bernoulli.stan with precompiled headers and 13.8 s without (Design note: v1.0 compilation state and C++ options #1254 §4, "Hashes rather than mtimes").

Also settled

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions