diff --git a/lib/darwin/README.md b/lib/darwin/README.md index c70f4360..5229ac63 100644 --- a/lib/darwin/README.md +++ b/lib/darwin/README.md @@ -1,9 +1,16 @@ -### Guide build for macOS +### Guide to build for macOS +#### Install lib -1) `git clone --recurse-submodules -b master https://github.com/ton-blockchain/ton.git` -2) `mkdir build && cd build` -3) `cmake ..` -4) `cmake --build . -- target emulator` +1) `brew tap ton-blockchain/ton` +2) `brew install ton` -When you see the successful status of the build, you can find the `libemulator.dylib` file in the `build/emulator` folder. \ No newline at end of file +#### Upgrade lib + +1) brew update +2) brew reinstall ton + +When you see the successful status of the build, you can find the `libemulator.dylib` file in the `/opt/homebrew/lib` +folder. + +💡 Full information can be found at github.com/ton-blockchain/packages \ No newline at end of file diff --git a/lib/darwin/libemulator.dylib b/lib/darwin/libemulator.dylib old mode 100755 new mode 100644 index dd7edcc3..cf746c4c Binary files a/lib/darwin/libemulator.dylib and b/lib/darwin/libemulator.dylib differ diff --git a/lib/gen.go b/lib/gen.go new file mode 100644 index 00000000..ea8a29a9 --- /dev/null +++ b/lib/gen.go @@ -0,0 +1,86 @@ +//go:generate go run gen.go + +package main + +import ( + "fmt" + "log" + "os" + "os/exec" +) + +func main() { + if err := darwinDownload(); err != nil { + log.Fatalf("failed to download file for macos: %v", err) + } + if err := linuxDownload(); err != nil { + log.Fatalf("failed to download file for linux: %v", err) + } +} + +func darwinDownload() error { + const path = "/opt/homebrew/lib" + const name = "libemulator.dylib" + + log.Println("starting download lib for macos") + + initTonCmd := exec.Command("brew", "tap", "ton-blockchain/ton") + if output, err := initTonCmd.CombinedOutput(); err != nil { + return fmt.Errorf("[darwinDownload] failed to init ton: %v, output: %s", err, output) + } + + _, err := os.Stat(fmt.Sprintf("%v/%v", path, name)) + if err == nil { + log.Println("file already exist, reinstalling lib...") + reinstallCmd := exec.Command("brew", "reinstall", "ton") + if output, err := reinstallCmd.CombinedOutput(); err != nil { + return fmt.Errorf("[darwinDownload] failed to reinstall lib: %v, output: %s", err, output) + } + } else if os.IsNotExist(err) { + log.Println("file doesn't exist, installing lib...") + installCmd := exec.Command("brew", "install", "ton") + if output, err := installCmd.CombinedOutput(); err != nil { + return fmt.Errorf("[darwinDownload] failed to install lib: %v, output: %s", err, output) + } + } else { + return fmt.Errorf("failed to check file: %v", err) + } + + copyCmd := exec.Command("cp", fmt.Sprintf("%v/%v", path, name), "darwin/") + if output, err := copyCmd.CombinedOutput(); err != nil { + return fmt.Errorf("[darwinDownload] failed to copy file: %v, output: %s", err, output) + } + + log.Println("[darwinDownload] successfully update lib") + + return nil +} + +func linuxDownload() error { + const path = "/usr/lib" + const name = "libemulator.so" + + log.Println("starting download lib for linux") + + commands := [][]string{ + {"sudo", "apt-key", "adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "F6A649124520E5F3"}, + {"sudo", "add-apt-repository", "ppa:ton-foundation/ppa"}, + {"sudo", "apt", "update"}, + {"sudo", "apt", "install", "ton"}, + } + for _, command := range commands { + cmd := exec.Command(command[0], command[1:]...) + if output, err := cmd.CombinedOutput(); err != nil { + return fmt.Errorf("[linuxDownload] failed to install lib: %v, output: %s", err, output) + } + } + + copyCmd := exec.Command("cp", fmt.Sprintf("%v/%v", path, name), "linux/") + if output, err := copyCmd.CombinedOutput(); err != nil { + return fmt.Errorf("[linuxDownload] failed to copy file: %v, output: %s", err, output) + } + + log.Println("[linuxDownload] successfully update lib") + + return nil +} diff --git a/lib/lib.go b/lib/lib.go index cd932604..d42958bf 100644 --- a/lib/lib.go +++ b/lib/lib.go @@ -1,4 +1,4 @@ -package lib +package main import ( _ "github.com/tonkeeper/tongo/lib/darwin" diff --git a/lib/linux/Dockerfile b/lib/linux/Dockerfile deleted file mode 100644 index 533b599a..00000000 --- a/lib/linux/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM docker.io/library/ubuntu:20.04 AS emulator-builder -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update -RUN apt-get -y install build-essential git cmake clang libgflags-dev zlib1g-dev libssl-dev libreadline-dev libmicrohttpd-dev pkg-config libgsl-dev python3 python3-dev python3-pip libsecp256k1-dev libsodium-dev -RUN git clone --recurse-submodules -b testnet https://github.com/ton-blockchain/ton.git -RUN mkdir build && (cd build && cmake ../ton -DCMAKE_BUILD_TYPE=Release && cmake --build . --target emulator -j 6) -RUN mkdir /output && cp build/emulator/libemulator.so /output diff --git a/lib/linux/README.md b/lib/linux/README.md index d29e41be..fd62bd12 100644 --- a/lib/linux/README.md +++ b/lib/linux/README.md @@ -1,10 +1,20 @@ -## Usage +### Guide to build for Linux + +#### Install lib + +``` +sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F6A649124520E5F3 +sudo add-apt-repository ppa:ton-foundation/ppa +sudo apt update +sudo apt install ton +``` -Copy `libemulator.so` to /usr/lib or use environment variable `LD_LIBRARY_PATH` -### Build guide for Linux +When you see the successful status of the build, you can find the `libemulator.so` file in the `/opt/homebrew/lib` +folder. + +#### Usage + +Copy `libemulator.so` to /usr/lib or use environment variable `LD_LIBRARY_PATH` - cd lib/linux - docker build . -t ton-emulator - docker create --name ton-emulator ton-emulator - docker cp ton-emulator:/output/libemulator.so . +💡 Full information can be found at github.com/ton-blockchain/packages