Skip to content

Commit

Permalink
[native build] Cleanup, and fix paths to osh-eval
Browse files Browse the repository at this point in the history
- Get rid of old functions
  • Loading branch information
Andy C committed May 15, 2022
1 parent 4df063f commit 7d6e646
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 256 deletions.
6 changes: 3 additions & 3 deletions benchmarks/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ readonly OIL_VERSION=$(head -n 1 oil-version.txt)

# Needed to run on flanders
readonly root=$PWD/../benchmark-data/src/oil-native-$OIL_VERSION
readonly OSH_EVAL_BENCHMARK_DATA=$root/_bin/osh_eval.opt.stripped
readonly OSH_EVAL_IN_TREE=_bin/osh_eval.opt.stripped
readonly OSH_EVAL_BENCHMARK_DATA=$root/_bin/cxx-opt/osh_eval.stripped
readonly OSH_EVAL_IN_TREE=_bin/cxx-opt/osh_eval.stripped


# NOTE: This is in {build,test}/common.sh too.
Expand Down Expand Up @@ -80,7 +80,7 @@ filter-provenance() {
# create a regex bash|dash
local pat=$(echo "$@" | sed 's/ /|/g')

# Anchor it at the end only. For _bin/osh_eval.opt.stripped and the
# Anchor it at the end only. For _bin/cxx-opt/osh_eval.stripped and the
# ../benchmark-data one.
pat="($pat)$"

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/compute.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ source benchmarks/common.sh # filter-provenance
source test/tsv-lib.sh # tsv2html

readonly BASE_DIR=_tmp/compute
readonly OSH_CC=_bin/osh_eval.opt.stripped
readonly OSH_CC=_bin/cxx-opt/osh_eval.stripped

TIMEFORMAT='%U'

Expand Down
16 changes: 8 additions & 8 deletions benchmarks/ovm-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ build-task() {
cp -v $target $bin_dir
;;

_bin/osh_eval.*)
_bin/cxx-*/osh_eval*)
case $action in
_bin/osh_eval.dbg)
local func='compile-oil-native'
_bin/cxx-dbg/osh_eval)
local func='dbg'
;;
_bin/osh_eval.opt.stripped)
local func='compile-oil-native-opt'
_bin/cxx-opt/osh_eval.stripped)
local func='opt'
;;
*)
die "Invalid target"
Expand All @@ -249,7 +249,7 @@ build-task() {
;;
esac

CXX=$cxx "${TIME_PREFIX[@]}" -- build/native.sh $func
CXX=$cxx "${TIME_PREFIX[@]}" -- _build/oil-native.sh $func

local target=$action
cp -v $target $bin_dir
Expand Down Expand Up @@ -284,8 +284,8 @@ oil-tasks() {
echo "$line" $oil_dir _bin/oil.ovm
echo "$line" $oil_dir _bin/oil.ovm-dbg

echo "$line" $oil_native_dir _bin/osh_eval.dbg
echo "$line" $oil_native_dir _bin/osh_eval.opt.stripped
echo "$line" $oil_native_dir _bin/cxx-dbg/osh_eval
echo "$line" $oil_native_dir _bin/cxx-opt/osh_eval.stripped
done
}

Expand Down
195 changes: 10 additions & 185 deletions build/native-steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,118 +107,17 @@ int main() { return 42; }
$CXX -o $dir/main $dir/main.cc
}

#
# Mutable GLOBALS
#

compile() {
### Invoked by build.ninja, and by test/cpp-unit.sh

local out=$1
shift

local flags="$CPPFLAGS"
local link_flags=''
case $out in
*.opt)
flags="$CPPFLAGS -O2 -g -D DUMB_ALLOC"
# To debug crash with 8 byte alignment
#flags="$CPPFLAGS -O0 -g -D DUMB_ALLOC -D ALLOC_LOG"
;;
*.uftrace)
# -O0 creates a A LOT more data. But sometimes we want to see the
# structure of the code.
# vector::size(), std::forward, len(), etc. are not inlined.
# Also List::List, Tuple2::at0, etc.
#local opt='-O2'
local opt='-O0'

