Thanks to visit codestin.com
Credit goes to github.com

Skip to content

syscall.Stat_t: consider shimming os.Ctime #1047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
paralin opened this issue Aug 4, 2021 · 5 comments
Open

syscall.Stat_t: consider shimming os.Ctime #1047

paralin opened this issue Aug 4, 2021 · 5 comments

Comments

@paralin
Copy link
Contributor

paralin commented Aug 4, 2021

Such that the following code (from go-git) compiles properly without requiring a separate logic for GopherJS:

		if os, ok := sys.(*syscall.Stat_t); ok {
			// not supported on gopherjs:
			e.CreatedAt = time.Unix(int64(os.Ctime), int64(os.CtimeNsec))
                 }

Does this make sense to do?

@nevkontakte
Copy link
Member

Could you provide a broader context for this? What are the sys and os variables here? I think a small, self-contained example would be useful here. Also I would like to understand why the syscall doesn't work in the first place, I assume you are using the node-syscall extension?

@paralin
Copy link
Contributor Author

paralin commented Aug 4, 2021

paralin/go-git@d84485b

@nevkontakte
Copy link
Member

nevkontakte commented Aug 4, 2021

Yes, I saw the link GitHub helpfully added to the issue 🙂 Unfortunately, the commit by itself doesn't really answer any of my questions, for example what this sys interface{} actually is. I'd have to read go-git codebase to find that out, which is unfamiliar to me and would take awhile. If you could provide a short self-contained program that reproduces the issue it would save me a considerable amount of time.

From maintainability perspective, it's a lot better for us to invest time in making GopherJS more compatible with regular Go than to keep adding patches for the standard library. Every patch to the standard library we make means more work upgrading to the next release, which is already a time-consuming process. Hope that makes sense 🙂

@paralin
Copy link
Contributor Author

paralin commented Aug 4, 2021

@nevkontakte it builds with GOOS=js and GOARCH=wasm but if you try to build it with gopherjs you get time.Unix and os.Ctime not defined errors.

The reason why I submit this issue is because this is a case where gopherjs requires an entirely separate build flagged file for removing this call, when it's supported in wasm.

Don't we expect things that work in wasm to also build and run in gopherjs? Like syscall/js?

The function is taking the creation time from a file handle. I'll see if I can make a small repro without the rest of go git.

@nevkontakte
Copy link
Member

Oh, I think I see what's going on. I was thrown off by the variable os thinking that it has to do with the package os and being incredibly confused 😅

But now I realized that syscall.Stat_t is defined differently under for linux/amd64 and js/wasm:

// linux
type Stat_t struct {
	Dev       uint64
	Ino       uint64
	Nlink     uint64
	Mode      uint32
	Uid       uint32
	Gid       uint32
	X__pad0   int32
	Rdev      uint64
	Size      int64
	Blksize   int64
	Blocks    int64
	Atim      Timespec
	Mtim      Timespec
	Ctim      Timespec
	X__unused [3]int64
}
// js/wasm
type Stat_t struct {
	Dev       int64
	Ino       uint64
	Mode      uint32
	Nlink     uint32
	Uid       uint32
	Gid       uint32
	Rdev      int64
	Size      int64
	Blksize   int32
	Blocks    int32
	Atime     int64
	AtimeNsec int64
	Mtime     int64
	MtimeNsec int64
	Ctime     int64
	CtimeNsec int64
}

Unfortunately that probably means no easy fix. GopherJS uses the syscall extension, which calls directly to the host OS native syscalls, so under linux and macos we end up building slightly different versions of the syscall package. If we forcibly replace the definition of the struct, the syscall will simply break.

I would actually like to switch GopherJS to the js/wasm implementation of the syscall package, but it's a fairly invasive change, and it also can be breaking for GopherJS users. Attempting this was on my plan after #997, but we'll have to tread carefully. #693 is relevant here too.

However, for go-git purposes you probably can reuse its linux implementation of this function for now, since that's the syscall version GopherJS currently uses.

paralin added a commit to paralin/go-git that referenced this issue Nov 16, 2021
Adds a separate build file for wasm and gopherjs environments.

Issues filed relating to no "gopherjs" tag being set - requiring the more
awkward "js,!wasm" condition, as well as the os.Ctime incompatibility:

 - gopherjs/gopherjs#1047
 - gopherjs/gopherjs#1046

Now the "gopherjs build -v" command works in this repository.

Signed-off-by: Christian Stewart <[email protected]>
paralin added a commit to paralin/go-git that referenced this issue Mar 22, 2023
Adds a separate build file for wasm and gopherjs environments.

Issues filed relating to no "gopherjs" tag being set - requiring the more
awkward "js,!wasm" condition, as well as the os.Ctime incompatibility:

 - gopherjs/gopherjs#1047
 - gopherjs/gopherjs#1046

Now the "gopherjs build -v" command works in this repository.

Signed-off-by: Christian Stewart <[email protected]>
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

No branches or pull requests

2 participants