Skip to content

Commit c5c90b7

Browse files
committed
feat: initial cpp2b idea
0 parents  commit c5c90b7

File tree

6 files changed

+150
-0
lines changed

6 files changed

+150
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.cache
2+
/dist
3+
/src/*.cpp
4+
*.obj
5+
*.o
6+
*.exe
7+
*.a

build.cmd

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
@echo off
2+
3+
set cppfront=%~dp0.cache\tools\cppfront.exe
4+
set cppfront_include_dir=%~dp0.cache\repos\cppfront\include
5+
set cpp2b_dist=%~dp0dist\debug\cpp2b
6+
set modules_dir=%~dp0.cache\modules
7+
8+
if not exist .cache\repos ( mkdir .cache\repos )
9+
if not exist %modules_dir% ( mkdir %modules_dir% )
10+
if not exist .cache\tools ( mkdir .cache\tools )
11+
if not exist dist ( mkdir dist )
12+
if not exist dist\debug ( mkdir dist\debug )
13+
14+
set vswhere="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
15+
16+
for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
17+
set vs_install_dir=%%i
18+
)
19+
20+
if exist "%vs_install_dir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" (
21+
set /p vs_tools_version=<"%vs_install_dir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"
22+
)
23+
24+
if "%vs_tools_version%"=="" (
25+
echo Cannot find VC tools installed on your system
26+
exit 1
27+
)
28+
29+
set vs_tools_dir=%vs_install_dir%\VC\Tools\MSVC\%vs_tools_version%
30+
31+
if exist .cache\repos\cppfront\ (
32+
@rem TODO - report which cppfront version is being used
33+
) else (
34+
git clone https://github.com/hsutter/cppfront.git .cache/repos/cppfront --quiet
35+
)
36+
37+
call "%vs_install_dir%\Common7\Tools\vsdevcmd.bat" /no_logo
38+
39+
if not exist "%modules_dir%\std.ifc" (
40+
echo Compiling std module...
41+
pushd %modules_dir%
42+
cl /std:c++latest /EHsc /nologo /W4 /MTd /c "%vs_tools_dir%\modules\std.ixx"
43+
popd
44+
)
45+
46+
if not exist "%modules_dir%\std.compat.ifc" (
47+
echo Compiling std.compat module...
48+
pushd %modules_dir%
49+
cl /std:c++latest /EHsc /nologo /W4 /MTd /c "%vs_tools_dir%\modules\std.compat.ixx"
50+
popd
51+
)
52+
53+
if not exist %cppfront% (
54+
pushd .cache\repos\cppfront\source
55+
echo Compiling cppfront...
56+
cl /nologo /std:c++latest /EHsc cppfront.cpp
57+
xcopy /y /q cppfront.exe %cppfront%
58+
popd
59+
)
60+
61+
%cppfront% src/main.cpp2 -pure -import-std -add-source-info -format-colon-errors
62+
63+
if %ERRORLEVEL% neq 0 exit %ERRORLEVEL%
64+
65+
cl /nologo src/main.cpp ^
66+
/diagnostics:caret /permissive- ^
67+
/reference "%modules_dir%\std.ifc" "%modules_dir%\std.obj" ^
68+
/reference "%modules_dir%\std.compat.ifc" "%modules_dir%\std.compat.obj" ^
69+
/std:c++latest /W4 /MTd /EHsc ^
70+
-I"%cppfront_include_dir%" ^
71+
/Fe"%cpp2b_dist%"
72+
73+
if %ERRORLEVEL% neq 0 exit %ERRORLEVEL%
74+
75+
echo %cpp2b_dist%.exe

clean.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
@rd /S /Q ".cache"

cpp2b.toml

Whitespace-only changes.

install.cmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@echo off
2+
3+
set cpp2b_dist=%~dp0dist\debug\cpp2b
4+
5+
call %~dp0build.cmd
6+
7+
xcopy /y /q %cpp2b_dist%.exe %USERPROFILE%\.local\bin\

src/main.cpp2

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
fs: namespace == std::filesystem;
2+
3+
ensure_dir: (dir: fs::path) = {
4+
status := fs::status(dir);
5+
6+
if status.type() == fs::file_type::not_found {
7+
fs::create_directories(dir);
8+
}
9+
}
10+
11+
12+
find_closest_file: (filename) find_closest_file(filename, fs::current_path());
13+
find_closest_file: (filename, base: fs::path) -> std::optional<fs::path> = {
14+
if fs::exists(base / filename) {
15+
return base / filename;
16+
}
17+
18+
if !base.has_parent_path() || base.parent_path() == base {
19+
return std::nullopt;
20+
}
21+
22+
return find_closest_file(filename, base.parent_path());
23+
}
24+
25+
expect: <T>(move opt: std::optional<T>, message) -> T = {
26+
if !opt {
27+
std::println("ERROR: {}", message);
28+
std::abort();
29+
}
30+
31+
return opt*;
32+
}
33+
34+
expect: <T>(move v: std::variant, message) -> T = {
35+
if !std::holds_alternative<T>(v) {
36+
panic("ERROR: {}", message);
37+
}
38+
39+
return std::get<T>(v);
40+
}
41+
42+
main: (args) -> int = {
43+
cpp2b_config_file := find_closest_file("cpp2b.toml").expect("Cannot find cpp2b config file. Are you sure you're running cpp2b in a cpp2b project?");
44+
45+
std::println("Found cpp2b config file: {}", cpp2b_config_file.string());
46+
47+
fs::current_path(cpp2b_config_file.parent_path());
48+
49+
ensure_dir(".cache/modules");
50+
ensure_dir(".cache/repos");
51+
ensure_dir(".cache/tools");
52+
53+
for args do (arg) {
54+
std::println("arg={}", arg);
55+
}
56+
57+
return 0;
58+
}

0 commit comments

Comments
 (0)