Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Build with mono on linux and add travis-ci settings #8

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

Merged
merged 1 commit into from
Feb 20, 2014
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
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: python
python:
- 2.7
before_install:
- sudo apt-get install software-properties-common
- sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ trusty main universe"
- sudo apt-get -qq update
- sudo apt-get -qq install mono-devel mono-gmcs mono-xbuild nunit-console
install:
- cd pythonnet
- python setupmono.py build_ext --inplace
script:
- export PYTHONPATH=`pwd`
- ./npython src/tests/runtests.py
8 changes: 0 additions & 8 deletions pythonnet/pythonnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,10 @@ Global
{E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWin|x64.Build.0 = Release|x64
{E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWin|x86.ActiveCfg = Release|x86
{E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWin|x86.Build.0 = Release|x86
{86E834DE-1139-4511-96CC-69636A56E7AC}.DebugMono|x64.ActiveCfg = DebugMono|x64
{86E834DE-1139-4511-96CC-69636A56E7AC}.DebugMono|x64.Build.0 = DebugMono|x64
{86E834DE-1139-4511-96CC-69636A56E7AC}.DebugMono|x86.ActiveCfg = DebugMono|x86
{86E834DE-1139-4511-96CC-69636A56E7AC}.DebugMono|x86.Build.0 = DebugMono|x86
{86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWin|x64.ActiveCfg = DebugWin|x64
{86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWin|x64.Build.0 = DebugWin|x64
{86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWin|x86.ActiveCfg = DebugWin|x86
{86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWin|x86.Build.0 = DebugWin|x86
{86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64
{86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseMono|x64.Build.0 = ReleaseMono|x64
{86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86
{86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseMono|x86.Build.0 = ReleaseMono|x86
{86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64
{86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWin|x64.Build.0 = ReleaseWin|x64
{86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86
Expand Down
141 changes: 141 additions & 0 deletions pythonnet/setupmono.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
"""
Setup script for building clr.pyd and dependencies using mono and into
an egg or wheel.
"""
from setuptools import setup, Extension
from distutils.command.build_ext import build_ext
from distutils.sysconfig import get_config_vars
from platform import architecture
from subprocess import check_output, check_call
import shutil
import sys
import os

CONFIG = "Release" # Release or Debug
DEVTOOLS = "Mono" # Mono or MsDev
VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic

if DEVTOOLS == "MsDev":
from distutils import msvc9compiler
msvc9compiler.VERSION = 11

cc = msvc9compiler.MSVCCompiler()
cc.initialize()
_xbuild = cc.find_exe("msbuild.exe")
_defines_sep = ";"
_config = "%sWin" % CONFIG

elif DEVTOOLS == "Mono":
_xbuild = "xbuild"
_defines_sep = ","
_config = "%sMono" % CONFIG

else:
raise NotImplementedError("DevTools %s not supported (use MsDev or Mono)" % DEVTOOLS)

_platform = "x64" if architecture()[0] == "64bit" else "x86"

class PythonNET_BuildExt(build_ext):

def build_extension(self, ext):
"""
Builds the .pyd file using msbuild or xbuild.
"""
if ext.name != "clr":
return super(PythonNET_BuildExt, self).build_extension(ext)

dest_file = self.get_ext_fullpath(ext.name)
dest_dir = os.path.dirname(dest_file)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)

defines = [
"PYTHON%d%s" % (sys.version_info[:2]),
"UCS2" if sys.maxunicode < 0x10FFFF else "UCS4",
]

if CONFIG == "Debug":
defines.extend(["DEBUG", "TRACE"])

cmd = [
_xbuild,
"pythonnet.sln",
"/p:Configuration=%s" % _config,
"/p:Platform=%s" % _platform,
"/p:DefineConstants=\"%s\"" % _defines_sep.join(defines),
"/p:PythonBuildDir=%s" % os.path.abspath(dest_dir),
"/p:NoNuGet=true",
"/verbosity:%s" % VERBOSITY,
]

self.announce("Building: %s" % " ".join(cmd))
check_call(" ".join(cmd) + " /t:Clean", shell=True)
check_call(" ".join(cmd) + " /t:Build", shell=True)

if DEVTOOLS == "Mono":
self._build_monoclr(ext)


def _build_monoclr(self, ext):
mono_libs = check_output("pkg-config --libs mono-2", shell=True)
mono_cflags = check_output("pkg-config --cflags mono-2", shell=True)
glib_libs = check_output("pkg-config --libs glib-2.0", shell=True)
glib_cflags = check_output("pkg-config --cflags glib-2.0", shell=True)
cflags = mono_cflags.strip() + " " + glib_cflags.strip()
libs = mono_libs.strip() + " " + glib_libs.strip()

# build the clr python module
setup(name="monoclr",
ext_modules=[
Extension("clr",
sources=[
"src/monoclr/pynetinit.c",
"src/monoclr/clrmod.c"
],
extra_compile_args=cflags.split(" "),
extra_link_args=libs.split(" "),
)]
)

# build the clr python executable
sources = [
"src/monoclr/pynetinit.c",
"src/monoclr/python.c",
]

macros = ext.define_macros[:]
for undef in ext.undef_macros:
macros.append((undef,))

objects = self.compiler.compile(sources,
output_dir=self.build_temp,
macros=macros,
include_dirs=ext.include_dirs,
debug=self.debug,
extra_postargs=cflags.split(" "),
depends=ext.depends)

output_dir = os.path.dirname(self.get_ext_fullpath(ext.name))
py_libs = get_config_vars("BLDLIBRARY")[0]
libs += " " + py_libs

self.compiler.link_executable(objects,
"npython",
output_dir=output_dir,
libraries=self.get_libraries(ext),
library_dirs=ext.library_dirs,
runtime_library_dirs=ext.runtime_library_dirs,
extra_postargs=libs.split(" "),
debug=self.debug)


if __name__ == "__main__":
setup(name="pythonnet",
ext_modules=[
Extension("clr", sources=[])
],
cmdclass = {
"build_ext" : PythonNET_BuildExt
}
)

40 changes: 13 additions & 27 deletions pythonnet/src/clrmodule/clrmodule.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)</PythonBuildDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\DebugMono\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
Expand All @@ -29,7 +30,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugMono|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\DebugMono\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
Expand All @@ -39,8 +40,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseMono|x86'">
<OutputPath>bin\x86\ReleaseMono\</OutputPath>
<DefineConstants>
</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''"></DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
Expand All @@ -51,8 +51,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseMono|x64'">
<OutputPath>bin\x64\ReleaseMono\</OutputPath>
<DefineConstants>
</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''"></DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
Expand All @@ -64,7 +63,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugWin|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\DebugWin\</OutputPath>
<DefineConstants>TRACE;DEBUG;DEBUG_PRINT</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;DEBUG_PRINT</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
Expand All @@ -75,7 +74,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugWin|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\DebugWin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
Expand All @@ -85,8 +84,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseWin|x86'">
<OutputPath>bin\x86\ReleaseWin\</OutputPath>
<DefineConstants>
</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''"></DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
Expand All @@ -97,8 +95,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseWin|x64'">
<OutputPath>bin\x64\ReleaseWin\</OutputPath>
<DefineConstants>
</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''"></DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
Expand All @@ -122,20 +119,9 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>del "$(SolutionDir)clr.pyd"</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>move "$(TargetPath)" "$(TargetDir)clr.pyd"
copy "$(TargetDir)clr.pyd" "$(SolutionDir)"</PostBuildEvent>
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="../../packages/UnmanagedExports.1.2.3-Beta/tools/RGiesecke.DllExport.targets" Condition="Exists('../../packages/UnmanagedExports.1.2.3-Beta/tools/RGiesecke.DllExport.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="'$(NoNuGet)' != 'true' And Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="..\..\packages\UnmanagedExports.1.2.3-Beta\tools\RGiesecke.DllExport.targets" Condition="Exists('..\..\packages\UnmanagedExports.1.2.3-Beta\tools\RGiesecke.DllExport.targets')"/>
<Target Name="AfterBuild" DependsOnTargets="RGieseckeDllExport">
<Copy SourceFiles="$(TargetPath)" DestinationFiles="$(PythonBuildDir)\clr.pyd" />
</Target>
-->
</Project>
Loading