Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env:
# https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md
LLVM_VERSION: '18.1.3'
CPP2B_LIBCXX_BUILD_ROOT: '/tmp/llvm-project/build'
CPP2B_PROJECT_ROOT: '.'

jobs:
typos-check:
Expand Down
2 changes: 1 addition & 1 deletion build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ setlocal enableextensions disabledelayedexpansion
set "search=@CPP2B_PROJECT_ROOT@"
set "replace=%root_dir%"

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

for /f "delims=" %%i in ('type "%inputFile%"') do (
Expand Down
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ if [ -f "$ROOT_DIR/.cache/cpp2/source/_build/cpp2b.cppm" ]; then
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"
cat "$ROOT_DIR/share/cpp2b/cpp2b.cppm.tpl" | sed "s\`@CPP2B_PROJECT_ROOT@\`$ROOT_DIR\`g" > "$ROOT_DIR/.cache/cpp2/source/_build/cpp2b.cppm"

$CPP2B_COMPILER \
-stdlib=libc++ \
Expand All @@ -197,6 +197,7 @@ $CPPFRONT src/main.cpp2 -pure -import-std -l -format-colon-errors -o "$ROOT_DIR/

log_info "compiling..."
$CPP2B_COMPILER \
-g \
-stdlib=libc++ \
"$MODULES_DIR/cpp2b.pcm" \
"$MODULES_DIR/dylib.pcm" \
Expand Down
3 changes: 3 additions & 0 deletions install.cmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@echo off

set cpp2b_dist=%~dp0dist\debug\cpp2b
set cpp2b_share_dir=%~dp0share

call %~dp0build.cmd

xcopy /y /q %cpp2b_dist%.exe %USERPROFILE%\.local\bin\
xcopy /y /q %cpp2b_dist%.pdb %USERPROFILE%\.local\bin\
xcopy /e /i /h /y %cpp2b_share_dir% %USERPROFILE%\.local\share

2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ cd $ROOT_DIR

./build.sh
cp dist/debug/cpp2b ~/.local/bin/cpp2b
rm -rf ~/.local/share/cpp2b
cp -r share/cpp2b ~/.local/share
File renamed without changes.
File renamed without changes.
56 changes: 44 additions & 12 deletions share/cpp2b.cppm.tpl → share/cpp2b/cpp2b.cppm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module;
# include <Windows.h>
#else
# include <stdlib.h>
# include <unistd.h>
#endif

export module cpp2b;
Expand All @@ -22,7 +23,6 @@ export namespace cpp2b {
enum class platform { linux, macos, windows };
enum class compiler_type { gcc, clang, msvc };
enum class compilation_type { debug, optimized, fast };
enum class build_type { local, development, release };

constexpr auto host_platform() -> platform {
#if defined(_WIN32)
Expand Down Expand Up @@ -51,17 +51,6 @@ constexpr auto compiler() -> compiler_type {
# error unknown compiler
#endif
}

constexpr auto build() -> build_type {
return build_type::local;
}

constexpr auto install_dir() -> const std::string_view {
if constexpr (build() == build_type::local) {
return R"_____cpp2b_____(@CPP2B_PROJECT_ROOT@)_____cpp2b_____";
}
}

} // namespace cpp2b

export namespace cpp2b::env {
Expand Down Expand Up @@ -183,4 +172,47 @@ public:
return iterator(nullptr);
}
};

std::filesystem::path executable_path() {
static std::string executable_path_str;

if(!executable_path_str.empty()) {
return executable_path_str;
}

auto size = 260;
auto buffer = std::vector<char>(size);

#if defined(_WIN32)
for (;;) {
DWORD len = GetModuleFileNameA(NULL, buffer.data(), size);
if (len == 0) {
executable_path_str = {};
return executable_path_str;
} else if (len < size - 1) {
executable_path_str = std::string(buffer.data(), len);
return executable_path_str;
}

size += 260;
buffer.resize(size);
}
#elif defined(__linux__)
for (;;) {
ssize_t len = readlink("/proc/self/exe", buffer.data(), size - 1);
if (len < 0) {
executable_path_str = {};
return executable_path_str;
} else if (len < size - 1) {
executable_path_str = std::string(buffer.data(), len);
return executable_path_str;
}

size += 260;
buffer.resize(size);
}
#else
# error unhandled executable_path platform
#endif
}
}
File renamed without changes.
Loading