Skip to content
Merged

++ #9

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

name: build

concurrency:
Expand All @@ -11,7 +12,6 @@ on:
branches: [ master ]

env:
MKN_LIB_LINK_LIB: 1
MKN_KUL_GIT_CO: --depth 1
CURL_GET: curl -fL --retry 3 --retry-delay 2
PATH_GET: https://github.com/mkn/mkn/releases/download/latest
Expand All @@ -27,13 +27,11 @@ jobs:
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: |
set -ex
$CURL_GET -o mkn ${PATH_GET}/mkn_nix
chmod +x mkn
KLOG=3 ./mkn clean build run -dtOa "-std=c++20 -fPIC"
KLOG=3 ./mkn clean build -dtOa "-std=c++20 -fPIC" -p test_module
python3 -c "import test_module as tm; tm.lol()"
PATH=$PWD:$PATH ./res/ci/linux.sh

macos:
runs-on: macos-latest
Expand All @@ -45,12 +43,12 @@ jobs:
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
architecture: arm64
- run: |
set -ex
$CURL_GET -o mkn ${PATH_GET}/mkn_arm_osx
chmod +x mkn
KLOG=3 ./mkn clean build run -dtOa "-std=c++20 -fPIC"
KLOG=3 ./mkn clean build run -dtOa "-std=c++20 -fPIC" -p test

windows:
runs-on: windows-latest
Expand All @@ -62,14 +60,17 @@ jobs:
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64
- env:
MKN_CL_PREFERRED: 1
shell: bash
run: | # /bin/link interferes with cl/link.exe
set -ex
rm /bin/link
$CURL_GET -o mkn.exe ${PATH_GET}/mkn.exe
KLOG=3 ./mkn clean build run -dtOa "-EHsc -std:c++20"
KLOG=3 ./mkn clean build run -dtOp test -a "-EHsc -std:c++20"
KLOG=3 ./mkn clean build -dtOa "-std:c++20 -EHsc" -p test_module
KLOG=3 ./mkn clean build run -dtKOa "-EHsc -std:c++20 -DYAML_CPP_STATIC_DEFINE"
KLOG=3 ./mkn clean build -dtKOa "-std:c++20 -EHsc -DYAML_CPP_STATIC_DEFINE" -p test_module
python3 -c "import test_module as tm; tm.lol()"
20 changes: 9 additions & 11 deletions mkn.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@

name: python3.module
version: master
property:
maiken_location: ${MKN_HOME}/app/mkn/${version}
maiken_scm: https://github.com/mkn/mkn

parent: base
src: mod.cpp
mode: shared

profile:
- name: base
dep: mkn&${maiken_location}(${maiken_scm})[mod]
dep: mkn.mod
if_dep:
bsd: parse.yaml[lib]
win: parse.yaml[lib]
if_arg:
win_shared: -DYAML_CPP_DLL
shared: -DMKN_KUL_SHARED

- name: test
parent: base
dep: mkn&${maiken_location}(${maiken_scm})[lib]
main: test.cpp
shared: -DMKN_KUL_SHARED
win: -DYAML_CPP_STATIC_DEFINE

- name: test_module
dep: lang.pybind11
src: test_module.cpp
mod: python3.module lang.python3
out: test_module
install: .
mode: shared
if_arg:
win: -DYAML_CPP_STATIC_DEFINE

- name: format
mod: |
Expand Down
41 changes: 20 additions & 21 deletions mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,16 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "maiken/module/init.hpp" // IWYU pragma: keep

#include "maiken/app.hpp" // for Application
#include "maiken/compiler.hpp" // for CompilationInfo, Mode
#include "mkn/mod/init.hpp" // IWYU pragma: keep

#include "mkn/kul/os.hpp" // for Dir, WHICH, PushDir
#include "mkn/kul/cli.hpp" // for EnvVar, EnvVarMode
#include "mkn/kul/env.hpp" // for GET, SET
#include "mkn/kul/env.hpp" // for Var, Var::Mode, GET, SET
#include "mkn/kul/dbg.hpp" // for TRACING
#include "mkn/kul/defs.hpp" // for MKN_KUL_PUBLISH
#include "mkn/kul/proc.hpp" // for Process, ProcessCapture, AProcess
#include "maiken/project.hpp" // for Project
#include "mkn/kul/except.hpp" // for Exception, KEXCEPT, KTHROW
#include "mkn/kul/string.hpp" // for String
#include "mkn/kul/log.hpp" // for KOUT, KLOG, KERR

#include <string> // for basic_string, string
#include <vector> // for vector
Expand All @@ -51,8 +48,7 @@ namespace YAML {
class Node;
}

namespace mkn {
namespace python3 {
namespace mkn::python3 {

kul::File find_python3() KTHROW(std::exception) {
std::string const HOME = kul::env::GET("PYTHON3_HOME");
Expand Down Expand Up @@ -83,8 +79,8 @@ kul::File find_python3() KTHROW(std::exception) {
throw std::runtime_error("Could not find python!");
}

kul::cli::EnvVar python3_path_var(kul::File const& exe) {
return {"PATH", exe.dir().real(), kul::cli::EnvVarMode::PREP};
kul::env::Var python3_path_var(kul::File const& exe) {
return {"PATH", exe.dir().real(), kul::env::Var::Mode::PREP};
}

static inline kul::File const python_exe = find_python3();
Expand All @@ -110,23 +106,26 @@ std::string pyexec_for_string(std::string const& cmd) {
return ret;
}

class ModuleMaker : public maiken::Module {
class ModuleMaker : public mkn::mod::Module {
public:
void init(maiken::Application& a, YAML::Node const& /*node*/) KTHROW(std::exception) override;
void init(mkn::mod::Context& ctx, YAML::Node const& /*node*/) KTHROW(std::exception) override;
};

void ModuleMaker::init(maiken::Application& a, YAML::Node const& /*node*/) KTHROW(std::exception) {
void ModuleMaker::init(mkn::mod::Context& ctx, YAML::Node const& /*node*/) KTHROW(std::exception) {
MKN_KUL_DBG_FUNC_ENTER;

auto const cmd = "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))";
a.m_cInfo.lib_ext = pyexec_for_string(cmd);
a.m_cInfo.lib_prefix = "";
a.mode(maiken::compiler::Mode::SHAR);
auto info = ctx.state().compileEnv.compilationInfo;
info.lib_ext = pyexec_for_string(cmd);
info.lib_prefix = "";
ctx.compilerState().add(mkn::mod::CompilationInfoInput{info});
ctx.compilerState().add(mkn::mod::BuildModeInput{mkn::mod::Mode::SHAR});
}

} // namespace python3
} // namespace mkn
} // namespace mkn::python3

extern "C" MKN_KUL_PUBLISH maiken::Module* maiken_module_construct() {
extern "C" MKN_KUL_PUBLISH mkn::mod::Module* maiken_module_construct() {
return new mkn::python3::ModuleMaker;
}

extern "C" MKN_KUL_PUBLISH void maiken_module_destruct(maiken::Module* p) { delete p; }
extern "C" MKN_KUL_PUBLISH void maiken_module_destruct(mkn::mod::Module* p) { delete p; }
6 changes: 6 additions & 0 deletions res/ci/linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -ex

KLOG=3 mkn clean build run -dtOa "-std=c++20 -fPIC"
KLOG=3 mkn clean build -dtOa "-std=c++20 -fPIC" -p test_module
python3 -c "import test_module as tm; tm.lol()"
35 changes: 0 additions & 35 deletions test.cpp

This file was deleted.

Loading