|
1 | | -## 🏃♂️ runcpp2 |
2 | | -A cross-platform tool that can let you run any c++ file as a script, just like python! |
| 1 | +# runcpp2 |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +A cross-platform tool that can let you run any c++ files as a script, just like python! |
3 | 6 |
|
4 | 7 | Run c++ files anytime, anywhere. |
5 | 8 |
|
6 | | -### Prerequisites |
7 | | -- A C++ compiler, currently only tested with g++ |
| 9 | +### 🛠️ Prerequisites |
| 10 | +- Any C++ compiler. The default user config only has g++ and msvc profiles. But feel free to |
| 11 | +add other compilers. |
8 | 12 |
|
9 | | -TODO: Support for other compilers |
| 13 | +### 📥️ Installation |
| 14 | +You can either build from source or use the binary release |
10 | 15 |
|
11 | | -### Installation |
| 16 | +To build from source: |
12 | 17 | 1. Clone the repository with `git clone --recursive https://github.com/Neko-Box-Coder/runcpp2.git` |
13 | 18 | 2. Run `Build.sh` or `Build.bat` to build |
14 | 19 |
|
15 | 20 | TODO: Ability to use pre-built binary |
16 | 21 |
|
17 | | -### How to use |
18 | | - |
19 | | -#### Single C/C++ File |
20 | | -Just run `runcpp2 <filename>.cpp <arguments...>` and it will execute the file just like any other script. |
21 | | - |
22 | | -#### C/C++ File with External Libraries |
23 | | - |
24 | | -TODO: Detail documentations |
25 | | - |
26 | | -<details> |
27 | | -<summary>Sample C++ file</summary> |
28 | | - |
29 | | -```c++ |
30 | | - |
31 | | -/* runcpp2 |
32 | | -
|
33 | | -OverrideCompileFlags: |
34 | | - # Profile with the respective flags to override |
35 | | - "g++": |
36 | | - # Flags to be removed from the default compile flags, separated by space |
37 | | - # Remove: "-Werror" |
38 | | -
|
39 | | -Dependencies: |
40 | | -- Name: ssLogger |
41 | | - Platforms: [Windows, Linux, MacOS] |
42 | | - Source: |
43 | | - Type: Git |
44 | | - Value: "https://github.com/Neko-Box-Coder/ssLogger.git" |
45 | | - LibraryType: Static |
46 | | - # LibraryType: Header |
47 | | - IncludePaths: |
48 | | - - "Include" |
49 | | - |
50 | | - # (Optional if LibraryType is Header) Link properties of the dependency |
51 | | - LinkProperties: |
52 | | - # Properties for searching the library binary for the profile |
53 | | - "g++": |
54 | | - # The library names to be searched for when linking against the script |
55 | | - SearchLibraryNames: ["ssLogger"] |
56 | | - |
57 | | - # (Optional) The library names to be excluded from being searched |
58 | | - ExcludeLibraryNames: ["ssLogger_SRC"] |
59 | | - |
60 | | - # The path (relative to the dependency folder) to be searched for the dependency binaries |
61 | | - SearchDirectories: ["./build"] |
62 | | - |
63 | | - # (Optional) Additional link options for this dependency |
64 | | - AdditionalLinkOptions: |
65 | | - All: [] |
66 | | -
|
67 | | - |
68 | | - # (Optional) List of setup commands for the supported platforms |
69 | | - Setup: |
70 | | - # Setup commands for the specified platform |
71 | | - All: |
72 | | - # Setup commands for the specified profile. |
73 | | - # All commands are run in the dependency folder |
74 | | - "g++": |
75 | | - - "git submodule update --init --recursive" |
76 | | - - "mkdir build" |
77 | | - - "cd build && cmake .." |
78 | | - - "cd build && cmake --build . -j 16" |
79 | | -*/ |
80 | | - |
81 | | - |
82 | | - |
83 | | -#include "ssLogger/ssLogSwitches.hpp" |
84 | | - |
85 | | -#define ssLOG_USE_SOURCE 1 |
86 | | -#if !ssLOG_USE_SOURCE |
87 | | - #include "ssLogger/ssLogInit.hpp" |
88 | | -#endif |
89 | | - |
90 | | -#include "ssLogger/ssLog.hpp" |
91 | | - |
92 | | -#include <iostream> |
93 | | - |
94 | | -int main(int argc, char* argv[]) |
95 | | -{ |
96 | | - std::cout << "Hello World" << std::endl; |
97 | | - |
98 | | - for(int i = 0; i < argc; ++i) |
99 | | - std::cout << "Arg" << i << ": " << argv[i] << std::endl; |
100 | | - |
101 | | - #if ssLOG_USE_SOURCE |
102 | | - ssLOG_LINE("Source dependency is working!!!"); |
103 | | - #else |
104 | | - ssLOG_LINE("Header only dependency is working!!!"); |
105 | | - #endif |
106 | | - |
107 | | - int CheckCounter = 5; |
108 | | - ssLOG_FATAL("Test fatal: " << CheckCounter); |
109 | | - ssLOG_ERROR("Test error: " << CheckCounter); |
110 | | - ssLOG_WARNING("Test warning: " << CheckCounter); |
111 | | - ssLOG_INFO("Test info: " << CheckCounter); |
112 | | - ssLOG_DEBUG("Test debug: " << CheckCounter); |
113 | | - |
114 | | - return 0; |
115 | | -} |
| 22 | +Finally, you just need to add runcpp2 binary location to the `PATH` environment variable and |
| 23 | +you can run c++ files anywhere you want. |
| 24 | + |
| 25 | +### ⚡️ Getting Started |
116 | 26 |
|
| 27 | +#### 1. Running directly |
| 28 | +Suppose you have a c++ file called `script.cpp`, you can run it immediately by doing |
| 29 | + |
| 30 | +```shell |
| 31 | +runcpp2 ./script.cpp <any arguments> |
117 | 32 | ``` |
118 | 33 |
|
| 34 | +> [!NOTE] |
| 35 | +> When invoking a c++ file with runcpp2, the first argument (`argv[0]`) to `main()` is the path |
| 36 | +> to the script, not the path to an executable. |
| 37 | +
|
| 38 | +#### 2. Watch and give compile errors |
| 39 | +If you want to edit the script but want to have feedback for any error, you can use "watch" mode. |
| 40 | + |
| 41 | +```shell |
| 42 | +runcpp2 --watch ./script.cpp |
| 43 | +``` |
| 44 | + |
| 45 | +#### 3. Adding script build settings |
| 46 | +If you want to add custom build settings such as compile/link flags, specify profile, etc. |
| 47 | +You will need to provide such settings to runcpp2 in the format of YAML. |
| 48 | + |
| 49 | +This build settings can either be embedded as comment in the script itself, or provided as |
| 50 | +a YAML file. |
| 51 | + |
| 52 | +To generate a script build settings template, do |
| 53 | + |
| 54 | +```shell |
| 55 | +# Embeds the build settings template as comment |
| 56 | +runcpp2 --create-script-template ./script.cpp |
119 | 57 |
|
120 | | -</details> |
| 58 | +# Creates the build settings template as dedicated yaml file |
| 59 | +runcpp2 --create-script-template ./script.yaml |
| 60 | + |
| 61 | +# Short form |
| 62 | +runcpp2 -t ./script.cpp |
| 63 | +``` |
| 64 | + |
| 65 | +This will generate the script build settings template for you. |
| 66 | +Everything is documented as comment in the template but here's a quick summary. |
| 67 | + |
| 68 | +- `RequiredProfiles`: To specify a specific profile for building for different platforms |
| 69 | +- `OverrideCompileFlags`: Compile flags to be added or removed from the current profile |
| 70 | +- `OverrideLinkFlags`: Same as `OverrideCompileFlags` but for linking |
| 71 | +- `OtherFilesToBeCompiled`: Other source files you wish to be compiled. |
| 72 | +- `Dependencies`: Any external libraries you wish to use. See next section. |
| 73 | + |
| 74 | +#### 4. Using External Libraries |
| 75 | + |
| 76 | +To use any external libraries, you need to specify them in the Dependencies section. |
| 77 | +Here's a quick run down on the important fields |
| 78 | + |
| 79 | +- `Source`: This specifies the source of the external dependency. |
| 80 | +It can either be type `Git` or `Local` where it will clone the repository if it is `Git` or |
| 81 | +copy the library folder in the filesystem if it is `Local` |
| 82 | +- `LibraryType`: This specifies the dependency type to be either `Static`, `Object`, `Shared` |
| 83 | +or `Header` |
| 84 | +- `IncludePaths`: The include paths relative to the root of the dependency folder |
| 85 | +- `LinkProperties`: Settings for linking |
| 86 | +- `Setup`, `Build` and `Cleanup`: List of shell commands for one time setup, building and |
| 87 | +cleaning up |
| 88 | + |
| 89 | +To access the source files of the dependencies, you can specify runcpp2 to build locally at |
| 90 | +where it is invoked from by passing the `--local` flag. This is useful when you want to |
| 91 | +look at the headers of the dependencies. |
| 92 | + |
| 93 | +```shell |
| 94 | +runcpp2 --local ./script.cpp |
| 95 | +``` |
121 | 96 |
|
| 97 | +This will create a `.runcpp2` folder and all the builds and dependencies will be inside it. |
0 commit comments