# Do we want DUMB_ALLOC here?
flags="$CPPFLAGS $opt -g -pg"
;;
*.malloc)
flags="$CPPFLAGS -O2 -g"
;;
*.tcmalloc)
flags="$CPPFLAGS -O2 -g -D TCMALLOC"
link_flags='-ltcmalloc'
;;
*.asan)
# Note: Clang's ASAN doesn't like DUMB_ALLOC, but GCC is fine with it
flags="$CPPFLAGS -O0 -g -fsanitize=address"
;;
*.alloclog)
# debug flags
flags="$CPPFLAGS -O0 -g -D DUMB_ALLOC -D ALLOC_LOG"
;;
*.dbg)
# debug flags
flags="$CPPFLAGS -O0 -g"
;;
esac

# Hack to remove optview::Exec
case $out in
*osh_parse*)
flags="$flags -D OSH_PARSE"
;;
*osh_eval*)
flags="$flags -D OSH_EVAL"
;;
esac

# Avoid memset(). TODO: remove this hack!
flags="$flags -D NO_GC_HACK"

if false; then
# With new Clang:
# - 5.3 seconds for osh_eval.cc
# - 1.3 seconds for syntax_asdl.cc -- hm how to speed this up
# - 14ms for cpp/signal_.cc, a tiny file
# So yeah parallelizing this is good. TODO: use Ninja

mkdir -p _build/obj

local -a objects=()
for src in "$@"; do

local obj=_build/obj/$(basename $src .cc).o

echo "--- $src"

# need -fPIC for some reason
time $CXX $flags \
-fPIC \
-ftime-trace \
-I . \
-I mycpp \
-I cpp \
-I _build/cpp \
-I _devbuild/gen \
-o $obj \
-c $src \

objects=("${objects[@]}" "$obj")
done

echo "=== link ${objects[@]}"
time cc -o $out "${objects[@]}" $link_flags -lstdc++

else
# flags are split
$CXX $flags \
-I . \
-I mycpp \
-I cpp \
-I _build/cpp \
-I _devbuild/gen \
-o $out \
"$@" \
$link_flags \
-lstdc++
fi
}
cxx='' # compiler
flags='' # compile flags
link_flags='' # link flags

cxx='' # MUTABLE GLOBAL compiler
flags='' # MUTABLE GLOBAL compile flags
link_flags='' # MUTABLE GLOBAL link flags
#
# Functions to set them
#

