Skip to content

Commit eaf916b

Browse files
committed
++
1 parent d6db77a commit eaf916b

8 files changed

Lines changed: 155 additions & 114 deletions

File tree

.github/workflows/build.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: build
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
push:
9+
branches: [ master ]
10+
pull_request:
11+
branches: [ master ]
12+
13+
env:
14+
MKN_KUL_GIT_CO: --depth 1
15+
16+
jobs:
17+
ubuntu:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v6
21+
22+
- run: uname -a
23+
24+
- env:
25+
MKN_LIB_LINK_LIB: 1
26+
run: |
27+
curl -fL --retry 3 --retry-delay 2 -o mkn https://github.com/mkn/mkn/releases/download/latest/mkn_nix
28+
chmod +x mkn
29+
KLOG=2 ./mkn clean build run -dtOa "-std=c++20 -fPIC"
30+
KLOG=2 ./mkn clean build -dtOa "-std=c++20 -fPIC" -p test_module
31+
python3 -c "import test_module as tm; tm.lol()"
32+
33+
macos:
34+
runs-on: macos-latest
35+
steps:
36+
- uses: actions/checkout@v6
37+
38+
- env:
39+
MKN_LIB_LINK_LIB: 1
40+
run: |
41+
curl -fL --retry 3 --retry-delay 2 -o mkn https://github.com/mkn/mkn/releases/download/latest/mkn_arm_osx
42+
chmod +x mkn
43+
KLOG=2 ./mkn clean build run -dtOa "-std=c++20 -fPIC"
44+
KLOG=2 ./mkn clean build -dtOa "-std=c++20 -fPIC" -p test_module
45+
python3 -c "import test_module as tm; tm.lol()"
46+
47+
windows:
48+
runs-on: windows-latest
49+
steps:
50+
- uses: actions/checkout@v6
51+
52+
- uses: ilammy/msvc-dev-cmd@v1
53+
with:
54+
arch: amd64
55+
56+
- env:
57+
MKN_CL_PREFERRED: 1
58+
shell: cmd
59+
run: | # /bin/link interferes with cl/link.exe
60+
bash -c "rm /bin/link"
61+
bash -c 'curl -Lo mkn.exe https://github.com/mkn/mkn/releases/download/latest/mkn.exe'
62+
bash -c 'KLOG=2 ./mkn clean build run -dtOa "-EHsc -std:c++20"'
63+
bash -c 'KLOG=2 ./mkn clean build run -dtOp test -a "-EHsc -std:c++20"'
64+
bash -c 'KLOG=2 ./mkn clean build -dtOp test_module -a "-EHsc -std:c++20"'
65+
bash -c 'python3 -c "import test_module as tm; tm.lol()"'

.github/workflows/build_nix.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/build_osx.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/build_win.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

mkn.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ profile:
2121
dep: mkn&${maiken_location}(${maiken_scm})[lib]
2222
main: test.cpp
2323

24+
- name: test_module
25+
dep: lang.pybind11
26+
src: test_module.cpp
27+
mod: python3.module lang.python3
28+
out: test_module
29+
install: .
30+
2431
- name: format
2532
mod: |
2633
clang.format{init{style: google, paths: .}}

mod.cpp

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4242
#include "mkn/kul/except.hpp" // for Exception, KEXCEPT, KTHROW
4343
#include "mkn/kul/string.hpp" // for String
4444

