Skip to content

Commit 258ce2b

Browse files
write a new gen file for updating emulator libs and update docs
1 parent 78b7625 commit 258ce2b

File tree

7 files changed

+129
-21
lines changed

7 files changed

+129
-21
lines changed

lib/darwin/README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
### Guide build for macOS
1+
### Guide to build for macOS
22

3+
#### Install lib
34

4-
1) `git clone --recurse-submodules -b master https://github.com/ton-blockchain/ton.git`
5-
2) `mkdir build && cd build`
6-
3) `cmake ..`
7-
4) `cmake --build . -- target emulator`
5+
1) `brew tap ton-blockchain/ton`
6+
2) `brew install ton`
87

9-
When you see the successful status of the build, you can find the `libemulator.dylib` file in the `build/emulator` folder.
8+
#### Upgrade lib
9+
10+
1) brew update
11+
2) brew reinstall ton
12+
13+
When you see the successful status of the build, you can find the `libemulator.dylib` file in the `/opt/homebrew/lib`
14+
folder.
15+
16+
💡 Full information can be found at github.com/ton-blockchain/packages

lib/darwin/libemulator.dylib

100755100644
1.32 MB
Binary file not shown.

lib/gen.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//go:generate go run gen.go
2+
3+
package main
4+
5+
import (
6+
"fmt"
7+
"log"
8+
"os"
9+
"os/exec"
10+
)
11+
12+
func main() {
13+
if err := darwinDownload(); err != nil {
14+
log.Fatalf("failed to download file for macos: %v", err)
15+
}
16+
if err := linuxDownload(); err != nil {
17+
log.Fatalf("failed to download file for linux: %v", err)
18+
}
19+
}
20+
21+
func darwinDownload() error {
22+
const path = "/opt/homebrew/lib"
23+
const name = "libemulator.dylib"
24+
25+
log.Println("starting download lib for macos")
26+
27+
initTonCmd := exec.Command("brew", "tap", "ton-blockchain/ton")
28+
if output, err := initTonCmd.CombinedOutput(); err != nil {
29+
return fmt.Errorf("[darwinDownload] failed to init ton: %v, output: %s", err, output)
30+
}
31+
32+
_, err := os.Stat(fmt.Sprintf("%v/%v", path, name))
33+
if err == nil {
34+
log.Println("file already exist, reinstalling lib...")
35+
reinstallCmd := exec.Command("brew", "reinstall", "ton")
36+
if output, err := reinstallCmd.CombinedOutput(); err != nil {
37+
return fmt.Errorf("[darwinDownload] failed to reinstall lib: %v, output: %s", err, output)
38+
}
39+
} else if os.IsNotExist(err) {
40+
log.Println("file doesn't exist, installing lib...")
41+
installCmd := exec.Command("brew", "install", "ton")
42+
if output, err := installCmd.CombinedOutput(); err != nil {
43+
return fmt.Errorf("[darwinDownload] failed to install lib: %v, output: %s", err, output)
44+
}
45+
} else {
46+
return fmt.Errorf("failed to check file: %v", err)
47+
}
48+
49+
copyCmd := exec.Command("cp", fmt.Sprintf("%v/%v", path, name), "darwin/")
50+
if output, err := copyCmd.CombinedOutput(); err != nil {
51+
return fmt.Errorf("[darwinDownload] failed to copy file: %v, output: %s", err, output)
52+
}
53+
54+
log.Println("[darwinDownload] successfully update lib")
55+
56+
return nil
57+
}
58+
59+
func linuxDownload() error {
60+
const path = "/usr/lib"
61+
const name = "libemulator.so"
62+
63+
log.Println("starting download lib for linux")
64+
65+
commands := [][]string{
66+
{"sudo", "apt-key", "adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "F6A649124520E5F3"},
67+
{"sudo", "add-apt-repository", "ppa:ton-foundation/ppa"},
68+
{"sudo", "apt", "update"},
69+
{"sudo", "apt", "install", "ton"},
70+
}
71+
for _, command := range commands {
72+
cmd := exec.Command(command[0], command[1:]...)
73+
if output, err := cmd.CombinedOutput(); err != nil {
74+
return fmt.Errorf("[linuxDownload] failed to install lib: %v, output: %s", err, output)
75+
}
76+
}
77+
78+
copyCmd := exec.Command("cp", fmt.Sprintf("%v/%v", path, name), "linux/")
79+
if output, err := copyCmd.CombinedOutput(); err != nil {
80+
return fmt.Errorf("[linuxDownload] failed to copy file: %v, output: %s", err, output)
81+
}
82+
83+
log.Println("[linuxDownload] successfully update lib")
84+
85+
return nil
86+
}

lib/lib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package lib
1+
package main
22

33
import (
44
_ "github.com/tonkeeper/tongo/lib/darwin"

lib/linux/Dockerfile

Lines changed: 0 additions & 7 deletions
This file was deleted.

lib/linux/README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
## Usage
1+
### Guide to build for Linux
2+
3+
#### Install lib
4+
5+
```
6+
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F6A649124520E5F3
7+
sudo add-apt-repository ppa:ton-foundation/ppa
8+
sudo apt update
9+
sudo apt install ton
10+
```
211

3-
Copy `libemulator.so` to /usr/lib or use environment variable `LD_LIBRARY_PATH`
412

5-
### Build guide for Linux
13+
When you see the successful status of the build, you can find the `libemulator.so` file in the `/opt/homebrew/lib`
14+
folder.
15+
16+
#### Usage
17+
18+
Copy `libemulator.so` to /usr/lib or use environment variable `LD_LIBRARY_PATH`
619

7-
cd lib/linux
8-
docker build . -t ton-emulator
9-
docker create --name ton-emulator ton-emulator
10-
docker cp ton-emulator:/output/libemulator.so .
20+
💡 Full information can be found at github.com/ton-blockchain/packages

lib/windows/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
### Guide to build for Windows
2+
3+
Please, be aware that multiple false positive alarms from various antivirus vendors may occur. This is an expected
4+
behaviour and there is no reason to worry.
5+
6+
#### Install lib
7+
8+
Open an elevated terminal (Run as Administrator) and execute the below command:
9+
10+
`choco install ton`
11+
12+
💡 Full information can be found at github.com/ton-blockchain/packages

0 commit comments

Comments
 (0)