From 6eb92e9fbc02f70603b11e87b66796c1adf72c45 Mon Sep 17 00:00:00 2001 From: Kasey Date: Tue, 12 Dec 2023 10:48:29 -0500 Subject: [PATCH] add go readme --- .github/workflows/go-assets.yml | 4 ++-- InstallGo | 7 +++---- README.go.md | 31 +++++++++++++++++++++++++++++++ README.md | 8 ++++---- build_go.sh | 15 ++------------- 5 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 README.go.md diff --git a/.github/workflows/go-assets.yml b/.github/workflows/go-assets.yml index 6ee29a98..e2c82725 100644 --- a/.github/workflows/go-assets.yml +++ b/.github/workflows/go-assets.yml @@ -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: @@ -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: diff --git a/InstallGo b/InstallGo index c8cfa3e6..3afaa0f6 100644 --- a/InstallGo +++ b/InstallGo @@ -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)" diff --git a/README.go.md b/README.go.md new file mode 100644 index 00000000..88cda3b9 --- /dev/null +++ b/README.go.md @@ -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 + diff --git a/README.md b/README.md index 399d8e27..0a4a4015 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/build_go.sh b/build_go.sh index d4d19f19..7720c95f 100755 --- a/build_go.sh +++ b/build_go.sh @@ -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" @@ -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 /\/\*\n#cgo CFLAGS: -I.\/ffi\n#cgo LDFLAGS: -liroh -L.\/ffi\n#include \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 /\/\*\n#cgo CFLAGS: -I.\/ffi\n#cgo LDFLAGS: -liroh -L.\/ffi\n#include \n\*\//" $IROH_GO_FILE else echo "Unsupported operating system: $OS"