Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow specifying compiler #6

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,20 @@ if exist "%root_dir%.cache\cpp2\source\_build\cpp2b.ixx" (

setlocal enableextensions disabledelayedexpansion

set "search=@CPP2B_PROJECT_ROOT@"
set "replace=%root_dir%"

set "inputFile=%root_dir%share\cpp2b.cppm.tpl"
set "outputFile=%root_dir%.cache\cpp2\source\_build\cpp2b.ixx"

set "compiler_subst=@CPP2B_COMPILER@"
set "compiler_value=msvc"
set "project_root_subst=@CPP2B_PROJECT_ROOT@"
set "project_root_value=%root_dir%"
for /f "delims=" %%i in ('type "%inputFile%"') do (
set "line=%%i"
setlocal enabledelayedexpansion
>>"%outputFile%" echo(!line:%search%=%replace%!
call set "line=!line:%compiler_subst%=%compiler_value%!"
call set "line=!line:%project_root_subst%=%project_root_value%!"
>>"%outputFile%" echo(!line!
endlocal
)
endlocal
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ if [ -f "$ROOT_DIR/.cache/cpp2/source/_build/cpp2b.cppm" ]; then
fi

cat "$ROOT_DIR/share/cpp2b.cppm.tpl" | sed "s\`@CPP2B_PROJECT_ROOT@\`$ROOT_DIR\`g" > "$ROOT_DIR/.cache/cpp2/source/_build/cpp2b.cppm"
cat "$ROOT_DIR/share/cpp2b.cppm.tpl" | sed "s\`@CPP2B_COMPILER@\`clang\`g" > "$ROOT_DIR/.cache/cpp2/source/_build/cpp2b.cppm"

$CPP2B_COMPILER \
-stdlib=libc++ \
Expand Down
6 changes: 3 additions & 3 deletions examples/donut/cursed_donut.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ main: () = {

t: float = c * h * g - f * e;

x: int = cpp2::unsafe_narrow<int>(40 + 30 * D * (l * h * m - t * n));
x: int = cpp2::unchecked_narrow<int>(40 + 30 * D * (l * h * m - t * n));

y: int = cpp2::unsafe_narrow<int>(12 + 15 * D * (l * h * n + t * m));
y: int = cpp2::unchecked_narrow<int>(12 + 15 * D * (l * h * n + t * m));

o: int = x + 80 * y;

N: int = cpp2::unsafe_narrow<int>(8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n));
N: int = cpp2::unchecked_narrow<int>(8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n));
if 22 > y && y > 0 && x > 0 && 80 > x && D > z[0] {
z[o] = D;
if N > 0 { b[o] = brightness_chars[N % brightness_chars.size()]; }
Expand Down
10 changes: 1 addition & 9 deletions share/cpp2b.cppm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,7 @@ constexpr auto target_platform() -> platform {
}

constexpr auto compiler() -> compiler_type {
#if defined(_MSC_VER)
return compiler_type::msvc;
#elif defined(__clang__)
return compiler_type::clang;
#elif defined(__GNUC__)
return compiler_type::gcc;
#else
# error unknown compiler
#endif
return compiler_type::@CPP2B_COMPILER@;
}

constexpr auto build() -> build_type {
Expand Down
Loading
Loading