@@ -6,12 +6,11 @@ usage() {
66 echo " usage: $0 [--platform p] [--app a] [--static] [--skip-run]"
77 exit 1
88}
9-
9+ trap ' echo aborted; exit 1 ' INT ERR
1010platform=${PLATFORM:- go}
1111application=${APPLICATION:- hello}
1212static=0
1313skip_run=0
14-
1514eval set -- " $( getopt -o " " --long platform:,app:,static,skip-run,help -- " $@ " ) "
1615if [[ $# -gt 1 ]]; then
1716 while true ; do
@@ -60,47 +59,35 @@ if [[ $# -gt 1 ]]; then
6059fi
6160platform=${platform:- go}
6261application=${application:- hello}
63-
6462platform_path=${PLATFORM_PATH:- platforms/ ${platform} }
6563app_path=${APPLICATION_PATH:- applications/ ${application} / ${platform} }
66-
67- [[ -d $platform_path && -d $app_path ]] ||
68- {
69- echo " missing dirs: $platform_path or $app_path "
70- exit 1
71- }
72- if [ ! -d " $platform_path /Lib" ]; then
73- ln -s ../../lib " $platform_path /Lib"
64+ if [[ ! -d $app_path ]]; then
65+ echo " missing dir: $app_path "
66+ exit 1
7467fi
7568if [ ! -d " $app_path /Lib" ]; then
7669 ln -s ../../../lib " $app_path /Lib"
7770fi
7871app_main=$app_path /main.roc
7972app_lib=$app_path /libapp.so
8073rm -f " $app_lib " 2> /dev/null || true
81- host_main=$platform_path /main.roc
82- host_bin=$platform_path /dynhost
83- rm -f " $host_bin " 2> /dev/null || true
84-
85- trap ' echo aborted; exit 1' INT ERR
86-
8774roc build --lib " $app_main " --output " $app_lib "
88-
89- # ------------ key fixes -----------------
90- abs_app_dir= $( realpath " $app_path " ) # compute BEFORE pushd
91- rel_app_dir= " ../applications/ ${application} / ${platform} " # runtime rpath
92- # ----------------------------------------
93-
94- pushd " $platform_path " > /dev/null
95-
96- export CGO_LDFLAGS= " -L ${abs_app_dir} -Wl,-rpath,' \$ ORIGIN/ ${rel_app_dir} ' "
97-
98- ldflags=()
99- (( static )) && ldflags=(-ldflags " -extldflags=-static " )
100-
101- go build -buildmode=pie " ${ldflags[@]} " -o " $( basename " $host_bin " ) "
102- popd > /dev/null
103- unset CGO_LDFLAGS
104-
105- roc preprocess-host " $host_bin " " $host_main " " $app_lib "
75+ abs_app_dir= $( realpath " $app_path " )
76+ rel_app_dir= " ../applications/ ${application} / ${platform} "
77+ if [[ -d " $platform_path " ]] ; then
78+ if [ ! -d " $platform_path /Lib " ] ; then
79+ ln -s ../../lib " $platform_path /Lib "
80+ fi
81+ host_main= $platform_path /main.roc
82+ host_bin= $platform_path /dynhost
83+ rm -f " $host_bin " 2> /dev/null || true
84+ pushd " $platform_path " > /dev/null
85+ export CGO_LDFLAGS= " -L ${abs_app_dir} -Wl,-rpath,' \$ ORIGIN/ ${rel_app_dir} ' "
86+ ldflags=()
87+ (( static )) && ldflags=(-ldflags " -extldflags=-static " )
88+ go build -buildmode=pie " ${ldflags[@]} " -o " $( basename " $host_bin " ) "
89+ popd > /dev/null
90+ unset CGO_LDFLAGS
91+ roc preprocess-host " $host_bin " " $host_main " " $app_lib "
92+ fi
10693(( skip_run)) || roc " $app_main "
0 commit comments