Skip to content

Commit

Permalink
add go readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ramfox committed Dec 12, 2023
1 parent 304934d commit 6eb92e9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Build
run: |
source "$HOME/.cargo/env"
./build_go.sh
./build_go.sh release
- name: Upload assets
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
- name: Install uniffi-bindgen-go & Build iroh ffi
run: |
export PATH=$PATH:~/.cargo/bin/
./build_go.sh
./build_go.sh release
- name: Upload assets
uses: actions/upload-artifact@v3
with:
Expand Down
7 changes: 3 additions & 4 deletions InstallGo
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ check-processor:
.PHONY: download-and-extract
download-and-extract:
@echo "Fetching release $(VERSION) for $(REPO_NAME)..."
@echo "Would normally fetch from https://github.com/$(PROJECT_NAME)/$(REPO_NAME)/releases/download/$(VERSION)/$(GO_NAME)-$(PLATFORM)-$(PROCESSOR).tar.gz"
@echo "Would normally fetch from https://github.com/$(PROJECT_NAME)/$(REPO_NAME)/releases/download/$(VERSION)/$(GO_NAME)-$(PLATFORM)-$(PROCESSOR)"
@echo "But installing locally instead"
@cp ~/Downloads/$(GO_NAME)-$(PLATFORM)-$(PROCESSOR) .
# @curl -L -o $(TAR_FILENAME) https://github.com/$(PROJECT_NAME)/$(REPO_NAME)/releases/download/$(VERSION)/$(GO_NAME)-$(PLATFORM)-$(PROCESSOR)
@mkdir -p $(GO_NAME)/$(DIR_NAME)
@tar -xf $(GO_NAME)-$(PLATFORM)-$(PROCESSOR) -C $(GO_NAME)/$(DIR_NAME)
@tar -xf $(GO_NAME)-$(PLATFORM)-$(PROCESSOR) -C extern/$(REPO_NAME)/$(GO_NAME)/$(DIR_NAME)
@rm $(GO_NAME)-$(PLATFORM)-$(PROCESSOR)
@echo "Successfully downloaded and extracted release $(VERSION) to $(REPO_NAME)/$(GO_NAME)/$(DIR_NAME)"
@echo "Successfully downloaded and extracted release $(VERSION) to extern/$(REPO_NAME)/$(GO_NAME)/$(DIR_NAME)"
31 changes: 31 additions & 0 deletions README.go.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# iroh-go

Instructions on how to use `iroh-ffi/iroh-go` in your project!

## mac & linux

```
$ go get github.com/n0-computer/iroh-ffi/iroh-go
$ git submodule add https://github.com/n0-computer/iroh-ffi.git extern/iroh-ffi
$ make -f extern/iroh-ffi/InstallGo
$ go mod edit -replace=github.com/n0-computer/iroh-ffi/iroh-go=./extern/iroh-ffi/iroh-go
```

## windows
Currently, to use iroh-go for windows, you need to build from source.

You will need rust and cargo installed on your machine.

```
$ go get github.com/n0-computer/iroh-ffi/iroh-go
$ git submodule add https://github.com/n0-computer/iroh-ffi.git extern/iroh-ffi
$ cd extern/iroh-ffi
$ cargo install uniffi-bindgen-go --git https://github.com/NordSecurity/uniffi-bindgen-go --tag v0.2.0+v0.25.0
$ cargo build --release
$ cd ../..
$ go mod edit -replace=github.com/n0-computer/iroh-ffi/iroh-go=./extern/iroh-ffi/iroh-go
$ export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-}:extern/iroh-ffi/iroh-go/iroh"
$ export CGO_LDFLAGS="-liroh -L extern/iroh-ffi/iroh-go/iroh"
```
Then you can properly run your go commands

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ cargo install uniffi-bindgen-go --git https://github.com/NordSecurity/uniffi-bin

Build the bindings:
```
./build_go_mac.sh
./build_go.sh
```

Or build in release mode:
```
./build_go_mac.sh release
./build_go.sh release
```

#### Running
Expand All @@ -96,12 +96,12 @@ cargo install uniffi-bindgen-go --git https://github.com/NordSecurity/uniffi-bin

Build the bindings:
```
./build_go_linux.sh
./build_go.sh
```

Or in release mode:
```
./build_go_linux.sh release
./build_go.sh release
```

#### Running
Expand Down
15 changes: 2 additions & 13 deletions build_go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,8 @@

set -eu

MODE=""
DIR_NAME="debug"
if [ "$#" -eq 1 ]; then
if [[ $1 == "release" ]]; then
MODE="--release"
DIR_NAME="release"
elif [[ $1 != "debug" ]]; then
echo "Unknown mode '$1'. Options are 'release' and 'debug'. Defaults to 'debug'"
exit
fi
fi
MODE="--release"
DIR_NAME="release"

# the path to the new folder we are including
GO_DIR="./iroh-go"
Expand All @@ -38,12 +29,10 @@ OS=$(uname -s)
if [[ "$OS" == "Darwin" ]]; then
# macOS
cp "target/${DIR_NAME}/libiroh.dylib" "${INCLUDE_PATH}/libiroh.dylib"
ln -s "../libiroh.dylib" "${INCLUDE_PATH}/deps/libiroh.dylib"
sed -i '' "s/\/\/ #include <iroh.h>/\/\*\n#cgo CFLAGS: -I.\/ffi\n#cgo LDFLAGS: -liroh -L.\/ffi\n#include <iroh.h>\n\*\//" $IROH_GO_FILE
elif [[ "$OS" == "Linux" ]]; then
# Linux
cp "target/${DIR_NAME}/libiroh.so" "${INCLUDE_PATH}/libiroh.so"
ln -s "../libiroh.so" "${INCLUDE_PATH}/deps/libiroh.so"
sed -i "s/\/\/ #include <iroh.h>/\/\*\n#cgo CFLAGS: -I.\/ffi\n#cgo LDFLAGS: -liroh -L.\/ffi\n#include <iroh.h>\n\*\//" $IROH_GO_FILE
else
echo "Unsupported operating system: $OS"
Expand Down

0 comments on commit 6eb92e9

Please sign in to comment.