45-
#include <memory> // for shared_ptr, make_shared
4645
#include <string> // for basic_string, string
4746
#include <vector> // for vector
4847
#include <stdlib.h> // for exit
@@ -54,54 +53,72 @@ class Node;
5453
namespace mkn {
5554
namespace python3 {
5655

56+
// kul::File find_python3() KTHROW(std::exception) {
57+
// //
58+
// std::string bin = "python3";
59+
60+
// return std::string{};
61+
// }
62+
63+
std::string pyexec_for_string(std::string const& cmd) {
64+
mkn::kul::Process p("python3");
65+
mkn::kul::ProcessCapture pc(p);
66+
p << "-c" << cmd;
67+
p.start();
68+
return pc.outs();
69+
}
70+
5771
class ModuleMaker : public maiken::Module {
5872
public:
59-
void init(maiken::Application& a, YAML::Node const& /*node*/) KTHROW(std::exception) override {
60-
if (!kul::env::WHICH(PY.c_str())) PY = "python";
61-
PYTHON = mkn::kul::env::GET("PYTHON");
62-
if (!PYTHON.empty()) PY = PYTHON;
73+
// ModuleMaker() : PY{find_python3()} {}
74+
void init(maiken::Application& a, YAML::Node const& /*node*/) KTHROW(std::exception) override;
75+
76+
private:
77+
auto python3_executable() const { return pyexec_for_string("import sys; print(sys.executable)"); }
78+
auto python3_extension_suffix() const {
79+
return pyexec_for_string("\"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))\"");
80+
}
81+
82+
// auto static find_python3();
83+
84+
// std::string const PY = find_python3();
85+
// std::string HOME, PY = "python3", PYTHON, PATH = mkn::kul::env::GET("PATH");
86+
// mkn::kul::Dir bin;
87+
};
88+
89+
void ModuleMaker::init(maiken::Application& a, YAML::Node const& /*node*/)
90+
KTHROW(std::exception) { /*
91+
if (!kul::env::WHICH(PY.c_str())) PY = "python";
92+
PYTHON = mkn::kul::env::GET("PYTHON");
93+
if (!PYTHON.empty()) PY = PYTHON;
6394
#if defined(_WIN32)
64-
if (PY.rfind(".exe") == std::string::npos) PY += ".exe";
95+
if (PY.rfind(".exe") == std::string::npos) PY += ".exe";
6596
#endif
66-
mkn::kul::Process p(PY);
67-
mkn::kul::ProcessCapture pc(p);
68-
HOME = mkn::kul::env::GET("PYTHON3_HOME");
69-
if (!HOME.empty()) {
97+
mkn::kul::Process p(PY);
98+
mkn::kul::ProcessCapture pc(p);
99+
HOME = mkn::kul::env::GET("PYTHON3_HOME");
100+
if (!HOME.empty()) {
70101
#if defined(_WIN32)
71-
bin = mkn::kul::Dir(HOME);
72-
if (!bin) KEXCEPT(kul::Exception, "$PYTHON3_HOME does not exist");
102+
bin = mkn::kul::Dir(HOME);
103+
if (!bin) KEXCEPT(kul::Exception, "$PYTHON3_HOME does not exist");
73104
#else
74-
bin = mkn::kul::Dir("bin", HOME);
75-
if (!bin) KEXCEPT(kul::Exception, "$PYTHON3_HOME/bin does not exist");
105+
bin = mkn::kul::Dir("bin", HOME);
106+
if (!bin) KEXCEPT(kul::Exception, "$PYTHON3_HOME/bin does not exist");
76107
#endif
77-
path_var =
78-
std::make_shared<kul::cli::EnvVar>("PATH", bin.real(), mkn::kul::cli::EnvVarMode::PREP);
79-
mkn::kul::env::SET(path_var->name(), path_var->toString().c_str());
80-
p.var(path_var->name(), path_var->toString());
81-
};
82-
83-
auto const extension =
84-
pyexec_for_string("\"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))\"");
85-
86-
a.m_cInfo.lib_ext = mkn::kul::String::LINES(extension)[0]; // drop EOL
87-
a.m_cInfo.lib_prefix = "";
88-
a.mode(maiken::compiler::Mode::SHAR);
89-
}
108+
kul::cli::EnvVar const path_var{"PATH", bin.real(), mkn::kul::cli::EnvVarMode::PREP};
90109
91-
private:
92-
std::string pyexec_for_string(std::string const& cmd) {
93-
mkn::kul::Process p(PY);
94-
mkn::kul::ProcessCapture pc(p);
95-
p << "-c" << cmd;
96-
p.start();
97-
return pc.outs();
98-
}
110+
mkn::kul::env::SET(path_var.name(), path_var.toString().c_str());
111+
p.var(path_var.name(), path_var.toString());
112+
}*/
113+
114+
auto const extension =
115+
pyexec_for_string("\"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))\"");
116+
117+
a.m_cInfo.lib_ext = mkn::kul::String::LINES(extension)[0]; // drop EOL
118+
a.m_cInfo.lib_prefix = "";
119+
a.mode(maiken::compiler::Mode::SHAR);
120+
}
99121

100-
std::string HOME, PY = "python3", PYTHON, PY_CONFIG = "python-config",
101-
PY3_CONFIG = "python3-config", PATH = mkn::kul::env::GET("PATH");
102-
mkn::kul::Dir bin;
103-
std::shared_ptr<kul::cli::EnvVar> path_var;
104-
};
105122
} // namespace python3
106123
} // namespace mkn
107124

test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
const std::string yArgs = "";
99

1010
int main(int argc, char *argv[]) {
11+
KOUT(NON) << __FILE__;
1112
mkn::kul::Signal sig;
1213
try {
1314
YAML::Node node = mkn::kul::yaml::String(yArgs).root();

test_module.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
4+
// #include <pybind11/functional.h>
5+
#include <pybind11/pybind11.h>
6+
// #include <pybind11/numpy.h>
7+
// #include <pybind11/stl.h>
8+
9+
10+
#include <iostream>
11+
12+
13+
void lol()
14+
{
15+
std::cout << "lol" << std::endl;
16+
}
17+
18+
19+
20+
PYBIND11_MODULE(test_module, m, pybind11::mod_gil_not_used())
21+
{
22+
23+
m.def("lol", lol, "lol");
24+
25+
}

0 commit comments

Comments
 (0)