Skip to content

feat: add fs module and pkgindex custom module loading#21

Merged
Sunrisepeak merged 1 commit into
mainfrom
feat/fs-module-and-pkgindex-loader
May 11, 2026
Merged

feat: add fs module and pkgindex custom module loading#21
Sunrisepeak merged 1 commit into
mainfrom
feat/fs-module-and-pkgindex-loader

Conversation

@Sunrisepeak
Copy link
Copy Markdown
Member

Summary

  • Add C++ fs module to libxpkg runtime — provides fs.symlink, fs.readlink, fs.is_symlink, fs.entries, fs.files, fs.dirs, fs.copy_file, fs.mkdir_p, fs.remove, fs.remove_all, fs.basename, fs.dirname (all backed by std::filesystem)
  • Extend import() to support xim.pkgindex.* — loads .lua modules from <pkgindex>/libs/ directory, cached after first load
  • Add pkgindex_dir to ExecutionContext and set _PKGINDEX_DIR global before package loading for top-level imports

Motivation

  • Package scripts (glibc, openssl, linux-headers) need filesystem primitives like symlink creation that are missing from os.* — they currently shell out to cp -r which triggers proot path resolution bugs in sandbox mode
  • Package index maintainers need a way to share common code (e.g., sysroot header installation) across packages without duplicating logic in every .lua file

Test plan

  • 8 new unit tests (fs module: symlink, entries, files recursive, copy_file, mkdir_p/remove; pkgindex: load from libs/, caching, unknown fallback)
  • All 35 executor tests pass
  • xlings builds successfully with local libxpkg

- Add C++ fs module (register_fs_module) with symlink, readlink,
  is_symlink, exists, entries, files, dirs, copy_file, mkdir_p,
  remove, remove_all, basename, dirname
- Extend import() to support xim.pkgindex.* — loads .lua modules
  from <pkgindex>/libs/ directory with caching
- Add pkgindex_dir to ExecutionContext for hook-time module loading
- Set _PKGINDEX_DIR global before L_dofile for top-level imports
- Add tests/main.cpp (gtest entry point, was missing)
- Add 8 new tests for fs module and pkgindex module loading
@Sunrisepeak Sunrisepeak merged commit 26db04f into main May 11, 2026
1 check failed
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.

1 participant