Skip to content
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

path/filepath: Walk walks through the same dir over and over again on build with gomobile iOS #35866

Open
blockcodemagic opened this issue Nov 27, 2019 · 15 comments
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@blockcodemagic
Copy link

blockcodemagic commented Nov 27, 2019

What version of Go are you using (go version)?

$ go version
go version go1.13.4 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/macuser/Library/Caches/go-build"
GOENV="/Users/macuser/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/macuser/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Library/Golang/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Library/Golang/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/macuser/0chain/zboxcli/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/5v/kc5tdz2506gf8tgp_kyk2kx00000gp/T/go-build973215397=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Created a go library that uses filepath.Walk(). Works as expected with go application build using this library. The same library created using "gomobile bind -target=ios", with a Mac app, walks through the same dir over and over again and application crashes due to too much heap usage.

What did you expect to see?

Mac app hould work similar to go application.

What did you see instead?

Recursive call and application crash. I works well with gomobile 1.12.7

@odeke-em odeke-em changed the title filepath.Walk walks through the same dir over and over again on build with gomobile iOS path/filepath: Walk walks through the same dir over and over again on build with gomobile iOS Nov 29, 2019
@odeke-em
Copy link
Member

Thank you for this report @blockcodemagic and welcome to the Go project!

Interesting, and you say it works alright with gomobile 1.12.7 or did you mean gomobile on Go 1.12.7? This then seems like a regression and I shall kindly ping some experts @eliasnaur @randall77

@odeke-em odeke-em added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 29, 2019
@eliasnaur
Copy link
Contributor

It wasn't clear to me: does the program fail only on iOS or on macOS as well (given Go 1.13.4)?

Please supply a short program and steps to reproduce.

@blockcodemagic
Copy link
Author

I tried it only on MacOS and it fails. I will create a test program and share it.

@blockcodemagic
Copy link
Author

blockcodemagic commented Nov 30, 2019

I created a sample go library and MacOS testapp https://github.com/blockcodemagic/filepathwalk.git

Sample app tries to use walk function for users Download dir. Please let me know if you need more information.

NOTE: It works on iOS

@odeke-em
Copy link
Member

@blockcodemagic did you mean to close this issue or was that a mistake?

@blockcodemagic
Copy link
Author

Oops sorry. Thanks it was a mistake

@eliasnaur
Copy link
Contributor

Sample app tries to use walk function for users Download dir. Please let me know if you need more information.

Thank you.

NOTE: It works on iOS

I'm still confused. You say that the program does work on iOS but yet the instructions refer to gomobile bind. Can you provide the exact steps to reproduce the error, given the repository?

@blockcodemagic
Copy link
Author

blockcodemagic commented Dec 1, 2019

What I mean is, if I create an iOS project in Xcode and link the ".framework" created by gomobile with "-target ios" it works as expected. However, if I create MacOS project in Xcode and use same ".framework", then it goes into a recursive call to the same dir over and over again.

You can clone "https://github.com/blockcodemagic/filepathwalk.git" and run the project [clone dir]/testfilepath/testfilepath.xcodeproj on Xcode to see the issue.

You can modify the go file https://github.com/blockcodemagic/filepathwalk/blob/master/filepathwalk.go and create ".framework" using "gomobile bind -target ios -o filepathwalk.framework github.com/blockcodemagic/filepathwalk"

Please, let me know if you need more information.

@eliasnaur
Copy link
Contributor

I can reproduce the infinite loop, but can't explain the difference. If you're saying that the program works if you build a Go program using the library, then a way to minimize the reproducer is to cut out gomobile:

First, export a function with Cgo:

//export Walk
func Walk() {
    Walk("/home/you/Downloads")
}

Then, build your library in c-archive mode:

$ go build -o walk.a -buildmode=c-archive github.com/blockcodemagic/filepathwalk

And then see if you can get the Xcode project to link walk.a and call Walk as a C function.

See https://golang.org/cmd/cgo/#hdr-C_references_to_Go for more details on exporting Go functions to C.

@blockcodemagic
Copy link
Author

After building the library, I am having trouble linking with Xcode project. Can anybody help?

@eliasnaur
Copy link
Contributor

Please elaborate. What are the errors you see? What steps are you trying?

@blockcodemagic
Copy link
Author

I created the library as you mentioned. But don't know how to import and use it Xcode MacOs project. Also, I didn't see _cgo_export.h created as mentioned https://golang.org/cmd/cgo/#hdr-C_references_to_Go.

@eliasnaur
Copy link
Contributor

You don't need the header file, just declare

extern void Walk(void)

somewhere in your code.

As to the generated .a archive file, I believe you can drag-n-drop it into Xcode and it will include the archive in the build.

@eliasnaur
Copy link
Contributor

This issue is a possible duplicate of #35767.

@eliasnaur
Copy link
Contributor

I can still reproduce the error with the fix for #35767, so this issue does not seem to be a duplicate.

@seankhliao seankhliao added this to the Unplanned milestone Aug 27, 2022
@seankhliao seankhliao added the mobile Android, iOS, and x/mobile label Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants