Skip to content

Commit

Permalink
write a new gen file for updating emulator libs and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhar-petukhov committed Mar 25, 2024
1 parent 78b7625 commit 136d03d
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 21 deletions.
19 changes: 13 additions & 6 deletions lib/darwin/README.md
Original file line number Diff line number Diff line change
@@ -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.
#### 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
Binary file modified lib/darwin/libemulator.dylib
100755 → 100644
Binary file not shown.
86 changes: 86 additions & 0 deletions lib/gen.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion lib/lib.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lib
package main

import (
_ "github.com/tonkeeper/tongo/lib/darwin"
Expand Down
7 changes: 0 additions & 7 deletions lib/linux/Dockerfile

This file was deleted.

24 changes: 17 additions & 7 deletions lib/linux/README.md
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 136d03d

Please sign in to comment.