Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit 1c8e998

Browse files
author
Hoyt Koepke
committed
[WIP] New build system.
Rearchitecture of the the build system. A vast simplification. Changes - ./configure can produce an XCode project of the Turi source code. - deps/ can be compiled and installed out of the regular build process. Helpful for the XCode project. - All packages in src/external/ and src/visualization compile into static libraries. - The rest of the code base compiles into a single shared library. This means that most everything occurs in one single CMakeLists.txt file using standard cmake commands. - All headers are installed into targets/include when `make install` is called. The main library is installed into targets/lib. - The code definitions that reflect compiler oddities (e.g. is std::hash<int128_t> defined) are dumped into a single header file, src/turi_common.h. All source files and headers include this file first. This allows other programs to link against this library / headers reliably. - The python part of TuriCreate now builds through the standard setup.py method. Cython / pybind11 extensions are compiled and packaged using the standard extensions mechanisms and linking against the installed Turi headers. WIP TODO: the python installation, deployment.
1 parent 038db92 commit 1c8e998

File tree

1,372 files changed

+2396
-2184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,372 files changed

+2396
-2184
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ syntax: glob
1111
debug/*
1212
release/*
1313
profile/*
14+
src/turi_common.h
1415
dist/turicreateapi*
1516
configure.deps
1617
config.log

build_python_wheel.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/bash -e
2+
3+
4+
function print_help {
5+
echo "Configures and builds a specified target."
6+
echo
7+
echo "Usage: ./build.sh [build options] [configure options]"
8+
echo
9+
echo "Common Options:"
10+
echo " --target-dir, -t The target directory to install artifact to."
11+
echo " default: `pwd`/targets."
12+
echo
13+
echo " --release Build in release mode."
14+
echo " --debug Build in debug mode (default)."
15+
echo
16+
echo " --jobs,-j The number of parallel jobs to run."
17+
echo
18+
echo " --cleanup,-c Clean up everything before building."
19+
echo
20+
echo " --skip-configure,-s Skip running ./configure."
21+
echo
22+
echo " --build-number Set build number. "
23+
echo " Defaults to part of git commit hash. "
24+
echo
25+
echo " All additional options passed through to ./configure."
26+
echo
27+
exit 1
28+
} # end of print help
29+
30+
function unknown_option {
31+
echo "Unrecognized option: $1"
32+
echo "To get help, run ./configure --help"
33+
exit 1
34+
} # end of unknown option
35+
36+
if [[ ${OSTYPE} == darwin* ]] ; then
37+
apple=1
38+
else
39+
apple=0
40+
fi
41+
42+
43+
# command flag options
44+
cleanup=0
45+
skip_configure=0
46+
jobs=4
47+
configure_options=""
48+
build_mode="release"
49+
target_dir=`pwd`/targets
50+
install_sysroot=""
51+
no_sudo=0
52+
copy_links=0
53+
build_number=`git rev-parse --short HEAD || echo "NULL"`
54+
55+
###############################################################################
56+
#
57+
# Parse command line configure flags ------------------------------------------
58+
#
59+
while [ $# -gt 0 ]
60+
do case $1 in
61+
62+
--cleanup|-c) cleanup=1;;
63+
64+
--skip-configure|-s) skip_configure=1;;
65+
66+
--copy-links) copy_links=1;;
67+
68+
--build-number=*) build_number=${1##--build-number=} ;;
69+
--build-number) build_number="$2"; shift;;
70+
71+
--target-dir=*) target_dir="${1##--target-dir=}" ;;
72+
--target-dir|-t) target_dir="$2"; shift ;;
73+
74+
--jobs=*) jobs=${1##--jobs=} ;;
75+
--jobs|-j) jobs=$2; shift ;;
76+
77+
--help) print_help; exit 0;;
78+
79+
-D) configure_options="${configure_options} -D $2"; shift ;;
80+
81+
*) configure_options="${configure_options} $1";;
82+
esac
83+
shift
84+
done
85+
86+
build_dir=`pwd`/${build_mode}
87+
src_dir=`pwd`
88+
89+
90+
echo "Setting up build:"
91+
echo "build_mode = ${build_mode}"
92+
echo "target_dir = ${target_dir}"
93+
echo "target = ${target}"
94+
echo "build_dir = ${build_dir}"
95+
96+
97+
if [[ ${cleanup} -eq 1 ]]; then
98+
./configure --cleanup --yes || exit 1
99+
fi
100+
101+
if [[ ${skip_configure} -eq 0 ]] ; then
102+
./configure ${configure_options} --with-python || exit 1
103+
else
104+
echo "skipping configure script as requested."
105+
fi
106+
107+
108+
install_dir=${target_dir}/python
109+
rm -rf ${target_dir}/python
110+
mkdir -p ${target_dir}/python
111+
112+
bash scripts/make_wheel.sh --skip_test --skip_cpp_test --build_number="$build_number" --num_procs=${jobs} --${build_mode} --target-dir="${install_dir}"

cmake/CompilerFlags.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ include(CheckCXXCompilerFlag)
22
include(CheckCCompilerFlag)
33
include(CMakeParseArguments)
44

5+
# Set a define to be dumped into turi_common.h at the end.
6+
#
7+
# A compiler source define is one that determines or switches some part of the
8+
# compilation, but isn't related to the particular build being asked for. These are dumped into
9+
# turi_common.h at the end.
10+
#
11+
macro(add_compiler_source_define FLAG)
12+
add_definitions(-D${FLAG})
13+
set(TC_COMPILER_SOURCE_DEFINES "${TC_COMPILER_SOURCE_DEFINES} ${FLAG}")
14+
endmacro()
515

616
# check_and_set_compiler_flag
717
#

cmake/CompilerOddities.cmake

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
include(CheckCXXSourceCompiles)
2+
include(CompilerFlags)
3+
24

35
macro(Set_Compiler_Specific_Flags)
46

@@ -16,7 +18,7 @@ macro(Set_Compiler_Specific_Flags)
1618

1719
if(COMPILER_HAS_IOS_BASE_FAILURE_WITH_ERROR_CODE)
1820
message(STATUS "Compiler supports ios_base::failure(str, error_code)")
19-
add_definitions(-DCOMPILER_HAS_IOS_BASE_FAILURE_WITH_ERROR_CODE)
21+
add_compiler_source_define(COMPILER_HAS_IOS_BASE_FAILURE_WITH_ERROR_CODE)
2022
else()
2123
message(STATUS "Compiler does not support ios_base::failure(str, error_code)")
2224
endif()
@@ -60,11 +62,11 @@ macro(Set_Compiler_Specific_Flags)
6062

6163
message(FATAL_ERROR "Cannot determine noexcept fladg on std::ios_base::failure. See log.")
6264
elseif(COMPILER_HAS_NOEXCEPT_WHAT_ON_EXCEPTIONS_V1)
63-
add_definitions(-DCOMPILER_MODIFIER_ON_EXCEPTION_WHAT=noexcept)
65+
add_compiler_source_define(COMPILER_MODIFIER_ON_EXCEPTION_WHAT=noexcept)
6466
elseif(COMPILER_HAS_NOEXCEPT_WHAT_ON_EXCEPTIONS_V2)
65-
add_definitions(-DCOMPILER_MODIFIER_ON_EXCEPTION_WHAT=_NOEXCEPT)
67+
add_compiler_source_define(DCOMPILER_MODIFIER_ON_EXCEPTION_WHAT=_NOEXCEPT)
6668
else()
67-
add_definitions(-DCOMPILER_MODIFIER_ON_EXCEPTION_WHAT="")
69+
add_compiler_source_define(COMPILER_MODIFIER_ON_EXCEPTION_WHAT=)
6870
endif()
6971

7072
endmacro()

configure

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ function print_help {
7878
echo
7979
echo " -D var=value Specify FLAGS definitions to be passed on to cmake."
8080
echo
81+
echo " --create-xcode-project Create an xcode project file as xcode/Turi.xcodeproj."
82+
echo
83+
echo " --build-dependencies Build the external dependencies as part of configure and install them into deps/local."
84+
echo " Needed for the xcode project build."
85+
echo
86+
echo " --skip-dependencies Skip building the dependencies."
87+
echo
8188
echo "Relevant environment variables: "
8289
echo
8390
echo " CMAKE Path to CMake executable."
@@ -153,12 +160,14 @@ with_release=1
153160
with_debug=1
154161
release_opt_for_size=0
155162
debug_opt_for_size=0
163+
create_xcode_project=0
156164
arch_list=""
157165
target=""
158166
builder="make"
159167
min_ios_version=${IOS_DEFAULT_MIN_VERSION}
160168
min_macos_version=${MACOS_DEFAULT_MIN_VERSION}
161169
enable_codesign=0
170+
build_dependencies=0
162171
list_source_files=0
163172

164173
DEBUG_DIR="${TURI_HOME}/debug"
@@ -233,6 +242,11 @@ while [ $# -gt 0 ]
233242
--min-macos-version=*) min_macos_version=${1##--min-macos-version=};;
234243
--min-macos-version) min_macos_version=${2}; shift ;;
235244

245+
--create-xcode-project) create_xcode_project=1; build_dependencies=1; builder=xcode;;
246+
247+
--build-dependencies) build_dependencies=1;;
248+
--skip-dependencies) skip_dependencies=1;;
249+
236250
--list-source-files) list_source_files=1 ;;
237251

238252
*) unknown_option $1 ;;
@@ -338,6 +352,8 @@ mkdir -p ${PWD}/deps/local/bin
338352
CCCMD=`./scripts/find_compiler.sh cc --ccache=$with_ccache --script-dir=${PWD}/deps/local/bin/`
339353
CXXCMD=`./scripts/find_compiler.sh cxx --ccache=$with_ccache --script-dir=${PWD}/deps/local/bin/`
340354

355+
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_C_COMPILER=$CCCMD -DCMAKE_CXX_COMPILER=$CXXCMD"
356+
341357
echo "Setting C compiler to $CCCMD."
342358
echo "Setting C++ compiler to $CXXCMD."
343359

@@ -349,16 +365,21 @@ CMAKE=`./scripts/find_cmake.sh`
349365
########################################################
350366
# Prepare to build
351367

368+
369+
370+
# Configuration flags that are specific to the xcode builder
371+
CMAKE_XCODE_CONFIG_FLAGS=""
372+
352373
set -e
353374
set -o pipefail
354375

355376
case $builder in
356-
xcode)
357-
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -GXcode"
358-
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=1"
377+
xcode)
378+
CMAKE_XCODE_CONFIG_FLAGS="${CMAKE_XCODE_CONFIG_FLAGS} -GXcode"
379+
CMAKE_XCODE_CONFIG_FLAGS="${CMAKE_XCODE_CONFIG_FLAGS} -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=1"
359380

360-
if [[ ! -z ${arch_list} ]] ; then
361-
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_OSX_ARCHITECTURES='${arch_list}'"
381+
if [[ ! -z ${arch_list} ]] ; then
382+
CMAKE_XCODE_CONFIG_FLAGS="${CMAKE_XCODE_CONFIG_FLAGS} -DCMAKE_OSX_ARCHITECTURES='${arch_list}'"
362383
fi
363384

364385
;;
@@ -377,11 +398,11 @@ if [[ ${enable_codesign} == 1 ]] ; then
377398

378399
elif [[ ${builder} == xcode ]] ; then
379400

380-
# Deal with the code signing issues.
381-
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY= -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=0 -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM= "
401+
# Deal with the code signing issues.
402+
CMAKE_XCODE_CONFIG_FLAGS="${CMAKE_XCODE_CONFIG_FLAGS} -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY= -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=0 -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM= "
382403

383404
# This also requires us to skip the code signing when trying to compile targets to check definitions.
384-
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY"
405+
CMAKE_XCODE_CONFIG_FLAGS="${CMAKE_XCODE_CONFIG_FLAGS} -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY"
385406

386407
echo "Skipping code signing."
387408
fi
@@ -429,22 +450,41 @@ if [[ ${build_platform} == macosx ]] ; then
429450
fi
430451
fi
431452

432-
build_cmd="$CMAKE \
433-
$GENERATOR \
434-
-D CMAKE_C_COMPILER=$CCCMD \
435-
-D CMAKE_CXX_COMPILER=$CXXCMD \
436-
${CMAKE_CONFIG_FLAGS}"
437-
438-
if [[ $with_debug == 1 ]] ; then
439-
set -x
440-
mkdir -p ${DEBUG_DIR}
441-
cd ${DEBUG_DIR} && $build_cmd -DCMAKE_BUILD_TYPE=Debug --config Debug -D CMAKE_CONFIGURATION_TYPES='Debug;Release' ${TURI_HOME}
442-
set +x
453+
if [[ $build_dependencies == 1 ]] ; then
454+
455+
# Build the dependencies through the make build scripts so they don't have to
456+
# be part of the XCode project, which doesn't work.
457+
458+
deps_build_dir=${TURI_HOME}/deps/build
459+
mkdir -p $deps_build_dir
460+
cd ${deps_build_dir}
461+
$CMAKE ${CMAKE_CONFIG_FLAGS} -DCMAKE_BUILD_TYPE=Release --config Release ${TURI_HOME}
462+
make external_dependencies
463+
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DTC_EXTERNAL_DEPS_PREBUILT=1"
464+
else
465+
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DTC_EXTERNAL_DEPS_PREBUILT=0"
443466
fi
444467

445-
if [[ $with_release == 1 ]] ; then
446-
set -x
447-
mkdir -p ${RELEASE_DIR}
448-
cd ${RELEASE_DIR} && $build_cmd -DCMAKE_BUILD_TYPE=Release -D CMAKE_CONFIGURATION_TYPES='Release;Debug' --config Release ${TURI_HOME}
449-
set +x
468+
469+
if [[ $create_xcode_project == 1 ]] ; then
470+
xcode_proj_dir=${TURI_HOME}/xcode/
471+
mkdir -p $xcode_proj_dir
472+
cd ${xcode_proj_dir}
473+
$CMAKE ${CMAKE_CONFIG_FLAGS} ${CMAKE_XCODE_CONFIG_FLAGS} -DTC_EXTERNAL_DEPS_PREBUILT=1 -DCMAKE_BUILD_TYPE=Debug --config Debug -D CMAKE_CONFIGURATION_TYPES='Debug;Release' ${TURI_HOME}
474+
475+
else
476+
if [[ $with_debug == 1 ]] ; then
477+
set -x
478+
mkdir -p ${DEBUG_DIR}
479+
cd ${DEBUG_DIR} && $CMAKE ${CMAKE_CONFIG_FLAGS} ${CMAKE_XCODE_CONFIG_FLAGS} -DCMAKE_BUILD_TYPE=Debug --config Debug -D CMAKE_CONFIGURATION_TYPES='Debug;Release' ${TURI_HOME}
480+
set +x
481+
fi
482+
483+
if [[ $with_release == 1 ]] ; then
484+
set -x
485+
mkdir -p ${RELEASE_DIR}
486+
cd ${RELEASE_DIR} && $CMAKE ${CMAKE_CONFIG_FLAGS} ${CMAKE_XCODE_CONFIG_FLAGS} -DCMAKE_BUILD_TYPE=Release -D CMAKE_CONFIGURATION_TYPES='Release;Debug' --config Release ${TURI_HOME}
487+
set +x
488+
fi
450489
fi
490+

0 commit comments

Comments
 (0)