Skip to content
Merged
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
51 changes: 51 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: build

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
MKN_LIB_LINK_LIB: 1
MKN_KUL_GIT_CO: --depth 1

jobs:
ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- run: |
curl -Lo mkn https://github.com/mkn/mkn/releases/download/latest/mkn_nix
chmod +x mkn
KLOG=2 ./mkn clean build run -dtOa "-std=c++20 -fPIC"

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v6
- run: |
curl -Lo mkn https://github.com/mkn/mkn/releases/download/latest/mkn_arm_osx
chmod +x mkn
KLOG=2 ./mkn clean build run -dtOa "-std=c++20 -fPIC"

windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v6
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64

- shell: cmd
env:
MKN_CL_PREFERRED: 1
run: | # /bin/link interferes with cl/link.exe
bash -c "rm /bin/link"
bash -c 'curl -Lo mkn.exe https://github.com/mkn/mkn/releases/download/latest/mkn.exe'
SET KLOG=2
mkn clean build run -dtOa "-EHsc -std:c++20"
23 changes: 0 additions & 23 deletions .github/workflows/build_nix.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/build_osx.yml

This file was deleted.

27 changes: 0 additions & 27 deletions .github/workflows/build_win.yml

This file was deleted.

4 changes: 2 additions & 2 deletions mkn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ parent: base
src: mod.cpp
mode: shared
if_arg:
win_shared: -DYAML_CPP_DLL
win_static: -DYAML_CPP_STATIC_DEFINE
shared: -DKUL_SHARED

profile:
Expand All @@ -21,7 +21,7 @@ profile:
parent: base
main: test.cpp
if_arg:
win_shared: -DYAML_CPP_DLL
win_static: -DYAML_CPP_STATIC_DEFINE

- name: format
mod: |
Expand Down
195 changes: 99 additions & 96 deletions mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,117 +28,120 @@ 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 <cstdint>
#include "maiken/module/init.hpp"

#include <cstdint>
#include <unordered_set>

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

