feat(modules): embed built-in modules in the binary (#316)

modules loaded only from an exe-adjacent modules/ dir or ~/.config, so a
bare `go install`ed binary shipped zero modules. embed the modules/ tree
and fall back to it when no filesystem builtin dir is found.

the on-disk builtin dir and the user-override dir still take precedence,
so a dev tree and a release that ships the folder alongside the binary
keep working unchanged. the embed directive lives at the repo root
because go:embed cannot reach a parent directory, and it registers the
filesystem with the loader through a package hook to avoid an import
cycle back into the root package.
This commit is contained in:
Tigah
2026-07-22 12:51:20 -07:00
committed by GitHub
parent f570dceadc
commit 356b16fc63
3 changed files with 99 additions and 1 deletions
+40
View File
@@ -0,0 +1,40 @@
/*
·━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━·
: :
: █▀ █ █▀▀ · Blazing-fast pentesting suite :
: ▄█ █ █▀ · BSD 3-Clause License :
: :
: (c) 2022-2026 vmfunc, xyzeva, :
: lunchcat alumni & contributors :
: :
·━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━·
*/
package sif
import (
"embed"
"io/fs"
"github.com/charmbracelet/log"
"github.com/vmfunc/sif/internal/modules"
)
// builtinModules embeds the module tree into the binary. this file lives at the
// repo root because go:embed cannot reference a parent directory, and modules/
// sits above internal/modules where the loader lives.
//
//go:embed modules
var builtinModules embed.FS
// register the embedded modules with the loader once, rooted at the modules
// directory so paths match the on-disk layout. the loader only uses this as a
// fallback when no filesystem modules/ dir is present.
func init() {
sub, err := fs.Sub(builtinModules, "modules")
if err != nil {
log.Debugf("embedded modules unavailable: %v", err)
return
}
modules.SetBuiltinFS(sub)
}