OILS / build / native.sh View on Github | oils.pub

208 lines, 95 significant
1#!/usr/bin/env bash
2#
3# Build oils-for-unix.
4#
5# Usage:
6# build/native.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12REPO_ROOT=$(cd "$(dirname $0)/.."; pwd) # tsv-lib.sh uses this
13source build/common.sh # log
14source build/dev-shell.sh # python2
15
16# Demo for the oils-for-unix tarball.
17# Notes:
18# - Does not rely on Ninja, which is for the dev build
19# - It shouldn't require 'objcopy'
20# - TODO: do this in the Soil 'cpp' task
21
22tarball-demo() {
23 translator=${1:-mycpp}
24 mkdir -p _bin
25
26 ./configure
27
28 time _build/oils.sh --translator "$translator" --skip-rebuild
29
30 local bin
31 case $translator in
32 mycpp)
33 bin=_bin/cxx-opt-sh/oils-for-unix.stripped
34 ;;
35 *)
36 bin=_bin/cxx-opt-sh/$translator/oils-for-unix.stripped
37 ;;
38 esac
39
40 ls -l $bin
41
42 echo
43 echo "You can now run $bin. Example:"
44 echo
45
46 set -o xtrace
47
48 # TODO: Use symlink
49 $bin osh -n -c 'echo "hello $name"'
50}
51
52measure-build-times() {
53 local variant=${1:-opt}
54
55 mkdir -p _bin
56
57 ./configure
58
59 local out_tsv=_tmp/time-tarball-$variant.tsv
60
61 # Header for functions in build/ninja-rules-cpp.sh
62 benchmarks/time_.py --tsv --out $out_tsv --rusage --print-header --field verb --field out
63
64 time TIME_TSV_OUT=$out_tsv _build/oils.sh --variant "$variant"
65
66 echo
67 cat $out_tsv
68}
69
70#
71# Ninja Wrappers
72#
73
74oils-demo() {
75 local osh=${1:-bin/osh}
76
77 export PYTHONPATH='.:vendor/'
78
79 echo 'echo hi' | bin/osh_parse.py
80 bin/osh_parse.py -c 'ls -l'
81
82 # Same functionality in bin/oils-for-unix
83 echo 'echo hi' | $osh
84 $osh -n -c 'ls -l'
85 echo ---
86 # ast format is none
87 $osh --ast-format none -n -c 'ls -l'
88
89 echo '-----'
90
91 # Now test some more exotic stuff
92 $osh -c '(( a = 1 + 2 * 3 )); echo $a'
93
94 $osh -c \
95 'echo "hello"x $$ ${$} $((1 + 2 * 3)) {foo,bar}@example.com'
96
97 $osh -c 'for x in 1 2 3; do echo $x; done'
98}
99
100soil-run() {
101 local osh=_bin/cxx-asan+gcalways/osh
102 local ysh=_bin/cxx-asan+gcalways/ysh
103
104 ninja $osh $ysh
105 echo
106
107 $osh --version
108 echo
109
110 oils-demo $osh
111
112 # Regression for pnode::PNode* rooting bug in spec/ysh-bugs, which only
113 # manifests with _bin/cxx-asan+gcalways/ysh
114 $ysh -c 'var x = 42; echo $x'
115}
116
117#
118# Slices
119#
120
121slices() {
122 # Prepare for Windows / Rust?
123
124 # This works, but it imports all of core/shell.py
125 local osh_eval=_bin/cxx-asan/bin/osh_eval.mycpp
126 ninja $osh_eval
127
128 $osh_eval -c 'echo 1; echo 2'
129
130 # ~400 lines of C++ compile errors - circular dependencies
131 #
132 # I think we need something like mycpp --to-header?
133 # So we can export all the forward declarations ... But maybe we won't use
134 # them? Can we built from the bottom up
135 #
136 # core/vm.py InitUnsafeArith might be an issue
137
138 local osh_parse=_bin/cxx-asan/bin/osh_parse.mycpp
139 ninja $osh_parse
140}
141
142count-slice() {
143 # osh_parse.py: 35 files
144 # 22K lines of output
145 #
146 # others: 89 files
147 wc -l \
148 _build/NINJA/bin.osh_parse/translate.txt \
149 _build/NINJA/bin.osh_eval/translate.txt \
150 _build/NINJA/bin.oils_for_unix/translate.txt
151}
152
153check-slice() {
154 # This type checks
155 #
156 # And we pass a list of files on the mycpp command line.
157 #
158 # I think we need to generate header files though
159 #
160 # core/vm.py if TYPE_CHECKING are an issue - they are not bound by
161 # dynamic_deps.py
162 #
163 # But we should understand them
164 #
165 # Maybe we need to have a pass which computes imports and types:
166 #
167 # cppgen_pass::Decl::visit_import_from() ?
168 #
169 # Or just do the same hack as prebuilt/ for all those headers ... hm OK!
170
171 devtools/types.sh check-binary bin.osh_parse
172}
173
174install-musl() {
175 sudo apt-get install musl-tools musl-dev
176}
177
178musl-demo() {
179 mkdir -p _tmp/musl
180 pushd _tmp/musl
181
182 echo 'int main() { return 42; }' > foo.c
183
184 echo '
185#include <iostream>
186int main() {
187 std::cout << "Hi";
188 return 42;
189}
190' > cpp.cpp
191
192 musl-gcc -o foo foo.c
193
194 # Doesn't work!
195 # https://www.musl-libc.org/faq.html
196 musl-gcc -std=c++11 -o cpp cpp.cpp
197
198 set +o errexit
199 ./foo
200 echo status=$?
201
202 ./cpp
203 echo status=$?
204
205 popd
206}
207
208"$@"