diff --git a/Crafter.Build-Project.cpp b/Crafter.Build-Project.cpp index 496b498..cb79530 100644 --- a/Crafter.Build-Project.cpp +++ b/Crafter.Build-Project.cpp @@ -160,31 +160,38 @@ void Project::Build(Configuration config, std::string outputDir) { }else{ pcmDir = config.buildDir; } + std::string clangDir; + if(config.target == "wasm32-unknown-wasi"){ + clangDir = "${WASI_SDK_PATH}/bin/clang++ --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot"; + name+=".wasm"; + } else{ + clangDir = "clang++"; + } for(const std::string& moduleFile : config.moduleFiles){ - system(std::format("clang++ -std={} {}.cppm --precompile -fprebuilt-module-path={} -o {}/{}.pcm", config.standard, moduleFile, pcmDir, pcmDir, moduleFile).c_str()); + system(std::format("{} -std={} {}.cppm --precompile -fprebuilt-module-path={} -o {}/{}.pcm {}", clangDir, config.standard, moduleFile, pcmDir, pcmDir, moduleFile, target).c_str()); } std::vector threads = std::vector(config.moduleFiles.size() + config.sourceFiles.size()); std::string files; for(std::int_fast32_t i = 0; i < config.moduleFiles.size(); i++) { files+=std::format("{}/{}.o ",config.buildDir, config.moduleFiles[i]); - threads[i] = std::thread([i, config, pcmDir, target](){ - system(std::format("clang++ -std={} {}/{}.pcm -fprebuilt-module-path={} -c -O{} -o {}/{}.o {}", config.standard, pcmDir, config.moduleFiles[i], pcmDir, config.optimizationLevel, config.buildDir, config.moduleFiles[i], target).c_str()); + threads[i] = std::thread([i, config, pcmDir, target, clangDir](){ + system(std::format("{} -std={} {}/{}.pcm -fprebuilt-module-path={} -c -O{} -o {}/{}.o {}", clangDir, config.standard, pcmDir, config.moduleFiles[i], pcmDir, config.optimizationLevel, config.buildDir, config.moduleFiles[i], target).c_str()); }); } for(std::int_fast32_t i = 0; i < config.sourceFiles.size(); i++) { files+=std::format("{}/{}_source.o ",config.buildDir, config.sourceFiles[i]); - threads[config.moduleFiles.size()+i] = std::thread([i, config, pcmDir, target](){ - system(std::format("clang++ -std={} {}.cpp -fprebuilt-module-path={} -c -O{} -o {}/{}_source.o {}", config.standard, config.sourceFiles[i], pcmDir, config.optimizationLevel, config.buildDir, config.sourceFiles[i], target).c_str()); + threads[config.moduleFiles.size()+i] = std::thread([i, config, pcmDir, target, clangDir](){ + system(std::format("{} -std={} {}.cpp -fprebuilt-module-path={} -c -O{} -o {}/{}_source.o {}", clangDir, config.standard, config.sourceFiles[i], pcmDir, config.optimizationLevel, config.buildDir, config.sourceFiles[i], target).c_str()); }); } for(std::thread& thread : threads){ thread.join(); } if(config.type == "executable"){ - system(std::format("clang++ {}-O{} -o {}/{} {}", files, config.optimizationLevel, outputDir, name, target).c_str()); + system(std::format("{} {}-O{} -o {}/{} {}", clangDir, files, config.optimizationLevel, outputDir, name, target).c_str()); } else if(config.type == "library"){ - system(std::format("ar r {}/{}.a {}", outputDir, name, files, target).c_str()); + system(std::format("ar r {}/{}.a {}", clangDir, outputDir, name, files, target).c_str()); } else if(config.type == "shared-library"){ system(std::format("ar r {}/{}.so {} -shared", outputDir, name, files, target).c_str()); } diff --git a/README.md b/README.md index faa27ed..d665a29 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Save and close, then run ``crafter-build -c debug``. Now you can run the ``hello ## CLI arguments -``--help`` Displays this help message. +``--help`` Displays a help message. ``-c`` The name of the configuration to build. @@ -67,3 +67,26 @@ Save and close, then run ``crafter-build -c debug``. Now you can run the ``hello ``-o`` Overrides the output folder. +## configuration properties +``name`` Name of the configuration. + +``standard`` C++ standard that this configuration uses, please refer to the [relevant clang documentation](https://clang.llvm.org/cxx_status.html) + +``source_files`` All source files of the project ``.cpp`` extension is assumed. + +``module_files`` All C++ 20 module files of the project ``.cppm`` extension is assumed. + +``build_dir`` The directory where intermediate files are stored. + +``output_dir`` The directory where the output files will be placed. + +``extends`` An array of configuration names that this configuration extends, later elements in the array take priority over previous ones. + +``optimization_level`` Please refer to the [relevant clang documentation](https://clang.llvm.org/docs/CommandGuide/clang.html#code-generation-options). + +``target`` Clang triplet this configuration uses, please refer to the [relevant clang documentation](https://clang.llvm.org/docs/CrossCompilation.html#target-triple). + +Note: the WASI SDK needs to be installed to use the ``wasm32-unknown-wasi`` to compile to webassmbly, and ``$WASI_SDK_PATH`` needs to be set, please refer to the [wasi-sdk installation guide](https://github.com/WebAssembly/wasi-sdk?tab=readme-ov-file#install). + + +