updated docs for dylib paths

This commit is contained in:
2026-02-18 20:30:54 -06:00
parent e2c26737f4
commit 777474ab4f
9 changed files with 115 additions and 72 deletions

View File

@@ -843,25 +843,51 @@ function make_c_symbol(pkg, file) {
return 'js_' + pkg_safe + '_' + file_safe + '_use'
}
// Compute the manifest path for a package (must match build.cm's manifest_path)
function dylib_manifest_path(pkg) {
var hash = content_hash(stone(blob(pkg + '\n' + 'manifest')))
return global_shop_path + '/build/' + hash
}
// Read a pre-built dylib manifest for a package.
// Returns the array of {file, symbol, dylib} or null.
function read_dylib_manifest(pkg) {
var mpath = dylib_manifest_path(pkg)
if (!fd.is_file(mpath)) return null
var content = text(fd.slurp(mpath))
if (!content || length(content) == 0) return null
return json.decode(content)
}
// Ensure all C modules for a package are built and loaded.
// Returns the array of {file, symbol, dylib} results, cached per package.
function ensure_package_dylibs(pkg) {
if (package_dylibs[pkg]) return package_dylibs[pkg]
var results = null
var build_mod = use_cache['core/build']
if (!build_mod) return null
var target = null
var c_files = null
var target = detect_host_target()
if (!target) return null
if (build_mod) {
target = detect_host_target()
if (!target) return null
var c_files = pkg_tools.get_c_files(pkg, target, true)
if (!c_files || length(c_files) == 0) {
package_dylibs[pkg] = []
return []
c_files = pkg_tools.get_c_files(pkg, target, true)
if (!c_files || length(c_files) == 0) {
package_dylibs[pkg] = []
return []
}
log.shop('ensuring C modules for ' + pkg)
results = build_mod.build_dynamic(pkg, target, 'release', {})
} else {
// No build module at runtime — read manifest from cell build
results = read_dylib_manifest(pkg)
if (!results) return null
log.shop('loaded manifest for ' + pkg + ' (' + text(length(results)) + ' modules)')
}
log.shop('ensuring C modules for ' + pkg)
var results = build_mod.build_dynamic(pkg, target, 'release', {})
package_dylibs[pkg] = results
// Preload all sibling dylibs with RTLD_LAZY|RTLD_GLOBAL
@@ -873,7 +899,6 @@ function ensure_package_dylibs(pkg) {
}
})
log.shop('built ' + text(length(results)) + ' C module(s) for ' + pkg)
return results
}