Compare commits
4 Commits
a8d8de611a
...
639d340f46
Author | SHA1 | Date |
---|---|---|
Sameer Rahmani | 639d340f46 | |
Sameer Rahmani | a98065c2f9 | |
Sameer Rahmani | 892117b010 | |
Sameer Rahmani | 1d26409923 |
|
@ -99,6 +99,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||||
-Wdouble-promotion
|
-Wdouble-promotion
|
||||||
-Wformat=2)
|
-Wformat=2)
|
||||||
|
|
||||||
|
add_link_options(-fuse-ld=lld)
|
||||||
# if ((SERENE_USE_LIBCXX) AND (NOT (SERENE_TOOLCHAIN_PATH)))
|
# if ((SERENE_USE_LIBCXX) AND (NOT (SERENE_TOOLCHAIN_PATH)))
|
||||||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -v")
|
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -v")
|
||||||
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
|
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
|
||||||
|
|
35
builder
35
builder
|
@ -120,16 +120,6 @@ export LSAN_OPTIONS
|
||||||
source "$ME/scripts/deps.sh"
|
source "$ME/scripts/deps.sh"
|
||||||
|
|
||||||
|
|
||||||
CMAKEARGS_DEBUG=(
|
|
||||||
"-DCMAKE_BUILD_TYPE=Debug"
|
|
||||||
)
|
|
||||||
|
|
||||||
CMAKEARGS=(
|
|
||||||
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
|
|
||||||
"-DSERENE_CCACHE_DIR=$HOME/.ccache"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Initialization
|
# Initialization
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
@ -166,8 +156,15 @@ function popd_build() {
|
||||||
function build-gen() {
|
function build-gen() {
|
||||||
pushed_build
|
pushed_build
|
||||||
info "Running: "
|
info "Running: "
|
||||||
info "cmake -G Ninja" "$ME" "${CMAKEARGS[*]} ${CMAKEARGS_DEBUG[*]}" "$@"
|
info "cmake -G Ninja" -C "$ME/cmake/caches/serene_$1.cmake" "$ME" "${@:2}"
|
||||||
cmake -G Ninja "$ME" "${CMAKEARGS[@]}" "${CMAKEARGS_DEBUG[@]}" "$@"
|
cmake -G Ninja \
|
||||||
|
-DSERENE_CONFIG_HOME="$SERENE_HOME_DIR" \
|
||||||
|
-DLLVM_VERSION="$LLVM_VERSION" \
|
||||||
|
-DBDWGC_VERSION="$BDWGC_VERSION" \
|
||||||
|
-DMUSL_VERSION="$MUSL_VERSION" \
|
||||||
|
-C "$ME/cmake/caches/serene_$1.cmake" \
|
||||||
|
"$ME" \
|
||||||
|
"${@:2}"
|
||||||
popd_build
|
popd_build
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +186,7 @@ function build() { ## Builds the project by regenerating the build scripts
|
||||||
local cpus
|
local cpus
|
||||||
|
|
||||||
rm -rf "$BUILD_DIR"
|
rm -rf "$BUILD_DIR"
|
||||||
build-gen "$@"
|
build-gen "dev" "$@"
|
||||||
pushed_build
|
pushed_build
|
||||||
|
|
||||||
cpus=$(nproc)
|
cpus=$(nproc)
|
||||||
|
@ -200,7 +197,7 @@ function build() { ## Builds the project by regenerating the build scripts
|
||||||
function build-20() { ## Builds the project using C++20 (will regenerate the build)
|
function build-20() { ## Builds the project using C++20 (will regenerate the build)
|
||||||
rm -rf "$BUILD_DIR"
|
rm -rf "$BUILD_DIR"
|
||||||
pushed_build
|
pushed_build
|
||||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCPP_20_SUPPORT=ON "$@" "$ROOT_DIR"
|
build-gen "dev" -DCPP_20_SUPPORT=ON "$@"
|
||||||
cmake --build .
|
cmake --build .
|
||||||
popd_build
|
popd_build
|
||||||
}
|
}
|
||||||
|
@ -212,7 +209,7 @@ function build-tidy() { ## Builds the project using clang-tidy (It takes longer
|
||||||
function build-release() { ## Builds the project in "Release" mode
|
function build-release() { ## Builds the project in "Release" mode
|
||||||
rm -rf "$BUILD_DIR"
|
rm -rf "$BUILD_DIR"
|
||||||
pushed_build
|
pushed_build
|
||||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release "${CMAKEARGS[@]}" "$ROOT_DIR"
|
build-gen "prod" "$@"
|
||||||
cmake --build . --config Release
|
cmake --build . --config Release
|
||||||
popd_build
|
popd_build
|
||||||
}
|
}
|
||||||
|
@ -221,8 +218,8 @@ function build-docs() { ## Builds the documentation of Serene
|
||||||
rm -rf "$BUILD_DIR"
|
rm -rf "$BUILD_DIR"
|
||||||
pip install -r "$ME/docs/requirements.txt"
|
pip install -r "$ME/docs/requirements.txt"
|
||||||
pushed_build
|
pushed_build
|
||||||
cmake -G Ninja -DSERENE_ENABLE_DOCS=ON "$ROOT_DIR"
|
build-gen "dev" -DSERENE_ENABLE_DOCS=ON "$@"
|
||||||
cmake --build .
|
cmake --build . --parallel
|
||||||
popd_build
|
popd_build
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,8 +269,8 @@ function tests() { ## Runs all the test cases
|
||||||
function build-tests() { ## Generates and build the project including the test cases
|
function build-tests() { ## Generates and build the project including the test cases
|
||||||
rm -rf "$BUILD_DIR"
|
rm -rf "$BUILD_DIR"
|
||||||
pushed_build
|
pushed_build
|
||||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DSERENE_BUILD_TESTING=ON "$ROOT_DIR"
|
build-gen "dev" -DSERENE_BUILD_TESTING=ON "$@"
|
||||||
cmake --build .
|
cmake --build . --parallel
|
||||||
popd_build
|
popd_build
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
# Serene Programming Language
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019-2023 Sameer Rahmani <lxsameer@gnu.org>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, version 2.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# This file sets up a CMakeCache to build serene for development
|
||||||
|
|
||||||
|
# Where to find the packages. Packages can be built from source
|
||||||
|
# or downloaded via the builder script.
|
||||||
|
message(STATUS "[SERENE] SET THE CONFIG DIR TO: ${SERENE_CONFIG_HOME}")
|
||||||
|
|
||||||
|
set(SERENE_PKG_DIR "${SERENE_CONFIG_HOME}/env")
|
||||||
|
|
||||||
|
set(SERENE_LLVM_DIR "${SERENE_PKG_DIR}/llvm.${LLVM_VERSION}"
|
||||||
|
CACHE STRING "Where to find the llvm installation.")
|
||||||
|
set(SERENE_LLVM_BIN "${SERENE_LLVM_DIR}/bin")
|
||||||
|
|
||||||
|
if(EXISTS ${SERENE_LLVM_DIR})
|
||||||
|
message(STATUS "Setting LLVM DIR to: '${SERENE_LLVM_DIR}'")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Can't find the LLVM dir at: '${SERENE_LLVM_DIR}'")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Setting the PATH env var to include the bin dir from the LLVM build
|
||||||
|
# this is the same as `export PATH="blah/:$PATH". it will not propegate
|
||||||
|
# to the host shell.
|
||||||
|
set(ENV{PATH} "${SERENE_LLVM_BIN}:$ENV{PATH}")
|
||||||
|
|
||||||
|
set(CMAKE_C_COMPILER "${SERENE_LLVM_BIN}/clang" CACHE PATH "")
|
||||||
|
set(CMAKE_CXX_COMPILER "${SERENE_LLVM_BIN}/clang++" CACHE PATH "")
|
||||||
|
|
||||||
|
# The name of this variable has to be like this(a mix of upper and
|
||||||
|
# lower case letters). That's due to the package name and it is not
|
||||||
|
# a mistake
|
||||||
|
set(BDWgc_DIR "${SERENE_PKG_DIR}/bdwgc.${BDWGC_VERSION}")
|
||||||
|
|
||||||
|
set(MUSL_DIR "${SERENE_PKG_DIR}/musl.${MUSL_VERSION}/" CACHE PATH "")
|
||||||
|
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "")
|
||||||
|
set(SERENE_CCACHE_DIR "$ENV{HOME}/.ccache" CACHE STRING "")
|
||||||
|
set(CMAKE_BUILD_TYPE "Debug")
|
|
@ -164,42 +164,35 @@ function info_bdwgc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function build_musl() {
|
function build_musl() {
|
||||||
local version
|
local version repo src install_dir build_dir
|
||||||
local repo
|
|
||||||
local src
|
|
||||||
|
|
||||||
version="$MUSL_VERSION"
|
version="$MUSL_VERSION"
|
||||||
|
install_dir="$DEPS_BUILD_DIR/musl.$version"
|
||||||
|
build_dir="$DEPS_BUILD_DIR/musl_build.$version"
|
||||||
repo="${MUSL_REPO:-git://git.musl-libc.org/musl}"
|
repo="${MUSL_REPO:-git://git.musl-libc.org/musl}"
|
||||||
src="$DEPS_SOURCE_DIR/$MUSL_DIR_NAME.$version"
|
src="$DEPS_SOURCE_DIR/musl.$version"
|
||||||
|
|
||||||
clone_dep "$repo" "$version" "$src"
|
clone_dep "$repo" "$version" "$src"
|
||||||
|
|
||||||
info "Building musl version '$version'..."
|
info "Building musl version '$version'..."
|
||||||
if [[ -d "$MUSL_BUILD_DIR.$version" ]]; then
|
if [[ -d "$build_dir" ]]; then
|
||||||
warn "A build dir for 'musl' already exists at '$MUSL_BUILD_DIR.$version'"
|
warn "A build dir for 'musl' already exists at '$build_dir'"
|
||||||
warn "Cleaning up..."
|
warn "Cleaning up..."
|
||||||
rm -rf "$MUSL_BUILD_DIR.$version"
|
rm -rf "$build_dir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Copy the source to the build directory at: '$MUSL_BUILD_DIR.$version'"
|
info "Copy the source to the build directory at: '$build_dir'"
|
||||||
cp -r "$src" "$MUSL_BUILD_DIR.$version"
|
cp -r "$src" "$build_dir"
|
||||||
|
|
||||||
mkdir -p "$MUSL_INSTALL_DIR"
|
mkdir -p "$install_dir"
|
||||||
|
|
||||||
_push "$MUSL_BUILD_DIR.$version"
|
_push "$build_dir"
|
||||||
./configure --disable-shared --prefix="$MUSL_INSTALL_DIR"
|
./configure --disable-shared --prefix="$install_dir"
|
||||||
|
|
||||||
make -j "$(nproc)"
|
make -j "$(nproc)"
|
||||||
make install
|
make install
|
||||||
_pop
|
_pop
|
||||||
info_musl
|
info "'musl' version '$version' installed at '$install_dir'"
|
||||||
}
|
|
||||||
|
|
||||||
function info_musl() {
|
|
||||||
local version
|
|
||||||
version="$MUSL_VERSION"
|
|
||||||
|
|
||||||
info "'musl' version '$MUSL_VERSION' installed at '$MUSL_INSTALL_DIR'"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function package_musl() { ## Packages the built toolchain
|
function package_musl() { ## Packages the built toolchain
|
||||||
|
|
|
@ -83,8 +83,11 @@ function build_llvm() {
|
||||||
|
|
||||||
unset CC
|
unset CC
|
||||||
unset CXX
|
unset CXX
|
||||||
|
|
||||||
_pop
|
_pop
|
||||||
|
|
||||||
|
# Enable the lld linker as the default linker for this toolchain
|
||||||
|
ln -s "$install_dir/bin/ld.lld" "$install_dir/bin/ld"
|
||||||
|
|
||||||
info "llvm build is ready at '$install_dir'"
|
info "llvm build is ready at '$install_dir'"
|
||||||
info "Just add the 'bin' dir to you PATH"
|
info "Just add the 'bin' dir to you PATH"
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,7 @@ set_target_properties(serene PROPERTIES
|
||||||
SOVERSION ${PROJECT_VERSION_MAJOR}
|
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||||
# Warn on unused libs
|
# Warn on unused libs
|
||||||
LINK_WHAT_YOU_USE TRUE
|
LINK_WHAT_YOU_USE TRUE
|
||||||
# LTO support
|
)
|
||||||
INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
||||||
|
|
||||||
if (CPP_20_SUPPORT)
|
if (CPP_20_SUPPORT)
|
||||||
target_compile_features(serene PRIVATE cxx_std_20)
|
target_compile_features(serene PRIVATE cxx_std_20)
|
||||||
|
@ -64,9 +63,21 @@ target_include_directories(serene
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# We don't want the generated files from table gen
|
# We don't want the generated files from table gen
|
||||||
# to be treated as local since the contain warnings
|
# to be treated as local since the contain warnings
|
||||||
target_include_directories(serene SYSTEM PRIVATE ${PROJECT_BINARY_DIR}/include)
|
target_include_directories(serene SYSTEM PRIVATE
|
||||||
|
${PROJECT_BINARY_DIR}/include
|
||||||
|
# ${SERENE_LLVM_DIR}/include/x86_64-unknown-linux-gnu/c++/v1
|
||||||
|
# ${SERENE_LLVM_DIR}/include/c++/v1
|
||||||
|
#${MUSL_DIR}/include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_directories(serene
|
||||||
|
PRIVATE
|
||||||
|
# ${SERENE_LLVM_DIR}/lib
|
||||||
|
# ${MUSL_DIR}/lib
|
||||||
|
)
|
||||||
|
|
||||||
# Autogenerate the `config.h` file
|
# Autogenerate the `config.h` file
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/serene/config.h.in include/serene/config.h)
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/serene/config.h.in include/serene/config.h)
|
||||||
|
@ -74,9 +85,17 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/serene/config.h.in include/se
|
||||||
|
|
||||||
target_compile_options(serene
|
target_compile_options(serene
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
-stdlib=libc++
|
||||||
# LLVM has it's own RTTI
|
# LLVM has it's own RTTI
|
||||||
-fno-rtti
|
-fno-rtti
|
||||||
-fno-builtin-strlen
|
-fno-builtin-strlen
|
||||||
|
# Don't link against system's default libc++ or libstdc++
|
||||||
|
# -nostdinc++
|
||||||
|
# -nostdlib++
|
||||||
|
|
||||||
|
# Do not link any default library, We want to be explicit
|
||||||
|
# -nodefaultlibs
|
||||||
|
# -nostdinc
|
||||||
|
|
||||||
# Dedicate a section to each function, so the linker
|
# Dedicate a section to each function, so the linker
|
||||||
# can do a better job on dead code elimination
|
# can do a better job on dead code elimination
|
||||||
|
@ -106,14 +125,13 @@ target_compile_options(serene
|
||||||
|
|
||||||
target_link_options(serene
|
target_link_options(serene
|
||||||
PRIVATE
|
PRIVATE
|
||||||
-fuse-ld=lld
|
-stdlib=libc++
|
||||||
-Wl,-gc-sections
|
-lc++abi
|
||||||
|
-Wl,--gc-sections
|
||||||
$<$<CONFIG:RELEASE>:-s>
|
$<$<CONFIG:RELEASE>:-s>
|
||||||
|
|
||||||
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
||||||
$<$<CONFIG:DEBUG>:-static-libsan>
|
$<$<CONFIG:DEBUG>:-static-libsan>
|
||||||
|
|
||||||
# Do not link against shared libraries
|
# Do not link against shared libraries
|
||||||
--static
|
--static
|
||||||
)
|
)
|
||||||
|
@ -126,15 +144,18 @@ if(SERENE_ENABLE_TIDY)
|
||||||
set_target_properties(serene PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
|
set_target_properties(serene PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: Setup the THINLTO on release
|
|
||||||
if(SERENE_ENABLE_THINLTO)
|
if(SERENE_ENABLE_THINLTO)
|
||||||
|
include(CheckIPOSupported)
|
||||||
|
# Optional IPO. Do not use IPO if it's not supported by compiler.
|
||||||
|
check_ipo_supported(RESULT result OUTPUT output)
|
||||||
|
if(result)
|
||||||
|
set_property(TARGET serene PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||||
|
else()
|
||||||
|
message(WARNING "IPO is not supported: ${output}")
|
||||||
|
message(WARNING "Make sure to use lld")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# target_link_libraries(serene
|
|
||||||
# PRIVATE
|
|
||||||
# )
|
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
|
|
@ -16,4 +16,36 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main() { return 0; }
|
|
||||||
|
#include <iomanip>
|
||||||
|
#include <memory>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
struct Vec3
|
||||||
|
{
|
||||||
|
int x, y, z;
|
||||||
|
|
||||||
|
// following constructor is no longer needed since C++20
|
||||||
|
Vec3(int x = 0, int y = 0, int z = 0) noexcept : x(x), y(y), z(z) { }
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const Vec3& v)
|
||||||
|
{
|
||||||
|
return os << "{ x=" << v.x << ", y=" << v.y << ", z=" << v.z << " }";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Use the default constructor.
|
||||||
|
std::unique_ptr<Vec3> v1 = std::make_unique<Vec3>();
|
||||||
|
// Use the constructor that matches these arguments
|
||||||
|
std::unique_ptr<Vec3> v2 = std::make_unique<Vec3>(0,1,2);
|
||||||
|
// Create a unique_ptr to an array of 5 elements
|
||||||
|
std::unique_ptr<Vec3[]> v3 = std::make_unique<Vec3[]>(5);
|
||||||
|
|
||||||
|
std::cout << "make_unique<Vec3>(): " << *v1 << '\n'
|
||||||
|
<< "make_unique<Vec3>(0,1,2): " << *v2 << '\n'
|
||||||
|
<< "make_unique<Vec3[]>(5): ";
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
std::cout << std::setw(i ? 30 : 0) << v3[static_cast<size_t>(i)] << '\n';
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue