diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..053f31e --- /dev/null +++ b/.clang-format @@ -0,0 +1,3 @@ +UseTab: Always +IndentWidth: 4 +TabWidth: 4 diff --git a/.editorconfig b/.editorconfig index ca93d68..88ce455 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,7 +1,15 @@ -root = true - -[*] -end_of_line = lf -insert_final_newline = true -indent_style = tab -indent_size = 4 +root = true + +[*] +end_of_line = lf +insert_final_newline = true +indent_style = tab +indent_size = 4 + +[*.{sh,cmd}] +indent_size = 4 +indent_style = space + +[*.{yml,yaml}] +indent_size = 2 +indent_style = space diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..b8cbaa2 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,87 @@ +name: main + +on: + pull_request: + +env: + # libcxx version to match whats already installed + # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md + LLVM_VERSION: '18.1.3' + +jobs: + typos-check: + name: Typos Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: crate-ci/typos@cfe759ac8dd421e203cc293a373396fbc6fe0d4b # v1.22.7 + + build-script-windows: + name: 'build.cmd' + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - run: .\build.cmd + - uses: actions/upload-artifact@v4 + with: + name: cpp2b.exe + path: dist/debug/cpp2b.exe + if-no-files-found: error + retention-days: 0 + + build-self-windows: + name: 'build self (windows)' + needs: build-script-windows + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: 'cpp2b.exe' + - run: .\cpp2b.exe build + - run: Copy-Item .\.cache\cpp2\bin\cpp2b.exe -Destination .\cpp2b-self.exe + - run: .\cpp2b-self.exe build + + build-script-linux: + name: 'build.sh' + runs-on: ubuntu-24.04 + steps: + - run: sudo apt-get install libclang-dev ninja-build -y + - uses: actions/cache@v4 + id: libcxx_with_modules + with: + path: /tmp/llvm-project/build + key: 'libcxx-${{ env.LLVM_VERSION }}' + - name: compiling libcxx ${{ env.LLVM_VERSION }} with modules + if: steps.libcxx_with_modules.outputs.cache-hit != 'true' + run: | + git clone --depth 1 --branch llvmorg-${{ env.LLVM_VERSION }} https://github.com/llvm/llvm-project.git /tmp/llvm-project + cd /tmp/llvm-project + mkdir build + CC=clang-18 CXX=clang++-18 cmake -G Ninja -S runtimes -B build -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" + ninja -C build + - uses: actions/checkout@v4 + - run: CPP2B_LIBCXX_BUILD_ROOT=/tmp/llvm-project/build CC=clang-18 ./build.sh + - uses: actions/upload-artifact@v4 + with: + name: cpp2b + path: dist/debug/cpp2b + if-no-files-found: error + retention-days: 0 + + build-self-linux: + name: 'build self (linux)' + needs: build-script-linux + runs-on: ubuntu-24.04 + steps: + - uses: actions/cache/restore@v4 + with: + path: /tmp/llvm-project/build + key: 'libcxx-${{ env.LLVM_VERSION }}' + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: cpp2b + - run: chmod +x cpp2b + - run: CPP2B_LIBCXX_BUILD_ROOT=/tmp/llvm-project/build ./cpp2b build + - run: CPP2B_LIBCXX_BUILD_ROOT=/tmp/llvm-project/build ./.cache/cpp2/bin/cpp2b build diff --git a/build.cmd b/build.cmd index ccad0f5..ef289fe 100644 --- a/build.cmd +++ b/build.cmd @@ -18,40 +18,40 @@ if not exist dist\debug ( mkdir dist\debug ) set vswhere="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" for /f "usebackq tokens=*" %%i in (`%vswhere% -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do ( - set vs_install_dir=%%i + set vs_install_dir=%%i ) if exist "%vs_install_dir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" ( - set /p vs_tools_version=<"%vs_install_dir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" + set /p vs_tools_version=<"%vs_install_dir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" ) if "%vs_tools_version%"=="" ( - echo ERROR: cannot find VC tools installed on your system - exit 1 + echo ERROR: cannot find VC tools installed on your system + exit 1 ) set vs_tools_dir=%vs_install_dir%\VC\Tools\MSVC\%vs_tools_version% if exist .cache\repos\cppfront\ ( - @rem TODO - report which cppfront version is being used + @rem TODO - report which cppfront version is being used ) else ( - git clone https://github.com/hsutter/cppfront.git .cache/repos/cppfront --quiet + git clone https://github.com/hsutter/cppfront.git .cache/repos/cppfront --quiet ) call "%vs_install_dir%\Common7\Tools\vsdevcmd.bat" /no_logo if not exist "%modules_dir%\std.ifc" ( - echo Compiling std module... - pushd %modules_dir% - cl /D"_CRT_SECURE_NO_WARNINGS=1" /std:c++latest /EHsc /nologo /W4 /MDd /c "%vs_tools_dir%\modules\std.ixx" - popd + echo Compiling std module... + pushd %modules_dir% + cl /D"_CRT_SECURE_NO_WARNINGS=1" /std:c++latest /EHsc /nologo /W4 /MDd /c "%vs_tools_dir%\modules\std.ixx" + popd ) if not exist "%modules_dir%\std.compat.ifc" ( - echo Compiling std.compat module... - pushd %modules_dir% - cl /std:c++latest /EHsc /nologo /W4 /MDd /c "%vs_tools_dir%\modules\std.compat.ixx" - popd + echo Compiling std.compat module... + pushd %modules_dir% + cl /std:c++latest /EHsc /nologo /W4 /MDd /c "%vs_tools_dir%\modules\std.compat.ixx" + popd ) if not exist "%root_dir%.cache\cpp2\source\_build" ( mkdir "%root_dir%.cache\cpp2\source\_build" ) @@ -72,37 +72,37 @@ endlocal pushd %modules_dir% cl /nologo ^ - /std:c++latest /W4 /MDd /EHsc ^ - /reference "%modules_dir%\std.ifc" ^ - /reference "%modules_dir%\std.compat.ifc" ^ - /c "%root_dir%.cache\cpp2\source\_build\cpp2b.ixx" > NUL + /std:c++latest /W4 /MDd /EHsc ^ + /reference "%modules_dir%\std.ifc" ^ + /reference "%modules_dir%\std.compat.ifc" ^ + /c "%root_dir%.cache\cpp2\source\_build\cpp2b.ixx" > NUL popd if %ERRORLEVEL% neq 0 ( - echo ERROR: failed to compile cpp2b module - exit %ERRORLEVEL% + echo ERROR: failed to compile cpp2b module + exit %ERRORLEVEL% ) echo INFO: compiling dylib module... pushd %modules_dir% cl /nologo ^ - /std:c++latest /W4 /MDd /EHsc ^ - /reference "%modules_dir%\std.ifc" ^ - /reference "%modules_dir%\std.compat.ifc" ^ - /c /interface /TP "%root_dir%src\dylib.cppm" > NUL + /std:c++latest /W4 /MDd /EHsc ^ + /reference "%modules_dir%\std.ifc" ^ + /reference "%modules_dir%\std.compat.ifc" ^ + /c /interface /TP "%root_dir%src\dylib.cppm" > NUL popd if %ERRORLEVEL% neq 0 ( - echo ERROR: failed to compile dylib module - exit %ERRORLEVEL% + echo ERROR: failed to compile dylib module + exit %ERRORLEVEL% ) if not exist %cppfront% ( - pushd .cache\repos\cppfront\source - echo INFO: compiling cppfront... - cl /nologo /std:c++latest /EHsc cppfront.cpp - xcopy cppfront.exe %tools_dir% /Y /Q - popd + pushd .cache\repos\cppfront\source + echo INFO: compiling cppfront... + cl /nologo /std:c++latest /EHsc cppfront.cpp + xcopy cppfront.exe %tools_dir% /Y /Q + popd ) if not exist "%root_dir%.cache/cpp2/source/src" ( mkdir "%root_dir%.cache/cpp2/source/src" ) @@ -113,16 +113,16 @@ if %ERRORLEVEL% neq 0 exit %ERRORLEVEL% cl /nologo "%root_dir%.cache/cpp2/source/src/main.cpp" ^ - /diagnostics:column /permissive- ^ - /reference "%modules_dir%\std.ifc" "%modules_dir%\std.obj" ^ - /reference "%modules_dir%\std.compat.ifc" "%modules_dir%\std.compat.obj" ^ - /reference "%modules_dir%\dylib.ifc" "%modules_dir%\dylib.obj" ^ - /reference "%modules_dir%\cpp2b.ifc" "%modules_dir%\cpp2b.obj" ^ - /std:c++latest /W4 /MDd /EHsc ^ - /DEBUG:FULL /Zi /FC ^ - -I"%cppfront_include_dir%" ^ - /Fe"%cpp2b_dist%" ^ - /Fd"%cpp2b_dist%.pdb" + /diagnostics:column /permissive- ^ + /reference "%modules_dir%\std.ifc" "%modules_dir%\std.obj" ^ + /reference "%modules_dir%\std.compat.ifc" "%modules_dir%\std.compat.obj" ^ + /reference "%modules_dir%\dylib.ifc" "%modules_dir%\dylib.obj" ^ + /reference "%modules_dir%\cpp2b.ifc" "%modules_dir%\cpp2b.obj" ^ + /std:c++latest /W4 /MDd /EHsc ^ + /DEBUG:FULL /Zi /FC ^ + -I"%cppfront_include_dir%" ^ + /Fe"%cpp2b_dist%" ^ + /Fd"%cpp2b_dist%.pdb" if %ERRORLEVEL% neq 0 exit %ERRORLEVEL% diff --git a/build.sh b/build.sh index 97f42e6..34d557d 100755 --- a/build.sh +++ b/build.sh @@ -22,24 +22,24 @@ mkdir -p $ROOT_DIR/.cache/cpp2/source/_build CPP2B_COMPILER=${CC:=clang} function log_info() { - echo "INFO: $1" + echo "INFO: $1" } function log_error() { - echo "ERROR: $1" + echo "ERROR: $1" } function fatal() { - echo "FATAL: $1" - exit 1 + echo "FATAL: $1" + exit 1 } if ! [ -x "$(command -v $CPP2B_COMPILER)" ]; then - fatal "cannot find $CPP2B_COMPILER in your PATH" + fatal "cannot find $CPP2B_COMPILER in your PATH" fi if ! [[ $CPP2B_COMPILER == *"clang"* ]]; then - fatal "only clang is supported: detected $CPP2B_COMPILER" + fatal "only clang is supported: detected $CPP2B_COMPILER" fi COMPILER_VERSION=$($CPP2B_COMPILER --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1) @@ -49,37 +49,37 @@ if [ "$COMPILER_MAJOR_VERSION" -lt 18 ]; then fi if [[ -z "${CPP2B_LIBCXX_BUILD_ROOT}" ]]; then - log_error "libcxx with module support must be built from source" - log_error "follow these instructions https://github.com/llvm/llvm-project/blob/main/libcxx/docs/Modules.rst" - fatal "missing CPP2B_LIBCXX_BUILD_ROOT environment variable" + log_error "libcxx with module support must be built from source" + log_error "follow these instructions https://github.com/llvm/llvm-project/blob/main/libcxx/docs/Modules.rst" + fatal "missing CPP2B_LIBCXX_BUILD_ROOT environment variable" fi log_info "using libcxx build root $CPP2B_LIBCXX_BUILD_ROOT" if ! [ -d $CPP2B_LIBCXX_BUILD_ROOT ]; then - log_fatal "directory $CPP2B_LIBCXX_BUILD_ROOT does not exixt" + log_fatal "directory $CPP2B_LIBCXX_BUILD_ROOT does not exist" fi function ensure_gh_repo() { - local repo=$1 - local repo_path=$ROOT_DIR/.cache/repos/$repo - if ! [ -d $repo_path ]; then - mkdir -p $repo_path - git clone --quiet --depth=1 --filter=blob:none --sparse https://github.com/$repo $repo_path - fi + local repo=$1 + local repo_path=$ROOT_DIR/.cache/repos/$repo + if ! [ -d $repo_path ]; then + mkdir -p $repo_path + git clone --quiet --depth=1 --filter=blob:none --sparse https://github.com/$repo $repo_path + fi } function ensure_gh_repo_subdir() { - local repo=$1 - local repo_path=$ROOT_DIR/.cache/repos/$repo - local repo_subdir=$2 - local repo_subdir_path=$repo_path/$repo_subdir - if ! [ -d $repo_subdir_path ]; then - cd $repo_path - log_info "checking out repo $repo/$reposubdir" - git sparse-checkout add $repo_subdir - cd $ROOT_DIR - fi + local repo=$1 + local repo_path=$ROOT_DIR/.cache/repos/$repo + local repo_subdir=$2 + local repo_subdir_path=$repo_path/$repo_subdir + if ! [ -d $repo_subdir_path ]; then + cd $repo_path + log_info "checking out repo $repo/$reposubdir" + git sparse-checkout add $repo_subdir + cd $ROOT_DIR + fi } ensure_gh_repo "hsutter/cppfront" @@ -93,26 +93,26 @@ LIBCXX_INCLUDE_DIR=$CPP2B_LIBCXX_BUILD_ROOT/include LIBCXX_LIB_DIR=$CPP2B_LIBCXX_BUILD_ROOT/lib if ! [ -x $CPPFRONT ]; then - log_info "compiling cppfront..." - cd $ROOT_DIR/.cache/repos/hsutter/cppfront/source - $CPP2B_COMPILER -lstdc++ -lc -lm -fuse-ld=lld -std=c++23 cppfront.cpp -o $CPPFRONT - cd $ROOT_DIR + log_info "compiling cppfront..." + cd $ROOT_DIR/.cache/repos/hsutter/cppfront/source + $CPP2B_COMPILER -lstdc++ -lc -lm -fuse-ld=lld -std=c++23 cppfront.cpp -o $CPPFRONT + cd $ROOT_DIR fi if ! [ -f $MODULES_DIR/std.pcm ]; then - cd $LIBCXX_MODULES_DIR/c++/v1 - log_info "compiling std module..." + cd $LIBCXX_MODULES_DIR/c++/v1 + log_info "compiling std module..." + + $CPP2B_COMPILER \ + -stdlib=libc++ \ + -std=c++23 \ + -fexperimental-library \ + -isystem $LIBCXX_INCLUDE_DIR/c++/v1 \ + -Wno-reserved-module-identifier \ + std.cppm \ + --precompile -o $MODULES_DIR/std.pcm - $CPP2B_COMPILER \ - -stdlib=libc++ \ - -std=c++23 \ - -fexperimental-library \ - -isystem $LIBCXX_INCLUDE_DIR/c++/v1 \ - -Wno-reserved-module-identifier \ - std.cppm \ - --precompile -o $MODULES_DIR/std.pcm - - cd $ROOT_DIR + cd $ROOT_DIR fi if ! [ -f $MODULES_DIR/std.compat.pcm ]; then @@ -129,64 +129,64 @@ if ! [ -f $MODULES_DIR/std.compat.pcm ]; then std.compat.cppm \ --precompile -o $MODULES_DIR/std.compat.pcm - cd $ROOT_DIR + cd $ROOT_DIR fi if ! [ -f $MODULES_DIR/dylib.pcm ]; then - cd $LIBCXX_MODULES_DIR/c++/v1 - log_info "compiling dylib module..." - - $CPP2B_COMPILER \ - -stdlib=libc++ \ - -std=c++23 \ - -fexperimental-library \ - -isystem $LIBCXX_INCLUDE_DIR/c++/v1 \ - -fprebuilt-module-path=$MODULES_DIR \ - "$ROOT_DIR/src/dylib.cppm" \ - --precompile -o $MODULES_DIR/dylib.pcm + cd $LIBCXX_MODULES_DIR/c++/v1 + log_info "compiling dylib module..." + + $CPP2B_COMPILER \ + -stdlib=libc++ \ + -std=c++23 \ + -fexperimental-library \ + -isystem $LIBCXX_INCLUDE_DIR/c++/v1 \ + -fprebuilt-module-path=$MODULES_DIR \ + "$ROOT_DIR/src/dylib.cppm" \ + --precompile -o $MODULES_DIR/dylib.pcm - cd $ROOT_DIR + cd $ROOT_DIR fi log_info "compiling cpp2b module..." if [ -f "$ROOT_DIR/.cache/cpp2/source/_build/cpp2b.cppm" ]; then - rm "$ROOT_DIR/.cache/cpp2/source/_build/cpp2b.cppm" + rm "$ROOT_DIR/.cache/cpp2/source/_build/cpp2b.cppm" fi cat "$ROOT_DIR/share/cpp2b.cppm.tpl" | sed "s\`@CPP2B_PROJECT_ROOT@\`$ROOT_DIR\`g" > "$ROOT_DIR/.cache/cpp2/source/_build/cpp2b.cppm" -$CPP2B_COMPILER \ - -stdlib=libc++ \ - -std=c++23 \ - -fexperimental-library \ - -isystem $LIBCXX_INCLUDE_DIR/c++/v1 \ - -fprebuilt-module-path=$MODULES_DIR \ - "$ROOT_DIR/.cache/cpp2/source/_build/cpp2b.cppm" \ - --precompile -o $MODULES_DIR/cpp2b.pcm +$CPP2B_COMPILER \ + -stdlib=libc++ \ + -std=c++23 \ + -fexperimental-library \ + -isystem $LIBCXX_INCLUDE_DIR/c++/v1 \ + -fprebuilt-module-path=$MODULES_DIR \ + "$ROOT_DIR/.cache/cpp2/source/_build/cpp2b.cppm" \ + --precompile -o $MODULES_DIR/cpp2b.pcm log_info "running cppfront..." $CPPFRONT src/main.cpp2 -pure -import-std -l -format-colon-errors -o "$ROOT_DIR/.cache/cpp2/source/src/main.cpp" log_info "compiling..." -$CPP2B_COMPILER \ - -stdlib=libc++ \ - "$MODULES_DIR/cpp2b.pcm" \ - "$MODULES_DIR/dylib.pcm" \ - "$MODULES_DIR/std.compat.pcm" \ - "$ROOT_DIR/.cache/cpp2/source/src/main.cpp" \ - -std=c++23 \ - -fexperimental-library \ - -Wno-unused-result \ - -Wno-deprecated-declarations \ - -fprebuilt-module-path=$MODULES_DIR \ - -L$LIBCXX_LIB_DIR \ - -isystem $LIBCXX_INCLUDE_DIR/c++/v1 \ - -lc++abi \ - -lc++ \ - -lm \ - -static \ - -fuse-ld=lld \ - -I"$CPPFRONT_INCLUDE_DIR" \ - -o $CPP2B_DIST +$CPP2B_COMPILER \ + -stdlib=libc++ \ + "$MODULES_DIR/cpp2b.pcm" \ + "$MODULES_DIR/dylib.pcm" \ + "$MODULES_DIR/std.compat.pcm" \ + "$ROOT_DIR/.cache/cpp2/source/src/main.cpp" \ + -std=c++23 \ + -fexperimental-library \ + -Wno-unused-result \ + -Wno-deprecated-declarations \ + -fprebuilt-module-path=$MODULES_DIR \ + -L$LIBCXX_LIB_DIR \ + -isystem $LIBCXX_INCLUDE_DIR/c++/v1 \ + -lc++abi \ + -lc++ \ + -lm \ + -static \ + -fuse-ld=lld \ + -I"$CPPFRONT_INCLUDE_DIR" \ + -o $CPP2B_DIST log_info "successfully built $CPP2B_DIST" diff --git a/run.cmd b/run.cmd index 45c3753..b568234 100644 --- a/run.cmd +++ b/run.cmd @@ -1,10 +1,10 @@ -@echo off - -set root_dir=%~dp0 -set cpp2b_dist=%~dp0dist\debug\cpp2b - -if not exist "%cpp2b_dist%.exe" ( - call %~dp0build.cmd -) - -"%cpp2b_dist%.exe" %* +@echo off + +set root_dir=%~dp0 +set cpp2b_dist=%~dp0dist\debug\cpp2b + +if not exist "%cpp2b_dist%.exe" ( + call %~dp0build.cmd +) + +"%cpp2b_dist%.exe" %* diff --git a/share/run_with_msvc_env.cmd b/share/run_with_msvc_env.cmd index d736b2b..994a43b 100644 --- a/share/run_with_msvc_env.cmd +++ b/share/run_with_msvc_env.cmd @@ -3,16 +3,16 @@ set vswhere="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" for /f "usebackq tokens=*" %%i in (`%vswhere% -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do ( - set vs_install_dir=%%i + set vs_install_dir=%%i ) if exist "%vs_install_dir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" ( - set /p vs_tools_version=<"%vs_install_dir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" + set /p vs_tools_version=<"%vs_install_dir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" ) if "%vs_tools_version%"=="" ( - echo ERROR: cannot find VC tools installed on your system - exit 1 + echo ERROR: cannot find VC tools installed on your system + exit 1 ) set vs_tools_dir=%vs_install_dir%\VC\Tools\MSVC\%vs_tools_version% diff --git a/src/main.cpp2 b/src/main.cpp2 index f280a77..51b33db 100644 --- a/src/main.cpp2 +++ b/src/main.cpp2 @@ -103,6 +103,13 @@ module_source_extension: (compiler: cpp2b::compiler_type) -> std::string_view = std::abort(); } +bmi_extension: (compiler: cpp2b::compiler_type) -> std::string_view = { + if compiler == cpp2b::compiler_type::msvc { return ".ifc"; } + if compiler == cpp2b::compiler_type::clang { return ".pcm"; } + if compiler == cpp2b::compiler_type::gcc { return ".pcm"; } // TODO: Is this right? + std::abort(); +} + generate_cpp2b_module: () = { cpp2b_module_template_path: fs::path = share_dir() / "cpp2b.cppm.tpl"; cpp2b_module_source_path: fs::path = ".cache/cpp2/source/_build/cpp2b(module_source_extension(cpp2b::compiler()))$"; @@ -171,22 +178,46 @@ get_vs_tools_dir: () -> fs::path = { return getenv_sv("VCToolsInstallDir").expect("missing 'VCToolsInstallDir' environment variable"); } -ensure_std_modules: () = { - d := modules_dir(); - std_bmi: fs::path = d / "std.ifc"; - std_compat_bmi: fs::path = d / "std.compat.ifc"; - vs_tools_dir := get_vs_tools_dir(); +get_libcxx_build_root: () -> fs::path = { + return getenv_sv("CPP2B_LIBCXX_BUILD_ROOT").expect("missing 'CPP2B_LIBCXX_BUILD_ROOT' environment variable"); +} - if !fs::exists(std_bmi) { - build_cpp1_module("std", :std::vector=(vs_tools_dir / "modules" / "std.ixx"), :std::vector = ()); - } +get_system_modules_dir: (compiler: cpp2b::compiler_type) -> fs::path = { + if compiler == cpp2b::compiler_type::msvc { return get_vs_tools_dir() / "modules"; } + if compiler == cpp2b::compiler_type::clang { return get_libcxx_build_root() / "modules"; } + log_error("cannot find system cpp20 modules directory"); + std::abort(); +} + +ensure_system_module: (name: std::string) = { + ensure_system_module(name, :std::vector = ()); +} - if !fs::exists(std_compat_bmi) { - build_cpp1_module("std.compat", :std::vector=(vs_tools_dir / "modules" / "std.compat.ixx"), :std::vector=("std")); +ensure_system_module: (name: std::string, deps) = { + d := modules_dir(); + bmi := d / std::format("{}{}", name, bmi_extension(cpp2b::compiler())); + system_modules_dir := get_system_modules_dir(cpp2b::compiler()); + + if !fs::exists(bmi) { + build_cpp1_module( + name, + :std::vector=(system_modules_dir / std::format("{}{}", name, module_source_extension(cpp2b::compiler()))), + deps + ); } } +ensure_std_modules: () = { + ensure_system_module("std"); + ensure_system_module("std.compat", :std::vector=("std")); +} + build_cpp1_module: (name: std::string, sources, module_deps) = { + if cpp2b::compiler() != cpp2b::compiler_type::msvc { + log_error("TODO: build_cpp1_module non-msvc support"); + std::abort(); + } + d := fs::absolute(modules_dir()); bmi := d / ("(name)$.ifc"); cmd_str: std::string = "cl /nologo /std:c++latest /W4 /MDd /EHsc /c /interface /TP"; @@ -469,6 +500,11 @@ build_binary: (info: cpp2b_source_binary_info) -> build_binary_result = { ensure_dir(log_path.parent_path()); ensure_dir(bin_outpath.parent_path()); + if cpp2b::compiler() != cpp2b::compiler_type::msvc { + log_error("TODO: build_binary non-msvc support"); + std::abort(); + } + d := fs::absolute(modules_dir()); cmd_str: std::string = "cl /nologo /std:c++latest /W4 /MDd /EHsc /DEBUG:full /Zi /FC"; for info.imports do (imp: std::string) { @@ -521,6 +557,11 @@ build_build_script: (info: cpp2b_source_build_info) -> build_binary_result = { ensure_dir(log_path.parent_path()); ensure_dir(bin_outpath.parent_path()); + if cpp2b::compiler() != cpp2b::compiler_type::msvc { + log_error("TODO: build_build_script non-msvc support"); + std::abort(); + } + d := fs::absolute(modules_dir()); cmd_str: std::string = "cl /nologo /std:c++latest /W4 /MDd /EHsc /LDd /DLL"; for info.imports do (imp: std::string) {