setglobal_cxx() {
local compiler=$1
Expand All @@ -229,7 +128,6 @@ setglobal_cxx() {
esac
}


setglobal_compile_flags() {
local variant=$1
local dotd=${2:-}
Expand Down Expand Up @@ -388,80 +286,6 @@ compile-and-link() {
"$cxx" -o "$out" $flags "$@" $link_flags
}


# what osh_eval.cc needs to compile
readonly -a DEPS_CC=(
cpp/core_pyos.cc \
cpp/core_pyutil.cc \
cpp/frontend_flag_spec.cc \
cpp/frontend_match.cc \
cpp/frontend_tdop.cc \
cpp/osh_arith_parse.cc \
cpp/osh_bool_stat.cc \
cpp/pgen2_parse.cc \
cpp/pylib_os_path.cc \
_build/cpp/runtime_asdl.cc \
_build/cpp/syntax_asdl.cc \
_build/cpp/hnode_asdl.cc \
_build/cpp/id_kind_asdl.cc \
_build/cpp/consts.cc \
_build/cpp/arith_parse.cc \
_build/cpp/arg_types.cc \
cpp/dumb_alloc.cc \
cpp/fcntl_.cc \
cpp/posix.cc \
cpp/signal_.cc \
cpp/libc.cc \
)

readonly -a GC_RUNTIME=( mycpp/{gc_heap,mylib2,my_runtime}.cc )

readonly -a OLD_RUNTIME=( mycpp/{gc_heap,mylib}.cc )

compile-slice() {
### Build done outside ninja in _bin/

local name=${1:-osh_eval}
# Add -opt to make it opt
local suffix=${2:-.dbg}

shift 2

mkdir -p _bin

local -a runtime
if test -n "${GC:-}"; then
# Not ready for this yet. Need list_contains() etc.
runtime=( "${GC_RUNTIME[@]}" )
else
runtime=( "${OLD_RUNTIME[@]}" )
fi

# Note: can't use globs here because we have _test.cc
time compile _bin/$name$suffix _build/cpp/${name}.cc \
"${runtime[@]}" "${DEPS_CC[@]}" \
"$@"
}

ninja-compile() {
# Invoked by ninja (also in _bin/)

local in=$1
local out=$2

local -a runtime
if test -n "${GC:-}"; then
# Not ready for this yet. Need list_contains() etc.
runtime=( "${GC_RUNTIME[@]}" )
else
runtime=( "${OLD_RUNTIME[@]}" )
fi

# Note: can't use globs here because we have _test.cc
time compile $out $in \
"${runtime[@]}" "${DEPS_CC[@]}"
}

strip_() {
### Invoked by ninja

Expand All @@ -475,6 +299,7 @@ strip_() {
objcopy --add-gnu-debuglink=$symbols $stripped
}

# test/cpp-unit.sh sources this
if test $(basename $0) = 'native-steps.sh'; then
"$@"
fi
43 changes: 4 additions & 39 deletions build/native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,9 @@ set -o errexit

source build/common.sh # CLANGXX

#
# Wrapper functions that don't use Ninja
#

# Used by devtools/release.sh and devtools/release-native.sh
# This is the demo we're releasing to users!

# TODO: This should be a shell script generated by build/native_graph.py
compile-oil-native() {
### Invoked by benchmarks/ovm-build
build/native-steps.sh compile-slice osh_eval ''
}

compile-quickly() {
### For the fast possible development experience
CXX=$CLANGXX ninja _bin/cxx-dbg/osh_eval
}

clang-size() {
clean
CXX=$CLANGXX ninja _bin/clang-opt/osh_eval.stripped
ls -l _bin/

# Oh geez even worse; it's 2.38 MB even with --gc-sections! What happened?
}

compile-oil-native-asan() {
build/native-steps.sh compile-slice osh_eval '.asan'
}

compile-oil-native-opt() {
### Invoked by benchmarks/ovm-build

build/native-steps.sh compile-slice osh_eval '.opt'

local in=_bin/osh_eval.opt
local out=$in.stripped
strip -o $out $in
ninja _bin/clang-dbg/osh_eval
}

# Demo for the oil-native tarball.
Expand All @@ -59,9 +24,9 @@ compile-oil-native-opt() {
tarball-demo() {
mkdir -p _bin

time compile-oil-native-opt
time _build/oil-native.sh opt

local bin=_bin/osh_eval.opt.stripped
local bin=_bin/cxx-opt/osh_eval.stripped

ls -l $bin

Expand Down Expand Up @@ -100,7 +65,7 @@ osh-eval-asan() {
}

osh-eval-opt() {
### Invoked by test/parse-errors.sh
### Invoked by test/spec-cpp.sh
build/native_graph.py
ninja _bin/cxx-opt/osh_eval.stripped
}
Expand Down
5 changes: 1 addition & 4 deletions build/native_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
- for build.ninja
- _build/oil-native.sh
- Should you make a bloaty report for the separate build too?
- delete compile-slice, and replace with _build/oil-native.sh
- fix other entry points in build/native.sh
"""

from __future__ import print_function
Expand Down Expand Up @@ -218,7 +215,7 @@ def ShellFunctions(f):
print(' ### Compile %s build of oil-native' % variant, file=f)
print('', file=f)

print(' mkdir -p _build/obj/cxx-%s' % variant, file=f)
print(' mkdir -p _build/obj/cxx-%s _bin/cxx-%s' % (variant, variant), file=f)
print('', file=f)

objects = []
Expand Down
4 changes: 2 additions & 2 deletions devtools/release-native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ extract-for-benchmarks() {

# For benchmarks
pushd oil-native-$OIL_VERSION
build/native.sh compile-oil-native
build/native.sh compile-oil-native-opt
_build/oil-native.sh dbg
_build/oil-native.sh opt
popd

git add oil-native-$OIL_VERSION
Expand Down
Loading

0 comments on commit 7d6e646

Please sign in to comment.