Skip to content

Commit

Permalink
[build] Allow user to override BASE_CXXFLAGS (in addition to CXXFLAGS)
Browse files Browse the repository at this point in the history
Also rename OIL_NINJA_VERBOSE -> OILS_CXX_VERBOSE

Example command to compile with cosmoc++:

    OILS_CXX_VERBOSE=1 BASE_CXXFLAGS= _build/oils.sh ~/install/cosmocc/bin/cosmoc++ 2>err.txt

Main error now seems to be not supporting -fexceptions.

Related to issue #1760.
  • Loading branch information
Andy C committed Dec 6, 2023
1 parent 6a56330 commit 2b1baf8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
15 changes: 14 additions & 1 deletion README-native.txt
@@ -1,7 +1,8 @@
Oils for Unix
=============

This is a preview of Oil's translation to C++.
This is the pure C++ tarball for Oils. (In contrast to the "executable spec",
it has no CPython code).

To use it, run

Expand All @@ -25,3 +26,15 @@ Send feedback to:

(TODO: Replace this with INSTALL.txt)


## More build configuration

You can pass the compiler and build variant to _build/oils.sh:

_build/oils.sh ~/install/cosmocc/bin/cosmoc++ dbg

The default values are 'cxx' (c++ system compiler), and 'opt' (optimized build)

You can also override the variables documented at the top of
build/ninja-rules-cpp.sh (e.g. BASE_CXXFLAGS, CXXFLAGS)

10 changes: 9 additions & 1 deletion build/common.sh
Expand Up @@ -54,7 +54,15 @@ CXX=${CXX:-'c++'}
# - TODO(6/22): Disabled invalid-offsetof for now, but we should enable it after
# progress on the garbage collector. It could catch bugs.

BASE_CXXFLAGS='-std=c++11 -Wall -Wno-invalid-offsetof -fno-omit-frame-pointer'
# Allow user to override both BASE_CXXFLAGS and CXXFLAGS
# There doesn't seem to be a well-known convention for this. Similar to this
# question:
# - https://stackoverflow.com/questions/51606653/allowing-users-to-override-cflags-cxxflags-and-friends

default_cxx_flags='-std=c++11 -Wall -Wno-invalid-offsetof -fno-omit-frame-pointer'

# note: Use - and not :- so that BASE_CXXFLAGS= works
BASE_CXXFLAGS=${BASE_CXXFLAGS-$default_cxx_flags}

readonly PY27=Python-2.7.13

Expand Down
21 changes: 14 additions & 7 deletions build/ninja-rules-cpp.sh
Expand Up @@ -11,9 +11,10 @@
# build/ninja-rules-cpp.sh <function name>
#
# Env variables:
# CXXFLAGS= - additional flags
# OIL_NINJA_VERBOSE=1 - show command lines
# TIME_TSV_OUT=file - compile_one and link output rows to this TSV file
# BASE_CXXFLAGS= default flags passed to all compiler invocations
# CXXFLAGS= additional flags
# OILS_CXX_VERBOSE=1 show compiler command lines
# TIME_TSV_OUT=file compile_one and link output rows to this TSV file

set -o nounset
set -o errexit
Expand Down Expand Up @@ -71,7 +72,13 @@ setglobal_compile_flags() {
# flags from Ninja/shell respected
flags="$BASE_CXXFLAGS -I $REPO_ROOT $more_cxx_flags"

# flags from env respected
# Flags from env
# Similar to
# - GNU make - https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
# CXXFLAGS "Extra flags to give to the C++ compiler"
# - CMake - https://cmake.org/cmake/help/latest/envvar/CXXFLAGS.html
# "Add default compilation flags to be used when compiling CXX (C++) files."

local env_flags=${CXXFLAGS:-}
if test -n "$env_flags"; then
flags="$flags $env_flags"
Expand Down Expand Up @@ -268,7 +275,7 @@ compile_one() {

setglobal_cxx $compiler

if test -n "${OIL_NINJA_VERBOSE:-}"; then
if test -n "${OILS_CXX_VERBOSE:-}"; then
echo '__' "$cxx" $flags -o "$out" -c "$in" >&2
fi

Expand Down Expand Up @@ -299,7 +306,7 @@ link() {
prefix="benchmarks/time_.py --tsv --out $TIME_TSV_OUT --append --rusage --field link --field $out --"
fi

if test -n "${OIL_NINJA_VERBOSE:-}"; then
if test -n "${OILS_CXX_VERBOSE:-}"; then
echo "__ $prefix $cxx -o $out $@ $link_flags" >&2
fi
# IMPORTANT: Flags like -ltcmalloc have to come AFTER objects! Weird but
Expand All @@ -322,7 +329,7 @@ compile_and_link() {

setglobal_cxx $compiler

if test -n "${OIL_NINJA_VERBOSE:-}"; then
if test -n "${OILS_CXX_VERBOSE:-}"; then
echo "__ $cxx -o $out $flags $@ $link_flags" >&2
fi

Expand Down

0 comments on commit 2b1baf8

Please sign in to comment.