andyarvanitis / purescript-native

A native compiler backend for PureScript (via C++ or Golang)
http://purescript.org
Other
629 stars 40 forks source link

purescript-native-go-ffi path? #35

Closed AlexMouton closed 5 years ago

AlexMouton commented 5 years ago

Hi Andy Can you clarify for me where this should be checked out when using psgo? I am getting:

src/purescript-assert/Test_Assert.go:4:2: cannot find package "Test_Assert" in any of:
    /usr/local/Cellar/go/1.11.5/libexec/src/Test_Assert (from $GOROOT)
    /Users/mouton/Documents/code/purescript/purescript-native/ps/output/src/Test_Assert (from $GOPATH)
    /Users/mouton/Documents/code/purescript/purescript-native/ps/src/Test_Assert

I have been messing with $GOPATH, so may have changed the output but I am expecting i should see src/purescript-assert/Test_Assert, or have purescript-native-ffi dir in my GOPATH?

Excuse me if this is should beobvious Thanks A

andyarvanitis commented 5 years ago

Hi Alex, thanks for trying this out and the question.

Something like the following should work.

Working directory (from which you will run your build commands):

~/Documents/code/purescript/purescript-native/ps/

Directory containing your purescript source files (working-dir/src):

~/Documents/code/purescript/purescript-native/ps/src

e.g. ~/Documents/code/purescript/purescript-native/ps/src/hello.purs

The base directory of your Go FFI source trees just go into your working directory. For example, you would do something like

$ cd working-dir
$ git clone https://github.com/andyarvanitis/purescript-native-go-ffi.git

which would result in

~/Documents/code/purescript/purescript-native/ps/purescript-native-go-ffi

which is going to look like

working-dir/purescript-native-go-ffi/README.md
working-dir/purescript-native-go-ffi/src/purescript-arrays
working-dir/purescript-native-go-ffi/src/purescript-assert
working-dir/purescript-native-go-ffi/src/purescript-console
...

You can make also your own FFI directories, just follow a similar structure and put them somewhere under your working directory. Note that there's nothing special about the purescript-native-go-ffi name.

The psgo command sets $GOPATH for you, so you shouldn't need to deal with it. It will search the directory from which you run it for .go source files in any subdirectories and then set it accordingly.

Let me know if that helps.

-andy

andyarvanitis commented 5 years ago

Also, I just made an update to psgo to make it append to any shell GOPATH (instead of replacing it), in case the user has set it for other Go libraries not under the current working directory.

AlexMouton commented 5 years ago

Ok thats all correct I think. Looking at ST:

purescript-native-go-ffi/src/purescript-st/Control_Monad_ST_Internal.go:4:2: cannot find package "Control_Monad_ST_Internal" in any of:
    /usr/local/Cellar/go/1.11.5/libexec/src/Control_Monad_ST_Internal (from $GOROOT)
    /Users/mouton/Documents/code/purescript/purescript-native/ps/output/src/Control_Monad_ST_Internal (from $GOPATH)
    /Users/mouton/Documents/code/purescript/purescript-native/ps/purescript-native-go-ffi/src/Control_Monad_ST_Internal

Is the correct path ..../ps/purescript-native-go-ffi/src or ..../ps/purescript-native-go-A ffi/src/purescript-st? Any idea where /Control_Monad_ST_Internal suffix coming from?

if i move Control_Monad_ST_Internal.go into ....src/purescript-st/Control_Monad_ST_Internal/ the error goes away.

Thanks A

andyarvanitis commented 5 years ago

I think you just need to spago install st – no need to rearrange anything. Another option is to comment out the purescript-st FFI "hook" in loader.go if your program doesn't need it right now. This is because the go FFI files have a dependency on their counterpart purescript packages (this is a Go limitation not found in the C++ backend). I plan to document this sort of thing before I announce the Go backend.

andyarvanitis commented 5 years ago

(edited) Actually, I think I know of a clean way to get rid of the counterpart dependency unless it's actually needed at runtime. I'll post here if it works well and I check it in.

AlexMouton commented 5 years ago

got it working. Needed to spago install as you said, and filter the loader.go list. thanks!