Skip to content

add odin build/run -cached flags - #7148

Open
i-api wants to merge 3 commits into
odin-lang:masterfrom
i-api:master
Open

i-api wants to merge 3 commits into
odin-lang:masterfrom
i-api:master

Conversation

@i-api

@i-api i-api commented Jul 28, 2026

Copy link
Copy Markdown

so we have the option to reuse cached binaries if it doesn't require a rebuild. makes runs after the first much less painful now

@gingerBill lmk how you feel about this, cool / not cool?

@antisaling

Copy link
Copy Markdown
Contributor

Even if we want something like this I think you completely overlooked that we still need checking mtime for statically-linked foreign libs.

@i-api

i-api commented Aug 1, 2026

Copy link
Copy Markdown
Author

you are right

@i-api
i-api force-pushed the master branch 2 times, most recently from 8cb7adb to f537dc1 Compare August 1, 2026 18:10
@i-api

i-api commented Aug 1, 2026

Copy link
Copy Markdown
Author

pushed my static libs fix

@i-api
i-api force-pushed the master branch 7 times, most recently from c0d043e to 94e8c3e Compare August 5, 2026 03:11
@i-api

i-api commented Aug 6, 2026

Copy link
Copy Markdown
Author

@gingerBill @Kelimion please review, thanks

@i-api
i-api force-pushed the master branch 3 times, most recently from d85e187 to 0a3a668 Compare August 10, 2026 04:04
@i-api
i-api force-pushed the master branch 4 times, most recently from 346df61 to f618161 Compare August 21, 2026 14:19
@i-api
i-api marked this pull request as draft September 14, 2026 02:58
@i-api i-api changed the title add odin run -cached flag add odin build/run -cached flags Sep 14, 2026
@i-api

i-api commented Sep 14, 2026

Copy link
Copy Markdown
Author

Rebased onto current master (e7b554e) — no conflicts. Verified locally: build/run -cached hits skip codegen, flag/compiler/static-lib changes correctly invalidate, committed tests/issues cached checks all pass, and run shares the single build cache path (test rides along via the same flag registration, no test-specific logic).

@i-api

i-api commented Sep 14, 2026

Copy link
Copy Markdown
Author

@gingerBill @Kelimion this is rebased on current master and I verified it locally. Cache hits skip codegen, changing flags or the compiler or a static lib forces a rebuild, and the cached tests in tests/issues all pass. run -cached is just build -cached plus exec on the same path, and test comes along for free with no test specific logic. Ready for review when you have time. Happy to change anything, especially the rules for what counts as a cache hit.

user.name added 2 commits September 22, 2026 17:04
Reuse a previously built executable when nothing that affects it has changed.

  odin build [-cached] <dir | file.odin>
  odin run   [-cached] <dir | file.odin>
  odin test  [-cached] <dir | file.odin>

`odin run` shares the `build` entry (cache identity only); `odin test` stays
distinct via ODIN_TEST. An entry is reused only when sources (including #load
files and static foreign libs), flags, the compiler binary, and the tracked
environment are all unchanged. The cache lives in $ODIN_CACHE_DIR (else the
user cache dir) and `odin clear-cache` empties it.

Details:

* Cache dir is keyed on source paths; flags, compiler mtime, and an env
  allowlist (ODIN_*, PATH, Windows SDK/MSVC vars, DEVELOPER_DIR, SDKROOT)
  are compared via manifests. Whole-environment comparison was dropped
  (PWD/SHLVL alone caused misses).
* Publish is temp + rename per file; manifests are written only after the
  executable copy succeeds. No entry-level lock: concurrent same-entry
  builds interleave (last writer wins), so do not run them concurrently.
* Hits are always copied, never linked, so the linker cannot truncate the
  cache through the output and `odin run` deleting its output is harmless.
* clear-cache never follows symlinks (lstat on the child path; fullpath is
  realpathed and must not be used). Corrupt/zero timestamps always miss.

tests/issues covers foreign-lib, flag, and compiler invalidation, no-temp
leftovers, runnable restored output, entry survival across `odin run`,
run/build sharing, symlink escape, corrupt manifests, and SDK env changes.
The path rotation only moved the last argument forward, so e.g. odin run -cached foo.odin -file failed with got .-cached.. Scan for the first non-flag token instead; all build flags are single argv tokens, so it can only be the path. Adds flag-order cases to tests/issues/run.sh.
@i-api
i-api marked this pull request as ready for review September 23, 2026 04:55
@i-api

i-api commented Sep 24, 2026

Copy link
Copy Markdown
Author

@Kelimion @gingerBill can you take over this PR for me? Unfortunately I won't have time to shepherd this change in the coming months

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