Skip to content

Commit f696cb7

Browse files
Updated README and TODO, added build scripts, fixed run path and CMake
1 parent e8f07d5 commit f696cb7

File tree

6 files changed

+160
-17
lines changed

6 files changed

+160
-17
lines changed

Build.bat

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@REM @echo off
2+
3+
setlocal
4+
5+
mkdir Build || goto :error
6+
7+
pushd Build || goto :error
8+
9+
cmake .. || goto :error
10+
cmake --build . --target Embed2C || goto :error
11+
cmake .. || goto :error
12+
cmake --build . -j 16 || goto :error
13+
14+
popd
15+
16+
goto :eof
17+
18+
:error
19+
echo Error occurred during the build process.
20+
21+
goto :eof

Build.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
set -e
3+
4+
mkdir -p ./Build
5+
pushd ./Build
6+
cmake ..
7+
cmake --build . --target Embed2C
8+
cmake ..
9+
cmake --build . -j 16
10+
11+
popd
12+

CMakeLists.txt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,28 @@ else()
2626
file(SIZE "${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/DefaultYAMLs.c" EMBEDDED_FILE_SIZE)
2727
endif()
2828

29+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/Embed2C")
30+
2931
if(RUNCPP2_UPDATE_DEFAULT_YAMLS OR EMBEDDED_FILE_SIZE LESS 1024)
30-
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/Embed2C")
3132
include("${CMAKE_CURRENT_LIST_DIR}/External/Embed2C/embedFile.cmake")
3233

3334
set(EMBED_EXEC_PATH "")
3435
GET_EXEC_PATH(EMBED_EXEC_PATH)
3536

36-
set(FILES_TO_EMBED "${CMAKE_CURRENT_LIST_DIR}/DefaultYAMLs/DefaultCompilerProfiles.yaml"
37-
"DefaultCompilerProfiles"
38-
"${CMAKE_CURRENT_LIST_DIR}/DefaultYAMLs/DefaultScriptInfo.yaml"
39-
"DefaultScriptInfo"
40-
)
41-
42-
EMBED_FILES("${EMBED_EXEC_PATH}"
43-
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/DefaultYAMLs.c"
44-
"${FILES_TO_EMBED}")
37+
if("${EMBED_EXEC_PATH}" STREQUAL "")
38+
message(WARNING "Please build Embed2C first")
39+
return()
40+
else()
41+
set(FILES_TO_EMBED "${CMAKE_CURRENT_LIST_DIR}/DefaultYAMLs/DefaultCompilerProfiles.yaml"
42+
"DefaultCompilerProfiles"
43+
"${CMAKE_CURRENT_LIST_DIR}/DefaultYAMLs/DefaultScriptInfo.yaml"
44+
"DefaultScriptInfo"
45+
)
46+
47+
EMBED_FILES("${EMBED_EXEC_PATH}"
48+
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/DefaultYAMLs.c"
49+
"${FILES_TO_EMBED}")
50+
endif()
4551
endif()
4652

4753

README.md

Lines changed: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,121 @@
11
## 🏃‍♂️ runcpp2
2-
32
A cross-platform tool that can let you run any c++ file as a script, just like python!
43

54
Run c++ files anytime, anywhere.
65

76
### Prerequisites
7+
- A C++ compiler, currently only tested with g++
88

9-
TODO
9+
TODO: Support for other compilers
1010

1111
### Installation
12+
1. Clone the repository with `git clone --recursive https://github.com/Neko-Box-Coder/runcpp2.git`
13+
2. Run `Build.sh` or `Build.bat` to build
1214

13-
TODO
14-
15+
TODO: Ability to use pre-built binary
1516

1617
### How to use
1718

18-
TODO
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+
}
116+
117+
```
118+
119+
120+
</details>
19121

Src/runcpp2/runcpp2.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ namespace
4343
{
4444
std::error_code _;
4545

46-
std::string runCommand = runcpp2::ProcessPath( "cd " + scriptDirectory +
47-
" && ./" + scriptName + exeExt);
46+
std::string runCommand = runcpp2::ProcessPath(scriptDirectory + "/" + scriptName + exeExt);
4847

4948
if(!runArgs.empty())
5049
{
@@ -287,6 +286,8 @@ bool runcpp2::RunScript(const std::string& scriptPath,
287286
std::error_code copyErrorCode;
288287
ghc::filesystem::copy(exeToCopy, scriptDirectory + "/" + scriptName + exeExt, _);
289288

289+
//TODO: Copy shared library files as well
290+
290291
if(copyErrorCode)
291292
{
292293
ssLOG_ERROR("Failed to copy file from " << exeToCopy << " to " << scriptDirectory);

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- Allow script info as standalone yaml file
2+
- Copy shared libraries to be next to the executable
23
- Commandline options
34
- Allow Languages to override FileExtensions in compiler profile

0 commit comments

Comments
 (0)