Skip to content

Initial coreclr and build tooling #612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
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
17 changes: 16 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,10 @@ def build_extension(self, ext):
),
shell=use_shell,
)
if DEVTOOLS == "Mono" or DEVTOOLS == "dotnet":
if DEVTOOLS == "Mono":
self._build_monoclr()
if DEVTOOLS == "dotnet":
self._build_coreclr()

def _get_manifest(self, build_dir):
if DEVTOOLS != "MsDev" and DEVTOOLS != "MsDev15":
Expand Down Expand Up @@ -403,6 +405,19 @@ def _build_monoclr(self):

build_ext.build_ext.build_extension(self, clr_ext)

def _build_coreclr(self):
# build the clr python module
clr_ext = Extension(
"clr",
sources=[
"src/coreclr/pynetinit.c",
"src/coreclr/clrmod.c",
"src/coreclr/coreutils.c",
],
)

build_ext.build_ext.build_extension(self, clr_ext)

def _install_packages(self):
"""install packages using nuget"""
use_shell = DEVTOOLS == "Mono" or DEVTOOLS == "dotnet"
Expand Down
70 changes: 70 additions & 0 deletions src/coreclr/clrmod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "pynetclr.h"

/* List of functions defined in the module */
static PyMethodDef clr_methods[] = {
{NULL, NULL, 0, NULL} /* Sentinel */
};

PyDoc_STRVAR(clr_module_doc,
"clr facade module to initialize the CLR. It's later "
"replaced by the real clr module. This module has a facade "
"attribute to make it distinguishable from the real clr module."
);

static PyNet_Args *pn_args;
char **environ = NULL;

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef clrdef = {
PyModuleDef_HEAD_INIT,
"clr", /* m_name */
clr_module_doc, /* m_doc */
-1, /* m_size */
clr_methods, /* m_methods */
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL, /* m_free */
};
#endif

static PyObject *_initclr(void)
{
PyObject *m;

/* Create the module and add the functions */
#if PY_MAJOR_VERSION >= 3
m = PyModule_Create(&clrdef);
#else
m = Py_InitModule3("clr", clr_methods, clr_module_doc);
#endif
if (m == NULL)
return NULL;
PyModule_AddObject(m, "facade", Py_True);
Py_INCREF(Py_True);

pn_args = PyNet_Init(1);
if (pn_args->error)
{
return NULL;
}

if (NULL != pn_args->module)
return pn_args->module;

return m;
}

#if PY_MAJOR_VERSION >= 3
PyMODINIT_FUNC
PyInit_clr(void)
{
return _initclr();
}
#else
PyMODINIT_FUNC
initclr(void)
{
_initclr();
}
#endif
55 changes: 55 additions & 0 deletions src/coreclr/coreclrhost.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

//
// APIs for hosting CoreCLR
//

#ifndef __CORECLR_HOST_H__
#define __CORECLR_HOST_H__

// For each hosting API, we define a function prototype and a function pointer
// The prototype is useful for implicit linking against the dynamic coreclr
// library and the pointer for explicit dynamic loading (dlopen, LoadLibrary)
#define CORECLR_HOSTING_API(function, ...) \
int function(__VA_ARGS__); \
typedef int (*function##_ptr)(__VA_ARGS__)

CORECLR_HOSTING_API(coreclr_initialize,
const char* exePath,
const char* appDomainFriendlyName,
int propertyCount,
const char** propertyKeys,
const char** propertyValues,
void** hostHandle,
unsigned int* domainId);

CORECLR_HOSTING_API(coreclr_shutdown,
void* hostHandle,
unsigned int domainId);

CORECLR_HOSTING_API(coreclr_shutdown_2,
void* hostHandle,
unsigned int domainId,
int* latchedExitCode);

CORECLR_HOSTING_API(coreclr_create_delegate,
void* hostHandle,
unsigned int domainId,
const char* entryPointAssemblyName,
const char* entryPointTypeName,
const char* entryPointMethodName,
void** delegate);

CORECLR_HOSTING_API(coreclr_execute_assembly,
void* hostHandle,
unsigned int domainId,
int argc,
const char** argv,
const char* managedAssemblyPath,
unsigned int* exitCode);

#undef CORECLR_HOSTING_API

#endif // __CORECLR_HOST_H__
Loading