Skip to content

Commit

Permalink
cxgo: Fix remapping, make it work for local includes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Jul 2, 2023
1 parent 38570a8 commit b3cfa47
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions libs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func (c *Env) ResolveImport(name string) string {
//
// Typically, the GetLibrary function should be used instead, because it will load the library automatically, if needed.
func (c *Env) LookupLibrary(name string) *Library {
if v, ok := c.Map[name]; ok {
name = v
}
if c.NoLibs && name != BuiltinH {
return nil
}
Expand Down
12 changes: 9 additions & 3 deletions libs/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ var defPathReplacer = strings.NewReplacer(

// GetLibrary finds or initializes the library, given a C include filename.
func (c *Env) GetLibrary(name string) (*Library, bool) {
if c.NoLibs && name != BuiltinH {
return nil, false
}
if v, ok := c.Map[name]; ok {
name = v
}
if c.NoLibs && name != BuiltinH {
return nil, false
}
l, ok := c.libs[name]
if ok {
return l, true
Expand Down Expand Up @@ -231,6 +231,9 @@ func (c *Env) NewLibrary(path string) (*Library, bool) {
}

func (c *Env) TypeByName(name string) (types.Type, bool) {
if v, ok := c.Map[name]; ok {
name = v
}
if c.NoLibs && name != BuiltinH {
return nil, false
}
Expand All @@ -243,6 +246,9 @@ func (c *Env) TypeByName(name string) (types.Type, bool) {
}

func (c *Env) LibIdentByName(name string) (*Library, *types.Ident, bool) {
if v, ok := c.Map[name]; ok {
name = v
}
if c.NoLibs && name != BuiltinH {
return nil, nil, false
}
Expand Down
7 changes: 5 additions & 2 deletions vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"strings"
"time"

"github.com/gotranspile/cxgo/libs"
"modernc.org/cc/v3"

"github.com/gotranspile/cxgo/libs"
)

var timeRun = time.Now()
Expand All @@ -23,7 +24,9 @@ type includeFS struct {

func (fs includeFS) content(path string, sys bool) (string, error) {
if !sys {
return "", os.ErrNotExist
if _, ok := fs.c.Map[strings.TrimPrefix(path, libs.IncludePath+"/")]; !ok {
return "", os.ErrNotExist
}
}
l, ok := fs.c.NewLibrary(path)
if !ok {
Expand Down

0 comments on commit b3cfa47

Please sign in to comment.