Skip to content

Commit 311cda7

Browse files
committed
initial commit
0 parents  commit 311cda7

File tree

15 files changed

+820
-0
lines changed

15 files changed

+820
-0
lines changed

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
# directories
3+
.vs/
4+
.idea/
5+
data/
6+
out/
7+
8+
# python
9+
scripts/__pycache__/
10+
sandbox/__pycache__/
11+
pilotlight/__pycache__/
12+
13+
# debug files
14+
src/*.pdb
15+
16+
# build scripts
17+
src/build.bat
18+
src/build.sh
19+
20+
# misc
21+
.DS_Store

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "dependencies/cpython"]
2+
path = dependencies/cpython
3+
url = https://github.com/python/cpython

.vscode/c_cpp_properties.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Win32",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"${workspaceFolder}/src",
8+
"${workspaceFolder}/../pilotlight/libs",
9+
"${workspaceFolder}/dependencies/cpython",
10+
"${workspaceFolder}/dependencies/cpython/Include",
11+
"${workspaceFolder}/dependencies/cpython/PC"
12+
],
13+
"defines": [
14+
"_DEBUG",
15+
"UNICODE",
16+
"_UNICODE"
17+
],
18+
"windowsSdkVersion": "10.0.26100.0",
19+
"compilerPath": "cl.exe",
20+
"cStandard": "c17",
21+
"cppStandard": "c++17",
22+
"intelliSenseMode": "windows-msvc-x64"
23+
}
24+
],
25+
"version": 4
26+
}

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "(Windows) Launch",
6+
"type": "cppvsdbg",
7+
"program": "${workspaceFolder}/out/pilotlight_python.exe",
8+
"console": "integratedTerminal",
9+
"request": "launch",
10+
"args": [],
11+
"stopAtEntry": false,
12+
"cwd": "${workspaceFolder}/out/",
13+
"environment": []
14+
}
15+
]
16+
}

dependencies/cpython

Submodule cpython added at 323c59a

pilotlight/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pass

pilotlight/pilotlight.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pilotlight._pilotlight as internal_pilotlight
2+
3+
def func0():
4+
internal_pilotlight.func0()
5+
6+
def func1():
7+
return internal_pilotlight.func1()
8+
9+
def func2(x, y):
10+
return internal_pilotlight.func2(x, y)

sandbox/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
import pilotlight.pilotlight as pl
3+
4+
print("Hello from python")
5+
6+
pl.func0()
7+
print(pl.func1())
8+
print(pl.func2(2.3, 4.5))

scripts/build_python_for_win32.bat

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@echo off
2+
3+
rem get current this batch file directory
4+
set dir=%~dp0
5+
6+
:Run
7+
if "%~1"=="--ci" goto Release
8+
9+
:Debug
10+
rem clean up previous build
11+
echo Cleaning previous python builds
12+
call "%dir%..\dependencies\cpython\PCbuild\build.bat" -c Debug -p x64 -t CleanAll
13+
14+
rem build python
15+
echo Building python in Debug and Release for x64
16+
call "%dir%..\dependencies\cpython\PCbuild\build.bat" -c Debug -p x64 -t Build
17+
18+
:Release
19+
rem clean up previous build
20+
echo Cleaning previous python builds
21+
call "%dir%..\dependencies\cpython\PCbuild\build.bat" -p x64 -t CleanAll
22+
23+
rem build python
24+
echo Building python in Debug and Release for x64
25+
call "%dir%..\dependencies\cpython\PCbuild\build.bat" -p x64 -t Build
26+
27+
pause

scripts/gen_build.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# gen_examples.py
2+
3+
# Index of this file:
4+
# [SECTION] imports
5+
# [SECTION] project
6+
# [SECTION] examples
7+
# [SECTION] generate_scripts
8+
9+
#-----------------------------------------------------------------------------
10+
# [SECTION] imports
11+
#-----------------------------------------------------------------------------
12+
13+
import os
14+
import sys
15+
import platform as plat
16+
17+
import pl_build.core as pl
18+
import pl_build.backend_win32 as win32
19+
20+
#-----------------------------------------------------------------------------
21+
# [SECTION] project
22+
#-----------------------------------------------------------------------------
23+
24+
# where to output build scripts
25+
working_directory = os.path.dirname(os.path.abspath(__file__)) + "/../src"
26+
27+
with pl.project("pilotlight_python"):
28+
29+
# project wide settings
30+
pl.set_output_directory("../out")
31+
pl.add_link_directories("../out")
32+
pl.add_definitions("_USE_MATH_DEFINES")
33+
pl.add_include_directories("../src")
34+
35+
#-----------------------------------------------------------------------------
36+
# [SECTION] examples
37+
#-----------------------------------------------------------------------------
38+
39+
with pl.target("pilotlight_python", pl.TargetType.EXECUTABLE, False):
40+
41+
pl.add_include_directories(
42+
"../../pilotlight/libs",
43+
"../dependencies/cpython/",
44+
"../dependencies/cpython/Include/",
45+
"../dependencies/cpython/PC/"
46+
)
47+
48+
pl.add_source_files("main.c")
49+
pl.set_output_binary("pilotlight_python")
50+
51+
with pl.configuration("debug"):
52+
53+
# win32
54+
with pl.platform("Windows"):
55+
with pl.compiler("msvc"):
56+
pl.add_link_directories("../dependencies/cpython/PCbuild/amd64/")
57+
pl.add_linker_flags("-noimplib", "-noexp", "-incremental:no")
58+
pl.add_compiler_flags("-Zc:preprocessor", "-nologo", "-std:c11", "-W4", "-WX", "-wd4201",
59+
"-wd4100", "-wd4996", "-wd4505", "-wd4189", "-wd5105", "-wd4115",
60+
"-permissive-", "-Od", "-MDd", "-Zi")
61+
pl.set_post_target_build_step(
62+
'@copy "..\\dependencies\\cpython\\PCbuild\\amd64\\python314_d.dll" "..\\out\\" >nul\n'
63+
'@copy "..\\dependencies\\cpython\\PCbuild\\amd64\\python314.dll" "..\\out\\" >nul\n'
64+
'@copy "..\\dependencies\\cpython\\PCbuild\\amd64\\python3.dll" "..\\out\\" >nul\n'
65+
'@copy "..\\dependencies\\cpython\\PCbuild\\amd64\\python3_d.dll" "..\\out\\" >nul\n'
66+
)
67+
68+
#-----------------------------------------------------------------------------
69+
# [SECTION] examples
70+
#-----------------------------------------------------------------------------
71+
72+
with pl.target("pilotlight", pl.TargetType.DYNAMIC_LIBRARY, False):
73+
74+
pl.add_include_directories(
75+
"../../pilotlight/libs",
76+
"../dependencies/cpython/",
77+
"../dependencies/cpython/Include/",
78+
"../dependencies/cpython/PC/"
79+
)
80+
81+
pl.add_source_files("module_pilotlight.c")
82+
pl.set_output_binary("_pilotlight")
83+
84+
with pl.configuration("distribute"):
85+
86+
# win32
87+
with pl.platform("Windows"):
88+
with pl.compiler("msvc"):
89+
pl.set_output_binary_extension(".pyd")
90+
pl.add_link_directories("../dependencies/cpython/PCbuild/amd64/")
91+
pl.add_linker_flags("-noimplib", "-noexp", "-incremental:no")
92+
pl.add_compiler_flags("-Zc:preprocessor", "-nologo", "-std:c11", "-W4", "-WX", "-wd4201",
93+
"-wd4100", "-wd4996", "-wd4505", "-wd4189", "-wd5105", "-wd4115",
94+
"-permissive-", "-Od", "-MD", "-Zi")
95+
96+
97+
98+
99+
#-----------------------------------------------------------------------------
100+
# [SECTION] generate scripts
101+
#-----------------------------------------------------------------------------
102+
103+
win32.generate_build(working_directory + '/' + "build.bat")

0 commit comments

Comments
 (0)