me

/

vinix-ports Public
382 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

Release the shared build lock when the work volume is low on space

diviocity committed 5 days ago · aeb3bff3fae35b8eae3b86f45b2ae6383ae8a7fc View patch
Unverified signature 2 files changed +27 -0
mesa/BOOTSTRAP.md +3 -0

@@ -17,6 +17,7 @@ Compile `tools/vinix-ninja.v` as `vinix-ninja` on the build host. Its default in

1717```sh

1818export VINIX_BUILD_LOCK="$worker_state/compile.lock" VINIX_BUILD_LOCK_FD=9

1919export VINIX_BUILD_SLICE_SECONDS=180

20+export VINIX_BUILD_MIN_FREE_MIB=6912

2021exec 9>>"$VINIX_BUILD_LOCK"

2122flock -x 9

2223vpac --native-build "$ports/llvm19-libs/PKGBUILD.vile" "$receipts/llvm19.manifest"

@@ -24,6 +25,8 @@ vpac --native-build "$ports/llvm19-libs/PKGBUILD.vile" "$receipts/llvm19.manifes

25

126The helper obtains the object prerequisites from Ninja’s graph and completes them in batches of eight. Once a batch exceeds the time slice, it hands the lock to waiting workers. The next batch resumes in the same verified source and build directory. Ninja rechecks the full requested dependency graph and runs the final links while holding the lock. The surrounding vpac process keeps ownership through its checks and archive creation.

227

28+`VINIX_BUILD_MIN_FREE_MIB` is an optional free-space threshold for the build filesystem. Before starting each batch or final link, the helper checks the available space. If it falls below this threshold, the helper releases the lock and checks every 30 seconds. Set the threshold above the required reserve to leave room for the next batch. The example leaves a 768 MiB margin above a 6 GiB reserve. The worker test confirmed a waiting build produced no object, a second process acquired the lock, and a build with sufficient space completed. Receipts are in `~/.local/state/vinix/ports/musl-busybox-CqkBEA/xorg/worker/ninja-free-space`.

29+

330Monitor the build log for the last completed batch. A clean wait for the lock leaves the original vpac process alive. If the process or host is terminated, preserve its logs and start a fresh native build from the pinned recipe. Use the completed manifest, verify the archive digest, then sign and install it into a clean target root before using the result.

431

532A native vpac build of libdrm 2.4.123 yielded after 8, 24 and 32 of its 53 object targets on November 30. A second process acquired the same lock between batches. The calling process still held it after vpac wrote the archive. A check with an unrelated lock file failed. The test archive SHA-256 is `caec67ab38c181231b0ded61a570cd4c8bf3cdf1ec65fc72a8a76caa6306b8bb`.

tools/vinix-ninja.v +24 -0

@@ -31,6 +31,27 @@ fn build(ninja string, directory string, targets []string) ! {

3131 }

3232}

3333

34+fn wait_for_space(fd int, directory string, minimum_mib u64) ! {

35+ if minimum_mib == 0 {

36+ return

37+ }

38+ mut reported := false

39+ for {

40+ disk := os.disk_usage(directory)!

41+ available_mib := disk.available / (1024 * 1024)

42+ if available_mib >= minimum_mib {

43+ return

44+ }

45+ if !reported {

46+ eprintln('Waiting for ${minimum_mib} MiB of free space in ${directory}; ${available_mib} MiB available.')

47+ reported = true

48+ }

49+ lock(fd, C.LOCK_UN)!

50+ time.sleep(30 * time.second)

51+ lock(fd, C.LOCK_EX)!

52+ }

53+}

54+

3455fn run(directory string, targets []string) ! {

3556 ninja := os.find_abs_path_of_executable('ninja')!

3657 shared := os.getenv('VINIX_BUILD_LOCK')

@@ -51,6 +72,7 @@ fn run(directory string, targets []string) ! {

5172 if seconds < 1 {

5273 return error('VINIX_BUILD_SLICE_SECONDS must be positive')

5374 }

75+ minimum_mib := strconv.parse_uint(os.getenv_opt('VINIX_BUILD_MIN_FREE_MIB') or { '0' }, 10, 64)!

5476 lock(fd, C.LOCK_EX)!

5577 mut query := [ninja, '-C', directory, '-t', 'inputs']

5678 query << targets

@@ -63,6 +85,7 @@ fn run(directory string, targets []string) ! {

6385 objects := inputs.output.split_into_lines().filter(it.ends_with('.o'))

6486 mut since := time.sys_mono_now()

6587 for first := 0; first < objects.len; first += 8 {

88+ wait_for_space(fd, directory, minimum_mib)!

6689 end := if first + 8 < objects.len { first + 8 } else { objects.len }

6790 build(ninja, directory, objects[first..end])!

6891 if end < objects.len && time.sys_mono_now() - since >= u64(seconds) * 1_000_000_000 {

@@ -75,6 +98,7 @@ fn run(directory string, targets []string) ! {

7598 }

7699 // Ninja rechecks every dependency and performs the requested final links.

77100 // Its caller still owns the same locked file description for packaging.

101+ wait_for_space(fd, directory, minimum_mib)!

78102 build(ninja, directory, targets)!

79103}

80104