Skip to content
Merged

++ #14

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
29 changes: 8 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,32 @@ jobs:
ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- env:
MKN_KUL_GIT_CO: --depth 1
run: |
- uses: actions/checkout@v6
- run: |
$CURL_GET -o mkn ${PATH_GET}/mkn_nix
chmod +x mkn
KLOG=2 ./mkn clean build run -dtOa "-std=c++20 -fPIC"
KLOG=2 ./mkn clean build run -dtOp test -a "-std=c++20 -fPIC"
PATH=$PWD:$PATH ./res/ci/linux.sh

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

- env:
MKN_LIB_LINK_LIB: 1
MKN_KUL_GIT_CO: --depth 1
run: |
- uses: actions/checkout@v6
- run: |
$CURL_GET -o mkn ${PATH_GET}/mkn_arm_osx
chmod +x mkn
KLOG=2 ./mkn clean build run -dtOa "-std=c++20 -fPIC"
KLOG=2 ./mkn clean build run -dtOp test -a "-std=c++20 -fPIC"

windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- uses: actions/checkout@v6
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64

- env:
MKN_KUL_GIT_CO: --depth 1
- shell: cmd
env:
MKN_CL_PREFERRED: 1
shell: cmd
run: | # /bin/link interferes with cl/link.exe
bash -c "rm /bin/link"
bash -c '$CURL_GET -o mkn.exe ${PATH_GET}/mkn.exe'
bash -c 'KLOG=2 ./mkn clean build run -dtOa "-EHsc -std:c++20"'
bash -c 'KLOG=2 ./mkn clean build run -dtOp test -a "-EHsc -std:c++20"'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Compile/Link phase module

## Prerequisites
[maiken](https://github.com/Dekken/maiken)
[maiken](https://github.com/mkn/mkn)

## Usage

Expand Down
17 changes: 6 additions & 11 deletions mkn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@

name: lang.python3
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
main: test.cpp
dep: mkn&${maiken_location}(${maiken_scm})[lib]
shared: -DMKN_KUL_SHARED
win_static: -DYAML_CPP_STATIC_DEFINE

- name: format
mod: |
Expand Down
62 changes: 25 additions & 37 deletions mod.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
Copyright (c) 2013, Philip Deegan.
Copyright (c) 2026, Philip Deegan.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -28,31 +28,24 @@ 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 GET, SET, Var, Var::Mode
#include "mkn/kul/log.hpp" // for KERR
#include "mkn/kul/defs.hpp" // for MKN_KUL_PUBLISH
#include "mkn/kul/proc.hpp" // for Process, ProcessCapture, AProcess
#include "mkn/kul/yaml.hpp" // for NodeValidator, Validator
#include "maiken/project.hpp" // for Project
#include "mkn/kul/except.hpp" // for Exception, KEXCEPT, KTHROW
#include "mkn/kul/string.hpp" // for String

#include <string> // for basic_string, string
#include <vector> // for vector
#include <sstream> // for stringstream
#include <stdlib.h> // for exit
#include <exception> // for exception
#include <stdexcept> // for exception

namespace mkn {
namespace lang {
namespace mkn::lang {

kul::File find_python3() KTHROW(std::exception) {
std::string const HOME = kul::env::GET("PYTHON3_HOME");
Expand Down Expand Up @@ -83,8 +76,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};
}

kul::File find_python_set_env() {
Expand Down Expand Up @@ -113,15 +106,15 @@ std::string pyexec_for_string(std::string const& cmd) {
throw;
}
auto ret = kul::String::LINES(pc.outs())[0];
if(ret.back() == '\n') ret.pop_back();
if(ret.back() == '\r') ret.pop_back();
if (ret.back() == '\n') ret.pop_back();
if (ret.back() == '\r') ret.pop_back();
return ret;
}

class Python3Module : public maiken::Module {
class Python3Module : public mkn::mod::Module {
public:
void compile(maiken::Application& a, YAML::Node const& node) KTHROW(std::exception) override;
void link(maiken::Application& a, YAML::Node const& node) KTHROW(std::exception) override;
void compile(mkn::mod::Context& a, YAML::Node const& node) KTHROW(std::exception) override;
void link(mkn::mod::Context& a, YAML::Node const& node) KTHROW(std::exception) override;

private:
auto py_include() const {
Expand Down Expand Up @@ -176,7 +169,7 @@ class Python3Module : public maiken::Module {
}
};

void Python3Module::compile(maiken::Application& a, YAML::Node const& node) KTHROW(std::exception) {
void Python3Module::compile(mkn::mod::Context& a, YAML::Node const& node) KTHROW(std::exception) {
VALIDATE_NODE(node);

std::vector<std::string> incs{py_include()};
Expand All @@ -199,10 +192,10 @@ void Python3Module::compile(maiken::Application& a, YAML::Node const& node) KTHR
}
for (auto const& inc : incs) {
kul::Dir const req_include(inc);

if (req_include) {
a.addInclude(req_include.real());
for (auto* rep : a.revendencies()) rep->addInclude(req_include.real());
a.compilerState().add(mkn::mod::IncludeInput{req_include.real()});
for (auto* rep : a.state().dependents)
rep->compilerState().add(mkn::mod::IncludeInput{req_include.real()});
}
}
} catch (kul::Exception const& e) {
Expand All @@ -214,7 +207,7 @@ void Python3Module::compile(maiken::Application& a, YAML::Node const& node) KTHR
}
}

void Python3Module::link(maiken::Application& a, YAML::Node const& node) KTHROW(std::exception) {
void Python3Module::link(mkn::mod::Context& a, YAML::Node const& node) KTHROW(std::exception) {
VALIDATE_NODE(node);

auto const embed = kul::String::BOOL(kul::env::GET("MKN_PYTHON_LIB_EMBED", "0"));
Expand All @@ -223,30 +216,25 @@ void Python3Module::link(maiken::Application& a, YAML::Node const& node) KTHROW(
auto const prefx = py_prefix();

if (prefx.size())
if (auto const lib = kul::Dir(kul::Dir::JOIN(prefx, "lib"))) a.addLibpath(lib.real());

#if defined(_WIN32) // or fallback
if (prefx.size())
if (auto const lib = kul::Dir{"libs", python_exe.dir()}) // windows fallback
a.addLibpath(lib.escm());
#endif
if (auto const lib = kul::Dir(kul::Dir::JOIN(prefx, "lib")))
a.compilerState().add(mkn::mod::LibPathInput{lib.real()});

#if defined(_WIN32) // or fallback
if (prefx.size())
if (auto const lib = kul::Dir{"libs", python_exe.dir()}) // windows fallback
a.addLibpath(lib.escm());
a.compilerState().add(mkn::mod::LibPathInput{lib.escm()});
#endif

if (embed) a.addLib(py_libname());
if (embed) a.compilerState().add(mkn::mod::LibInput{py_libname()});

if (a.mode() != maiken::compiler::Mode::STAT) a.prependLinkString(linker);
if (a.state().buildMode != mkn::mod::Mode::STAT)
a.compilerState().add(mkn::mod::LinkPrefixInput{linker});
}

} // namespace lang
} // namespace mkn
} // namespace mkn::lang

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

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; }
4 changes: 4 additions & 0 deletions res/ci/linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -ex

KLOG=2 mkn clean build run -dtOa "-std=c++20 -fPIC"
35 changes: 0 additions & 35 deletions test.cpp

This file was deleted.

Loading