Skip to content

Commit

Permalink
fix: use clang-19 directly (temp)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy committed Nov 1, 2024
1 parent 6b9e305 commit a926247
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions examples/static-member/src/main.cpp2
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Month: type = {
id_: int;
names: std::vector<std::string> == ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
names: () == :std::array=("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
}

main: () = {
for Month::names do(name) {
for Month::names() do(name) {
std::println("hello {}", name);
}
}
40 changes: 20 additions & 20 deletions src/main.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ get_vs_tools_dir: () -> fs::path = {
.fs::canonical();
}

get_libcxx_build_root: () -> fs::path = {
return cpp2b::env::get_var("CPP2B_LIBCXX_BUILD_ROOT").expect("missing 'CPP2B_LIBCXX_BUILD_ROOT' environment variable");
get_llvm_root: () -> fs::path = {
return "/usr/lib/llvm-19";
}

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" / "c++" / "v1"; }
if compiler == cpp2b::compiler_type::clang { return get_llvm_root() / "share" / "libc++" / "v1"; }
log_error("cannot find system cpp20 modules directory");
std::abort();
}
Expand Down Expand Up @@ -238,9 +238,9 @@ cl_build_cpp1_module_cmd: (name: std::string, sources, module_deps, bmi_path: fs

unix_build_cpp1_module_cmd: (compiler_cmd: std::string, name: std::string, sources, module_deps, bmi_path: fs::path) -> std::string = {
d := fs::absolute(modules_dir());
libcxx_inc_dir := get_libcxx_build_root() / "include" / "c++" / "v1";
sys_inc_dir := get_llvm_root() / "include" / "c++" / "v1";
cmd_str: std::string = std::format("{} -stdlib=libc++ -std=c++23 -fexperimental-library", compiler_cmd);
cmd_str += std::format(" -isystem \"{}\"", fs::absolute(libcxx_inc_dir).string());
cmd_str += std::format(" -isystem \"{}\"", fs::absolute(sys_inc_dir).string());
cmd_str += std::format(" -fprebuilt-module-path=\"{}\"", fs::absolute(d).string());
for sources do (src: fs::path) {
cmd_str += " \"(fs::absolute(src).string())$\"";
Expand All @@ -260,7 +260,7 @@ build_cpp1_module: (name: std::string, sources, module_deps) = {

cmd_str: std::string = "";
if compiler == cpp2b::compiler_type::msvc { cmd_str = cl_build_cpp1_module_cmd(name, sources, module_deps, bmi); }
else if compiler == cpp2b::compiler_type::clang { cmd_str = unix_build_cpp1_module_cmd("clang", name, sources, module_deps, bmi); }
else if compiler == cpp2b::compiler_type::clang { cmd_str = unix_build_cpp1_module_cmd("clang-19", name, sources, module_deps, bmi); }
else if compiler == cpp2b::compiler_type::gcc { cmd_str = unix_build_cpp1_module_cmd("gcc", name, sources, module_deps, bmi); }
else { log_error("unsupported compiler"); std::abort(); }

Expand Down Expand Up @@ -363,11 +363,11 @@ main: (args) -> int = {
}
}
} else {
libcxx_lib_dir := get_libcxx_build_root() / "lib";
sys_lib_dir := get_llvm_root() / "lib";
ld_library_path := cpp2b::env::get_var("LD_LIBRARY_PATH");
if !ld_library_path || !ld_library_path*.contains(libcxx_lib_dir.string()) {
log_info("setting LD_LIBRARY_PATH to '{}'", libcxx_lib_dir.string());
cpp2b::env::set_var("LD_LIBRARY_PATH", libcxx_lib_dir.string());
if !ld_library_path || !ld_library_path*.contains(sys_lib_dir.string()) {
log_info("setting LD_LIBRARY_PATH to '{}'", sys_lib_dir.string());
cpp2b::env::set_var("LD_LIBRARY_PATH", sys_lib_dir.string());
return run_with_args(argz);
}
}
Expand Down Expand Up @@ -579,8 +579,8 @@ cl_build_binary_cmd: (info: cpp2b_source_binary_info, bin_outpath: fs::path) ->
}

unix_build_binary_cmd: (compiler_cmd: std::string, info: cpp2b_source_binary_info, bin_outpath: fs::path) -> std::string = {
libcxx_inc_dir := get_libcxx_build_root() / "include" / "c++" / "v1";
libcxx_lib_dir := get_libcxx_build_root() / "lib";
sys_inc_dir := get_llvm_root() / "include" / "c++" / "v1";
sys_lib_dir := get_llvm_root() / "lib";
cppfront_include_dir := fs::absolute(".cache/cpp2/repos/hsutter/cppfront/include");
transpiled_src := fs::absolute(".cache/cpp2/source") / fs::path(info.src).replace_extension(".cpp");
d := fs::absolute(modules_dir());
Expand All @@ -591,8 +591,8 @@ unix_build_binary_cmd: (compiler_cmd: std::string, info: cpp2b_source_binary_inf
cmd_str += " \"(transpiled_src.string())$\"";
cmd_str += " -std=c++23 -fexperimental-library";
cmd_str += std::format(" -fprebuilt-module-path={}", d.string());
cmd_str += std::format(" -L{}", libcxx_lib_dir.string());
cmd_str += std::format(" -isystem {}", libcxx_inc_dir.string());
cmd_str += std::format(" -L{}", sys_lib_dir.string());
cmd_str += std::format(" -isystem {}", sys_inc_dir.string());
cmd_str += " -lc++abi -lc++ -lm -static -fuse-ld=lld";
cmd_str += " -I\"(cppfront_include_dir.string())$\"";
cmd_str += " -o \"(bin_outpath.string())$\"";
Expand All @@ -616,7 +616,7 @@ build_binary: (info: cpp2b_source_binary_info) -> build_binary_result = {

cmd_str: std::string = "";
if compiler == cpp2b::compiler_type::msvc { cmd_str = cl_build_binary_cmd(info, bin_outpath); }
else if compiler == cpp2b::compiler_type::clang { cmd_str = unix_build_binary_cmd("clang", info, bin_outpath); }
else if compiler == cpp2b::compiler_type::clang { cmd_str = unix_build_binary_cmd("clang-19", info, bin_outpath); }
else if compiler == cpp2b::compiler_type::gcc { cmd_str = unix_build_binary_cmd("gcc", info, bin_outpath); }
else { log_error("Unsupported compiler"); std::abort(); }

Expand Down Expand Up @@ -677,8 +677,8 @@ cl_build_build_script_cmd: (info: cpp2b_source_build_info, bin_outpath: fs::path


unix_build_build_script_cmd: (compiler_cmd: std::string, info: cpp2b_source_build_info, bin_outpath: fs::path) -> std::string = {
libcxx_inc_dir := get_libcxx_build_root() / "include" / "c++" / "v1";
libcxx_lib_dir := get_libcxx_build_root() / "lib";
sys_inc_dir := get_llvm_root() / "include" / "c++" / "v1";
sys_lib_dir := get_llvm_root() / "lib";
cppfront_include_dir := fs::absolute(".cache/cpp2/repos/hsutter/cppfront/include");
transpiled_src := fs::absolute(".cache/cpp2/source") / fs::path(info.src).replace_extension(".cpp");
d := fs::absolute(modules_dir());
Expand All @@ -689,8 +689,8 @@ unix_build_build_script_cmd: (compiler_cmd: std::string, info: cpp2b_source_buil
cmd_str += " \"(transpiled_src.string())$\"";
cmd_str += " -std=c++23 -fexperimental-library -fPIC";
cmd_str += std::format(" -fprebuilt-module-path={}", d.string());
cmd_str += std::format(" -L{}", libcxx_lib_dir.string());
cmd_str += std::format(" -isystem {}", libcxx_inc_dir.string());
cmd_str += std::format(" -L{}", sys_lib_dir.string());
cmd_str += std::format(" -isystem {}", sys_inc_dir.string());
cmd_str += " -lc++abi -lc++ -lm -fuse-ld=lld";
cmd_str += " -I\"(cppfront_include_dir.string())$\"";
cmd_str += " -o \"(bin_outpath.string())$\"";
Expand All @@ -708,7 +708,7 @@ build_build_script: (info: cpp2b_source_build_info) -> build_binary_result = {
d := fs::absolute(modules_dir());
cmd_str: std::string = "";
if compiler == cpp2b::compiler_type::msvc { cmd_str = cl_build_build_script_cmd(info, bin_outpath); }
else if compiler == cpp2b::compiler_type::clang { cmd_str = unix_build_build_script_cmd("clang", info, bin_outpath); }
else if compiler == cpp2b::compiler_type::clang { cmd_str = unix_build_build_script_cmd("clang-19", info, bin_outpath); }
else if compiler == cpp2b::compiler_type::gcc { cmd_str = unix_build_build_script_cmd("gcc", info, bin_outpath); }
else { log_error("Unsupported compiler"); std::abort(); }

Expand Down

0 comments on commit a926247

Please sign in to comment.