class SwigModule : public maiken::Module {
private:
bool pyconfig_found = 0;
std::string HOME, SWIG = "swig",
PATH = mkn::kul::env::GET("PATH");

protected:

static void VALIDATE_NODE(const YAML::Node& node) {
using namespace mkn::kul::yaml;
Validator(
{
NodeValidator("src", 1), // TODO : add regex
NodeValidator("inc"), // TODO : add regex
NodeValidator("conf"),
NodeValidator("outdir"),
NodeValidator("objdir"),
NodeValidator("objfile"),
}
).validate(node);
}

public:
SwigModule(){
if(mkn::kul::env::EXISTS("SWIG")) SWIG = mkn::kul::env::GET("SWIG");
}
void compile(maiken::Application& a, const YAML::Node& node)
KTHROW(std::exception) override {
VALIDATE_NODE(node);

std::string conf = "-python -c++";
if(node["conf"]) conf = node["conf"].Scalar();
std::stringstream incs;
if(node["inc"])
for(const auto inc : mkn::kul::cli::asArgs(node["inc"].Scalar()))
incs << "-I" << inc << " ";

for(const auto source : mkn::kul::cli::asArgs(node["src"].Scalar())){
mkn::kul::File src(source);
if(!src) {
KERR << "WARNING: Source does not exist: " << src.full();
continue;
}

std::string outdir = src.dir().escm(), objdir = src.dir().escm();
if(node["outdir"]) outdir = node["outdir"].Scalar();
if(node["objdir"]) outdir = node["objdir"].Scalar();

mkn::kul::File objfile(src.name()+".cpp", objdir);
if(node["objfile"]) objfile = mkn::kul::File(node["objfile"].Scalar(), objdir);

mkn::kul::Process p(SWIG);
p << conf << incs.str();
p << "-outdir" << outdir;
p << "-o" << objfile.escm() << src.escm();
KLOG(DBG) << p;
p.start();
private:
bool pyconfig_found = 0;
std::string HOME, SWIG = "swig", PATH = mkn::kul::env::GET("PATH");

protected:
static void VALIDATE_NODE(const YAML::Node& node) {
using namespace mkn::kul::yaml;
Validator({
NodeValidator("src", 1), // TODO : add regex
NodeValidator("inc"), // TODO : add regex
NodeValidator("conf"),
NodeValidator("outdir"),
NodeValidator("objdir"),
NodeValidator("objfile"),
})
.validate(node);
}

a.m_cInfo.lib_ext = mkn::kul::String::LINES(extension())[0]; // drop EOL
a.m_cInfo.lib_prefix = "";
KLOG(TRC);
a.mode(maiken::compiler::Mode::SHAR);
KLOG(TRC);
}
protected:
std::string extension(){
auto pyconfig = mkn::kul::env::GET("PY3_CONFIG", "python3-config");
public:
SwigModule() {
if (mkn::kul::env::EXISTS("SWIG"))
SWIG = mkn::kul::env::GET("SWIG");
}
void compile(maiken::Application& a, const YAML::Node& node)
KTHROW(std::exception) override {

VALIDATE_NODE(node);

std::string conf = "-python -c++";
if (node["conf"])
conf = node["conf"].Scalar();
std::stringstream incs;
if (node["inc"])
for (const auto inc : mkn::kul::cli::asArgs(node["inc"].Scalar()))
incs << "-I" << inc << " ";

for (const auto source : mkn::kul::cli::asArgs(node["src"].Scalar())) {
mkn::kul::File src(source);
if (!src) {
KERR << "WARNING: Source does not exist: " << src.full();
continue;
}

std::string outdir = src.dir().escm(), objdir = src.dir().escm();
if (node["outdir"])
outdir = node["outdir"].Scalar();
if (node["objdir"])
outdir = node["objdir"].Scalar();

mkn::kul::File objfile(src.name() + ".cpp", objdir);
if (node["objfile"])
objfile = mkn::kul::File(node["objfile"].Scalar(), objdir);

mkn::kul::Process p(SWIG);
p << conf << incs.str();
p << "-outdir" << outdir;
p << "-o" << objfile.escm() << src.escm();
KLOG(DBG) << p;
p.start();
}

a.m_cInfo.lib_ext = mkn::kul::String::LINES(extension())[0]; // drop EOL
a.m_cInfo.lib_prefix = "";
KLOG(TRC);
a.mode(maiken::compiler::Mode::SHAR);
KLOG(TRC);
}

protected:
std::string extension() {
auto pyconfig = mkn::kul::env::GET("PY3_CONFIG", "python3-config");

#if defined(_WIN32)
auto pyconfig_found = false; // doesn't exist on windows (generally)
auto pyconfig_found = false; // doesn't exist on windows (generally)
#else
auto pyconfig_found = mkn::kul::env::WHICH(pyconfig);
auto pyconfig_found = mkn::kul::env::WHICH(pyconfig);
#endif

std::string extension;
if (pyconfig_found) {
// mkn::kul::os::PushDir pushd(a.project().dir());
mkn::kul::Process p(pyconfig);
mkn::kul::ProcessCapture pc(p);
p << "--extension-suffix";
p.start();
extension = pc.outs();
} else {
auto py = mkn::kul::env::GET("PYTHON", "python3");
mkn::kul::Process p(py);
mkn::kul::ProcessCapture pc(p);
p << "-c"
<< "\"import sysconfig; "
"print(sysconfig.get_config_var('EXT_SUFFIX'))\"";
p.start();
extension = pc.outs();
}
return extension;
}
std::string extension;
if (pyconfig_found) {
// mkn::kul::os::PushDir pushd(a.project().dir());
mkn::kul::Process p(pyconfig);
mkn::kul::ProcessCapture pc(p);
p << "--extension-suffix";
p.start();
extension = pc.outs();
} else {
auto py = mkn::kul::env::GET("PYTHON", "python3");
mkn::kul::Process p(py);
mkn::kul::ProcessCapture pc(p);
p << "-c"
<< "\"import sysconfig; "
"print(sysconfig.get_config_var('EXT_SUFFIX'))\"";
p.start();
extension = pc.outs();
}
return extension;
}
};
} // namespace lang
} // namespace mkn

extern "C" KUL_PUBLISH maiken::Module* maiken_module_construct() {
return new mkn::lang::SwigModule;
} // namespace mkn::lang

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

extern "C" KUL_PUBLISH void maiken_module_destruct(maiken::Module* p) {
delete p;
extern "C" MKN_KUL_PUBLISH void maiken_module_destruct(maiken::Module* p) {
delete p;
}
Loading