<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>4. Building C and C++ Extensions on Windows — Python v2.6.6 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '2.6.6',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python v2.6.6 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="top" title="Python v2.6.6 documentation" href="../index.html" />
<link rel="up" title="Extending and Embedding the Python Interpreter" href="index.html" />
<link rel="next" title="5. Embedding Python in Another Application" href="embedding.html" />
<link rel="prev" title="3. Building C and C++ Extensions with distutils" href="building.html" />
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../modindex.html" title="Global Module Index"
accesskey="M">modules</a> |</li>
<li class="right" >
<a href="embedding.html" title="5. Embedding Python in Another Application"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="building.html" title="3. Building C and C++ Extensions with distutils"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="../index.html">Python v2.6.6 documentation</a> »</li>
<li><a href="index.html" accesskey="U">Extending and Embedding the Python Interpreter</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="building-c-and-c-extensions-on-windows">
<span id="building-on-windows"></span><h1>4. Building C and C++ Extensions on Windows<a class="headerlink" href="#building-c-and-c-extensions-on-windows" title="Permalink to this headline">¶</a></h1>
<p>This chapter briefly explains how to create a Windows extension module for
Python using Microsoft Visual C++, and follows with more detailed background
information on how it works. The explanatory material is useful for both the
Windows programmer learning to build Python extensions and the Unix programmer
interested in producing software which can be successfully built on both Unix
and Windows.</p>
<p>Module authors are encouraged to use the distutils approach for building
extension modules, instead of the one described in this section. You will still
need the C compiler that was used to build Python; typically Microsoft Visual
C++.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This chapter mentions a number of filenames that include an encoded Python
version number. These filenames are represented with the version number shown
as <tt class="docutils literal"><span class="pre">XY</span></tt>; in practice, <tt class="docutils literal"><span class="pre">'X'</span></tt> will be the major version number and <tt class="docutils literal"><span class="pre">'Y'</span></tt>
will be the minor version number of the Python release you’re working with. For
example, if you are using Python 2.2.1, <tt class="docutils literal"><span class="pre">XY</span></tt> will actually be <tt class="docutils literal"><span class="pre">22</span></tt>.</p>
</div>
<div class="section" id="a-cookbook-approach">
<span id="win-cookbook"></span><h2>4.1. A Cookbook Approach<a class="headerlink" href="#a-cookbook-approach" title="Permalink to this headline">¶</a></h2>
<p>There are two approaches to building extension modules on Windows, just as there
are on Unix: use the <a title="Support for building and installing Python modules into an existing Python installation." class="reference external" href="../library/distutils.html#module-distutils"><tt class="xref docutils literal"><span class="pre">distutils</span></tt></a> package to control the build process, or
do things manually. The distutils approach works well for most extensions;
documentation on using <a title="Support for building and installing Python modules into an existing Python installation." class="reference external" href="../library/distutils.html#module-distutils"><tt class="xref docutils literal"><span class="pre">distutils</span></tt></a> to build and package extension modules
is available in <a class="reference external" href="../distutils/index.html#distutils-index"><em>Distributing Python Modules</em></a>. This section describes the manual
approach to building Python extensions written in C or C++.</p>
<p>To build extensions using these instructions, you need to have a copy of the
Python sources of the same version as your installed Python. You will need
Microsoft Visual C++ “Developer Studio”; project files are supplied for VC++
version 7.1, but you can use older versions of VC++. Notice that you should use
the same version of VC++that was used to build Python itself. The example files
described here are distributed with the Python sources in the
<tt class="docutils literal"><span class="pre">PC\example_nt\</span></tt> directory.</p>
<ol class="arabic">
<li><p class="first"><strong>Copy the example files</strong> — The <tt class="docutils literal"><span class="pre">example_nt</span></tt> directory is a
subdirectory of the <tt class="docutils literal"><span class="pre">PC</span></tt> directory, in order to keep all the PC-specific
files under the same directory in the source distribution. However, the
<tt class="docutils literal"><span class="pre">example_nt</span></tt> directory can’t actually be used from this location. You
first need to copy or move it up one level, so that <tt class="docutils literal"><span class="pre">example_nt</span></tt> is a
sibling of the <tt class="docutils literal"><span class="pre">PC</span></tt> and <tt class="docutils literal"><span class="pre">Include</span></tt> directories. Do all your work
from within this new location.</p>
</li>
<li><p class="first"><strong>Open the project</strong> — From VC++, use the <em>File ‣ Open
Solution</em> dialog (not <em>File ‣ Open</em>!). Navigate to and select
the file <tt class="docutils literal"><span class="pre">example.sln</span></tt>, in the <em>copy</em> of the <tt class="docutils literal"><span class="pre">example_nt</span></tt> directory
you made above. Click Open.</p>
</li>
<li><p class="first"><strong>Build the example DLL</strong> — In order to check that everything is set up
right, try building:</p>
</li>
<li><p class="first">Select a configuration. This step is optional. Choose
<em>Build ‣ Configuration Manager ‣ Active Solution Configuration</em>
and select either <strong>Release</strong> or <strong>Debug</strong>. If you skip this
step, VC++ will use the Debug configuration by default.</p>
</li>
<li><p class="first">Build the DLL. Choose <em>Build ‣ Build Solution</em>. This
creates all intermediate and result files in a subdirectory called either
<tt class="docutils literal"><span class="pre">Debug</span></tt> or <tt class="docutils literal"><span class="pre">Release</span></tt>, depending on which configuration you selected
in the preceding step.</p>
</li>
<li><p class="first"><strong>Testing the debug-mode DLL</strong> — Once the Debug build has succeeded, bring
up a DOS box, and change to the <tt class="docutils literal"><span class="pre">example_nt\Debug</span></tt> directory. You should
now be able to repeat the following session (<tt class="docutils literal"><span class="pre">C></span></tt> is the DOS prompt, <tt class="docutils literal"><span class="pre">>>></span></tt>
is the Python prompt; note that build information and various debug output from
Python may not match this screen dump exactly):</p>
<div class="highlight-c"><pre>C>..\..\PCbuild\python_d
Adding parser accelerators ...
Done.
Python 2.2 (#28, Dec 19 2001, 23:26:37) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import example
[4897 refs]
>>> example.foo()
Hello, world
[4903 refs]
>>></pre>
</div>
<p>Congratulations! You’ve successfully built your first Python extension module.</p>
</li>
<li><p class="first"><strong>Creating your own project</strong> — Choose a name and create a directory for
it. Copy your C sources into it. Note that the module source file name does
not necessarily have to match the module name, but the name of the
initialization function should match the module name — you can only import a
module <tt class="xref docutils literal"><span class="pre">spam</span></tt> if its initialization function is called <tt class="xref docutils literal"><span class="pre">initspam()</span></tt>,
and it should call <a title="Py_InitModule" class="reference external" href="../c-api/allocation.html#Py_InitModule"><tt class="xref docutils literal"><span class="pre">Py_InitModule()</span></tt></a> with the string <tt class="docutils literal"><span class="pre">"spam"</span></tt> as its
first argument (use the minimal <tt class="docutils literal"><span class="pre">example.c</span></tt> in this directory as a guide).
By convention, it lives in a file called <tt class="docutils literal"><span class="pre">spam.c</span></tt> or <tt class="docutils literal"><span class="pre">spammodule.c</span></tt>.
The output file should be called <tt class="docutils literal"><span class="pre">spam.pyd</span></tt> (in Release mode) or
<tt class="docutils literal"><span class="pre">spam_d.pyd</span></tt> (in Debug mode). The extension <tt class="docutils literal"><span class="pre">.pyd</span></tt> was chosen
to avoid confusion with a system library <tt class="docutils literal"><span class="pre">spam.dll</span></tt> to which your module
could be a Python interface.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 2.5: </span>Previously, file names like <tt class="docutils literal"><span class="pre">spam.dll</span></tt> (in release mode) or
<tt class="docutils literal"><span class="pre">spam_d.dll</span></tt> (in debug mode) were also recognized.</p>
<p>Now your options are:</p>
</li>
<li><dl class="first docutils">
<dt>Copy <tt class="docutils literal"><span class="pre">example.sln</span></tt> and <tt class="docutils literal"><span class="pre">example.vcproj</span></tt>, rename them to</dt>
<dd><p class="first last"><tt class="docutils literal"><span class="pre">spam.*</span></tt>, and edit them by hand, or</p>
</dd>
</dl>
</li>
<li><p class="first">Create a brand new project; instructions are below.</p>
<p>In either case, copy <tt class="docutils literal"><span class="pre">example_nt\example.def</span></tt> to <tt class="docutils literal"><span class="pre">spam\spam.def</span></tt>,
and edit the new <tt class="docutils literal"><span class="pre">spam.def</span></tt> so its second line contains the string
‘<tt class="docutils literal"><span class="pre">initspam</span></tt>‘. If you created a new project yourself, add the file
<tt class="docutils literal"><span class="pre">spam.def</span></tt> to the project now. (This is an annoying little file with only
two lines. An alternative approach is to forget about the <tt class="docutils literal"><span class="pre">.def</span></tt> file,
and add the option <em class="xref">/export:initspam</em> somewhere to the Link settings, by
manually editing the setting in Project Properties dialog).</p>
</li>
<li><p class="first"><strong>Creating a brand new project</strong> — Use the <em>File ‣ New
‣ Project</em> dialog to create a new Project Workspace. Select <strong>Visual
C++ Projects/Win32/ Win32 Project</strong>, enter the name (<tt class="docutils literal"><span class="pre">spam</span></tt>), and make sure the
Location is set to parent of the <tt class="docutils literal"><span class="pre">spam</span></tt> directory you have created (which
should be a direct subdirectory of the Python build tree, a sibling of
<tt class="docutils literal"><span class="pre">Include</span></tt> and <tt class="docutils literal"><span class="pre">PC</span></tt>). Select Win32 as the platform (in my version,
this is the only choice). Make sure the Create new workspace radio button is
selected. Click OK.</p>
<p>You should now create the file <tt class="docutils literal"><span class="pre">spam.def</span></tt> as instructed in the previous
section. Add the source files to the project, using <em>Project ‣
Add Existing Item</em>. Set the pattern to <tt class="docutils literal"><span class="pre">*.*</span></tt> and select both <tt class="docutils literal"><span class="pre">spam.c</span></tt>
and <tt class="docutils literal"><span class="pre">spam.def</span></tt> and click OK. (Inserting them one by one is fine too.)</p>
<p>Now open the <em>Project ‣ spam properties</em> dialog. You only need
to change a few settings. Make sure <strong>All Configurations</strong> is selected
from the <strong>Settings for:</strong> dropdown list. Select the C/C++ tab. Choose
the General category in the popup menu at the top. Type the following text in
the entry box labeled <strong>Additional Include Directories</strong>:</p>
<div class="highlight-c"><pre>..\Include,..\PC</pre>
</div>
<p>Then, choose the General category in the Linker tab, and enter</p>
<div class="highlight-c"><pre>..\PCbuild</pre>
</div>
<p>in the text box labelled <strong>Additional library Directories</strong>.</p>
<p>Now you need to add some mode-specific settings:</p>
<p>Select <strong>Release</strong> in the <strong>Configuration</strong> dropdown list.
Choose the <strong>Link</strong> tab, choose the <strong>Input</strong> category, and
append <tt class="docutils literal"><span class="pre">pythonXY.lib</span></tt> to the list in the <strong>Additional Dependencies</strong>
box.</p>
<p>Select <strong>Debug</strong> in the <strong>Configuration</strong> dropdown list, and
append <tt class="docutils literal"><span class="pre">pythonXY_d.lib</span></tt> to the list in the <strong>Additional Dependencies</strong>
box. Then click the C/C++ tab, select <strong>Code Generation</strong>, and select
<strong>Multi-threaded Debug DLL</strong> from the <strong>Runtime library</strong>
dropdown list.</p>
<p>Select <strong>Release</strong> again from the <strong>Configuration</strong> dropdown
list. Select <strong>Multi-threaded DLL</strong> from the <strong>Runtime
library</strong> dropdown list.</p>
</li>
</ol>
<p>If your module creates a new type, you may have trouble with this line:</p>
<div class="highlight-c"><div class="highlight"><pre><span class="n">PyObject_HEAD_INIT</span><span class="p">(</span><span class="o">&</span><span class="n">PyType_Type</span><span class="p">)</span>
</pre></div>
</div>
<p>Change it to:</p>
<div class="highlight-c"><div class="highlight"><pre><span class="n">PyObject_HEAD_INIT</span><span class="p">(</span><span class="nb">NULL</span><span class="p">)</span>
</pre></div>
</div>
<p>and add the following to the module initialization function:</p>
<div class="highlight-c"><div class="highlight"><pre><span class="n">MyObject_Type</span><span class="p">.</span><span class="n">ob_type</span> <span class="o">=</span> <span class="o">&</span><span class="n">PyType_Type</span><span class="p">;</span>
</pre></div>
</div>
<p>Refer to section 3 of the <a class="reference external" href="http://www.python.org/doc/faq">Python FAQ</a> for
details on why you must do this.</p>
</div>
<div class="section" id="differences-between-unix-and-windows">
<span id="dynamic-linking"></span><h2>4.2. Differences Between Unix and Windows<a class="headerlink" href="#differences-between-unix-and-windows" title="Permalink to this headline">¶</a></h2>
<p>Unix and Windows use completely different paradigms for run-time loading of
code. Before you try to build a module that can be dynamically loaded, be aware
of how your system works.</p>
<p>In Unix, a shared object (<tt class="docutils literal"><span class="pre">.so</span></tt>) file contains code to be used by the
program, and also the names of functions and data that it expects to find in the
program. When the file is joined to the program, all references to those
functions and data in the file’s code are changed to point to the actual
locations in the program where the functions and data are placed in memory.
This is basically a link operation.</p>
<p>In Windows, a dynamic-link library (<tt class="docutils literal"><span class="pre">.dll</span></tt>) file has no dangling
references. Instead, an access to functions or data goes through a lookup
table. So the DLL code does not have to be fixed up at runtime to refer to the
program’s memory; instead, the code already uses the DLL’s lookup table, and the
lookup table is modified at runtime to point to the functions and data.</p>
<p>In Unix, there is only one type of library file (<tt class="docutils literal"><span class="pre">.a</span></tt>) which contains code
from several object files (<tt class="docutils literal"><span class="pre">.o</span></tt>). During the link step to create a shared
object file (<tt class="docutils literal"><span class="pre">.so</span></tt>), the linker may find that it doesn’t know where an
identifier is defined. The linker will look for it in the object files in the
libraries; if it finds it, it will include all the code from that object file.</p>
<p>In Windows, there are two types of library, a static library and an import
library (both called <tt class="docutils literal"><span class="pre">.lib</span></tt>). A static library is like a Unix <tt class="docutils literal"><span class="pre">.a</span></tt>
file; it contains code to be included as necessary. An import library is
basically used only to reassure the linker that a certain identifier is legal,
and will be present in the program when the DLL is loaded. So the linker uses
the information from the import library to build the lookup table for using
identifiers that are not included in the DLL. When an application or a DLL is
linked, an import library may be generated, which will need to be used for all
future DLLs that depend on the symbols in the application or DLL.</p>
<p>Suppose you are building two dynamic-load modules, B and C, which should share
another block of code A. On Unix, you would <em>not</em> pass <tt class="docutils literal"><span class="pre">A.a</span></tt> to the
linker for <tt class="docutils literal"><span class="pre">B.so</span></tt> and <tt class="docutils literal"><span class="pre">C.so</span></tt>; that would cause it to be included
twice, so that B and C would each have their own copy. In Windows, building
<tt class="docutils literal"><span class="pre">A.dll</span></tt> will also build <tt class="docutils literal"><span class="pre">A.lib</span></tt>. You <em>do</em> pass <tt class="docutils literal"><span class="pre">A.lib</span></tt> to the
linker for B and C. <tt class="docutils literal"><span class="pre">A.lib</span></tt> does not contain code; it just contains
information which will be used at runtime to access A’s code.</p>
<p>In Windows, using an import library is sort of like using <tt class="docutils literal"><span class="pre">import</span> <span class="pre">spam</span></tt>; it
gives you access to spam’s names, but does not create a separate copy. On Unix,
linking with a library is more like <tt class="docutils literal"><span class="pre">from</span> <span class="pre">spam</span> <span class="pre">import</span> <span class="pre">*</span></tt>; it does create a
separate copy.</p>
</div>
<div class="section" id="using-dlls-in-practice">
<span id="win-dlls"></span><h2>4.3. Using DLLs in Practice<a class="headerlink" href="#using-dlls-in-practice" title="Permalink to this headline">¶</a></h2>
<p>Windows Python is built in Microsoft Visual C++; using other compilers may or
may not work (though Borland seems to). The rest of this section is MSVC++
specific.</p>
<p>When creating DLLs in Windows, you must pass <tt class="docutils literal"><span class="pre">pythonXY.lib</span></tt> to the linker.
To build two DLLs, spam and ni (which uses C functions found in spam), you could
use these commands:</p>
<div class="highlight-c"><div class="highlight"><pre><span class="n">cl</span> <span class="o">/</span><span class="n">LD</span> <span class="o">/</span><span class="n">I</span><span class="o">/</span><span class="n">python</span><span class="o">/</span><span class="n">include</span> <span class="n">spam</span><span class="p">.</span><span class="n">c</span> <span class="p">..</span><span class="o">/</span><span class="n">libs</span><span class="o">/</span><span class="n">pythonXY</span><span class="p">.</span><span class="n">lib</span>
<span class="n">cl</span> <span class="o">/</span><span class="n">LD</span> <span class="o">/</span><span class="n">I</span><span class="o">/</span><span class="n">python</span><span class="o">/</span><span class="n">include</span> <span class="n">ni</span><span class="p">.</span><span class="n">c</span> <span class="n">spam</span><span class="p">.</span><span class="n">lib</span> <span class="p">..</span><span class="o">/</span><span class="n">libs</span><span class="o">/</span><span class="n">pythonXY</span><span class="p">.</span><span class="n">lib</span>
</pre></div>
</div>
<p>The first command created three files: <tt class="docutils literal"><span class="pre">spam.obj</span></tt>, <tt class="docutils literal"><span class="pre">spam.dll</span></tt> and
<tt class="docutils literal"><span class="pre">spam.lib</span></tt>. <tt class="docutils literal"><span class="pre">Spam.dll</span></tt> does not contain any Python functions (such
as <a title="PyArg_ParseTuple" class="reference external" href="../c-api/arg.html#PyArg_ParseTuple"><tt class="xref docutils literal"><span class="pre">PyArg_ParseTuple()</span></tt></a>), but it does know how to find the Python code
thanks to <tt class="docutils literal"><span class="pre">pythonXY.lib</span></tt>.</p>
<p>The second command created <tt class="docutils literal"><span class="pre">ni.dll</span></tt> (and <tt class="docutils literal"><span class="pre">.obj</span></tt> and <tt class="docutils literal"><span class="pre">.lib</span></tt>),
which knows how to find the necessary functions from spam, and also from the
Python executable.</p>
<p>Not every identifier is exported to the lookup table. If you want any other
modules (including Python) to be able to see your identifiers, you have to say
<tt class="docutils literal"><span class="pre">_declspec(dllexport)</span></tt>, as in <tt class="docutils literal"><span class="pre">void</span> <span class="pre">_declspec(dllexport)</span> <span class="pre">initspam(void)</span></tt> or
<tt class="docutils literal"><span class="pre">PyObject</span> <span class="pre">_declspec(dllexport)</span> <span class="pre">*NiGetSpamData(void)</span></tt>.</p>
<p>Developer Studio will throw in a lot of import libraries that you do not really
need, adding about 100K to your executable. To get rid of them, use the Project
Settings dialog, Link tab, to specify <em>ignore default libraries</em>. Add the
correct <tt class="docutils literal"><span class="pre">msvcrtxx.lib</span></tt> to the list of libraries.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference external" href="#">4. Building C and C++ Extensions on Windows</a><ul>
<li><a class="reference external" href="#a-cookbook-approach">4.1. A Cookbook Approach</a></li>
<li><a class="reference external" href="#differences-between-unix-and-windows">4.2. Differences Between Unix and Windows</a></li>
<li><a class="reference external" href="#using-dlls-in-practice">4.3. Using DLLs in Practice</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="building.html"
title="previous chapter">3. Building C and C++ Extensions with distutils</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="embedding.html"
title="next chapter">5. Embedding Python in Another Application</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li><a href="../_sources/extending/windows.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../modindex.html" title="Global Module Index"
>modules</a> |</li>
<li class="right" >
<a href="embedding.html" title="5. Embedding Python in Another Application"
>next</a> |</li>
<li class="right" >
<a href="building.html" title="3. Building C and C++ Extensions with distutils"
>previous</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="../index.html">Python v2.6.6 documentation</a> »</li>
<li><a href="index.html" >Extending and Embedding the Python Interpreter</a> »</li>
</ul>
</div>
<div class="footer">
© <a href="../copyright.html">Copyright</a> 1990-2011, Python Software Foundation.
<br />
The Python Software Foundation is a non-profit corporation.
<a href="http://www.python.org/psf/donations/">Please donate.</a>
<br />
Last updated on Jul 20, 2011.
<a href="../bugs.html">Found a bug</a>?
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.6.
</div>
</body>
</html>
Copyright 2K16 - 2K18 Indonesian Hacker Rulez