comparison service/iot2/tasks.py @ 1490:455b1b80516e

introduce capnp, more build, some demos Ignore-this: 29801e9e9f8a85fd0d822207c6eacce1 darcs-hash:b2da18876d27b0fb9192811375752b5c4e7322e0
author drewp <drewp@bigasterisk.com>
date Thu, 23 Jan 2020 21:00:47 -0800
parents a4fb4cc60ae1
children ae8ad2b758e2
comparison
equal deleted inserted replaced
1489:a4fb4cc60ae1 1490:455b1b80516e
1 from invoke import task 1 from invoke import task
2 from pathlib import Path 2 from pathlib import Path
3 3
4 PY_ENV = f'build/py'
5 NIM_ENV = f'build/nim'
6 NIM_BIN = f'{NIM_ENV}/bin'
7 PY_SITE_PACKAGES = f'{PY_ENV}/lib/python3.7/site-packages'
8 SOME_PY_DEP = Path(f'{PY_SITE_PACKAGES}/standardservice')
9
4 @task 10 @task
5 def nim_install(ctx): 11 def nim_install(ctx):
6 if Path('nim-1.0.4/bin/nim').exists(): 12 if Path(f'{NIM_BIN}/nim').exists():
7 return 13 return
8 ctx.run(f'curl https://nim-lang.org/download/nim-1.0.4-linux_x64.tar.xz | xz -dc | tar x') 14 ctx.run(f'curl https://nim-lang.org/download/nim-1.0.4-linux_x64.tar.xz | '
15 f'xz -dc | '
16 f'tar --extract --strip-components=1 --one-top-level={NIM_ENV}')
9 17
10 @task 18 @task
11 def py_install(ctx): 19 def py_install(ctx):
12 if Path('env/bin/python').exists(): 20 if Path(f'{PY_ENV}/bin/python').exists():
13 return 21 return
14 ctx.run(f'mkdir -p env') 22 ctx.run(f'mkdir -p {PY_ENV}')
15 ctx.run(f'virtualenv -p /usr/bin/python3.7 env') 23 ctx.run(f'virtualenv -p /usr/bin/python3.7 {PY_ENV}')
24 # now .../wheel is newer than requirements.txt
16 25
17 @task(pre=[py_install]) 26 @task(pre=[py_install])
18 def py_deps(ctx): 27 def py_deps(ctx):
19 pip_install_ran = Path('env/lib/python3.7/site-packages/wheel').stat().st_mtime 28 pip_install_ever_ran = SOME_PY_DEP.exists()
29 pip_install_last_ran = Path(f'{PY_SITE_PACKAGES}/wheel').stat().st_mtime
20 requirements = Path('requirements.txt').stat().st_mtime 30 requirements = Path('requirements.txt').stat().st_mtime
21 if pip_install_ran > requirements: 31 if pip_install_ever_ran and pip_install_last_ran > requirements:
22 return 32 return
23 ctx.run(f'env/bin/pip install --quiet --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple -r requirements.txt') 33 ctx.run(f'{PY_ENV}/bin/pip install '
34 #f'--quiet '
35 f'--index-url https://projects.bigasterisk.com/ '
36 f'--extra-index-url https://pypi.org/simple '
37 f'-r requirements.txt')
24 38
25 @task(pre=[nim_install]) 39 @task(pre=[nim_install])
26 def nim_deps(ctx): 40 def nim_deps(ctx):
27 pkgs = ['nimpy-0.1.0'] 41 pkgs = [('nimpy', 'nimpy-0.1.0'),
28 if all(Path(f'~/.nimble/pkgs/{pkg}').expanduser().exists() for pkg in pkgs): 42 ('https://github.com/avsej/capnp.nim.git', 'capnp-0.0.3'),
43 ]
44 if all(Path(f'~/.nimble/pkgs/{pkg[1]}').expanduser().exists() for pkg in pkgs):
29 return 45 return
30 plain_names = ' '.join(p.split('-')[0] for p in pkgs) 46 plain_names = ' '.join(p[0] for p in pkgs)
31 ctx.run(f'nim-1.0.4/bin/nimble install {plain_names}', pty=True) 47 ctx.run(f'{NIM_BIN}/nimble install -y {plain_names}', pty=True)
48 ctx.run(f'ln -s ~/.nimble/bin/capnpc ~/.nimble/bin/capnpc-nim')
32 49
33 50
34 @task(pre=[nim_install]) 51 @task(pre=[nim_deps])
35 def nim_build_x86(ctx): 52 def nim_build_x86(ctx):
36 ctx.run(f'nim-1.0.4/bin/nim c --out:iot2_linux_x86 iot2_linux.nim', pty=True) 53 ctx.run(f'{NIM_BIN}/nim compile '
54 f'--out:build/iot2_linux_x86 '
55 f'iot2_linux.nim',
56 pty=True)
37 57
38 @task 58 @task
39 def arm_cross_compiler_install(ctx): 59 def arm_cross_compiler_install(ctx):
60 if Path('/usr/share/crossbuild-essential-armhf/list').exists():
61 return
40 ctx.run(f'sudo apt install -y crossbuild-essential-armhf', pty=True) 62 ctx.run(f'sudo apt install -y crossbuild-essential-armhf', pty=True)
41 63
42 @task(pre=[nim_install]) 64 @task(pre=[arm_cross_compiler_install, nim_install])
43 def nim_build_arm(ctx): 65 def nim_build_arm(ctx):
44 ctx.run(f'nim-1.0.4/bin/nim c --cpu:arm --out:iot2_linux_arm iot2_linux.nim', pty=True) 66 ctx.run(f'{NIM_BIN}/nim compile '
67 f'--cpu:arm '
68 f'--out:build/iot2_linux_arm '
69 f'iot2_linux.nim',
70 pty=True)
45 71
46 @task(pre=[py_deps, nim_build_x86]) 72 @task(pre=[py_deps, nim_build_x86])
47 def local_run(ctx): 73 def local_run(ctx):
48 ctx.run(f'./iot2_linux_x86') 74 ctx.run(f'build/iot2_linux_x86')
75
76 @task
77 def nim_build_esp32(ctx):
78 ctx.run(f'{NIM_BIN}/nim compile '
79 f'--cpu:arm '
80 f'--os:standalone '
81 #f'--deadCodeElim:on '
82 # --gc:refc|v2|markAndSweep|boehm|go|none|regions
83 f'--gc:stack '
84 f'--compileOnly:on '
85 f'--noMain '
86 f'--nimcache:build/nimcache '
87 f'--embedsrc:on '
88 f'--verbosity:3 '
89 #f'-d:release '
90 f'iot2_esp32.nim')
91 ctx.run(f'')
92
93 @task
94 def install_nim_capnp(ctx):
95 ctx.run(f'git clone git@github.com:drewp/capnp.nim.git build/capnp.nim')
96 ctx.run(f'cd build/capnp.nim; ./build.sh')
97 ctx.run(f'cd build/capnp.nim; bin/nim c capnp/capnpc.nim')
98
99 @task
100 def messages_build_nim(ctx):
101 ctx.run(f'capnp compile -o ./build/capnp.nim/capnp/capnpc messages.capnp > build/messages.nim')
49 102
50 103
51 # pack this into docker for pushing to Pi 104 # pack this into docker for pushing to Pi
52 105
53 # apt install -y sshfs 106 # apt install -y sshfs