Archived:Build PySymbian
Article Metadata
This article shows how to build the PySymbian 2.0 runtime and extensions from source.
Reasons: hamishwillee (14 Nov 2011)
Compiler required to build no longer available (was linked at http URL (//tools.ext.nokia.com/download/beta_build.php). It also doesn't explain where the source can be obtained.
Steps to build PySymbian 2.0:
Note: to build PySymbian 2.0 I got inspired from pys60-2.0.0_src.zip\src\README_BUILD_INSTRUCTIONS.txt.
To build we need:
- the PySymbian 2.0 source code
- Python 2.5.4 - we really need to use 2.5, otherwise seems to have bytecode incompatibility
- Open C/C++ Plug-ins version 1.6 (seems to work also with latest 1.7.5) available at http://www.developer.nokia.com/info/sw.nokia.com/id/91d89929-fb8c-4d66-bea0-227e42df9053/Open_C_SDK_Plug-In.html
- S60 C++ SDK. Currently supported versions for building are: S60 SDK 3.0 (I used S60_3rd_MR - Maintenance Release - and seems to be OK), S60 SDK 3.2 and S60 SDK 5.0. One can find them at http://www.developer.nokia.com/info/sw.nokia.com/id/4a7149a5-95a5-4726-913a-3c6f21eb65a5/S60-SDK-0616-3.0-mr.html; SDKs only from 3rd edition onwards at http://www.developer.nokia.com/info/sw.nokia.com/id/ec866fab-4b76-49f6-b5a5-af0631419e9c/S60_All_in_One_SDKs.html.
- install GCCE build configuration by going to "S60 Developer Tools" program group in the Start Menu, choose the SDK (e.g., S60 3rd MR), go to Tools and then click on "CSL Toolchain (GCCE) - Install". (Note: NO need to have (RCVT) ARMV5 compiler installed).
- Carbide - I used 2.7.0.
- Python source code doesn't get compiled using the latest x86 compiler (build > 471). You will need x86 compiler of build 471. Unfortunately download link is broken (//tools.ext.nokia.com/download/beta_build.php). Extract it in "C:\Symbian\Tools\Carbide.c++ v2.7\" folder.
- To patch the S60 SDK's headers you need the GNU patch utility.
- download pys60-2.0.0_src.zip
- Note: We do NOT need PySymbian SDK (like Python_2.0.0_SDK_3rdEdFP1.zip).
To configure the build, open a command prompt:
- give: set EPOCROOT=\
- give: subst t: C:\Symbian\9.1\S60_3rd_MR (for example)
- (make sure that Python 2.5.4 is in your PATH.)
- unzip pys60-2.0.0_src.zip in T:\PySymbian_2_0
- give: T: and then cd PySymbian_2_0
- give: python setup.py configure -s 30gcce -k selfsigned --caps "LocalServices NetworkServices ReadUserData WriteUserData UserEnvironment" >stdout_config
(Note: I was not able to successfully run python setup.py build --device because the GCCE compiler crashes (:o) at _sre.c - somebody else had the same issue: http://www.developer.nokia.com/Community/Discussion/showthread.php?165341-PySymbian-1.9.3-compilation-problem-(in-order-to-compile-modules)/page2 . Therefore I use Carbide directly.)
To build:
- open Carbide:
- import in Carbide C:\Symbian\9.1\S60_3rd_MR\PySymbian_2_0\newcore\Symbian\group\bld.inf. (do not import T:\...\bld.inf, since Carbide and the project need to reside on the same drive, otherwise you receive errors).
- build GCCE release.
Then I have C:\Symbian\9.1\S60_3rd_MR\Epoc32\BUILD\Symbian\9.1\S60_3rd_MR\PySymbian_2_0\newcore\Symbian\group\PYTHON25\GCCE\UREL\python25.dll. :))) But a few modules didn't compile :(.
Notes about ARMV5 and GCCE build configurations:
- http://www.developer.nokia.com/Community/Discussion/showthread.php?154122-can-only-build-for-emulator.-ARM5-and-CCE-do-not-build - "ARMV5 target requires you to buy the RealView Compiler Toolkit (RVCT) from ARM. However there is a free target compiler bundled with the SDK, that is the GCCE target, use that one. If it fails, make sure that you have actually installed it ("CSL Toolchain (GCCE) - Install" in the Tools section of the SDK's program group in the Start Menu)."
- http://www.developer.nokia.com/Community/Discussion/showthread.php?75170-WARNING-Cannot-determine-the-version-of-the-RVCT-Compiler. - "The toolchain you have installed from the SDK (CSL Toolchain (GCCE)) is a GCC compiler, which is free. The RVCT (RealView Compiler Toolkit) is a product what you can buy for a significant amount of money from ARM. Anyway, most developers can happily live with the GCC."
Building PyS0 extensions
First:
- Install S60 SDK – tried with 3rd edition FP1.
- Install Carbide (tested on 2.7 and 2.3).
- Install PySymbian 2.0 SDK and copy the header files, etc in Symbian\9.2\S60_3rd_FP1, etc!!!!.
Then:
- At least for S60 3rd FP1 edit C:\Symbian\9.2\S60_3rd_FP1\Epoc32\include\python25\pyconfig.h:
commented (not necessary in amigaconfig.h)
#define HAVE_STDINT_H 1
#define HAVE_UINTPTR_T 1
#define HAVE_SYS_SELECT_H 1
#define HAVE_WCHAR_H 1
uncommented (probably not necessary) /* #undef HAVE_USABLE_WCHAR_T */
added also in the automatically generated .mmp by Py_XT_create - SYSTEMINCLUDE \epoc32\include\libc
edited /Symbian/9.2/S60_3rd_FP1/EPOC32/include/python25/Python-ast.h - add newline at EOF
- Also, to build sysagent module on 3rd edition FP1
Copied SharedData\epoc32\include\psvariables.h, coreapplicationuisinternalpskeys.h and telephonyinternalpskeys.h from S60_3rd_SDK_MR_API_Plug-In_Pack_v5_43.zip.
(note that it is MR and not FP1)
In Carbide:
- import project - Symbian OS\Symbian OS Bld.inf file
- import bld.inf in Carbide - select All Build config
- Build Configuration\Set Active - Phone Release (GCCE)
- put the project on the same drive as the Carbide installation
- then build project
- then find generated .pyd in C:\Symbian\9.2\S60_3rd_FP1\Epoc32\release\gcce\urel\
If converting PySymbian 1.4.5 extensions to PySymbian 2.0 consult PySymbian manual. Reproduced here:
The changes needed for porting existing native PySymbian extensions are as follows:
- From Symbian 9.1 onwards Symbian allows Writable Static Data in a DLL by making use of EPOCALLOWDLLDATA keyword in the mmp file. Main reason for this one is for porting some non-Symbian applications onto Symbian. Thus TLS functionality is no longer needed. Use EPOCALLOWDLLDATA in the MMP file if the module has initialized static data.
- Use PyGILState_Ensure() and PyGILState_Release() functions for acquiring and releasing the global interpreter lock, instead of using PyEval_RestoreThread(PYTHON_TLS->thread_state) and PyEval_SaveThread().
- The interpreter DLL name is changed to python25.lib. This change has to be reflected in the MMP file so that the module is linked against this DLL instead of python222.lib used in 1.4.x.
- The Python header files are now in \epoc32\include\Python25 and hence the MMP file needs to be updated accordingly.
- The pyd name should be kf_module-name.pyd.
Note: This change is required only for the pyd name and module name is not required to have this prefix.
- Packaging an extension module is explained in section 8.1.3, Distributing extension modules.
Note: The init-function still needs to be exported in the pyd at ordinal 1.
IMPORTANT NOTES:
Be careful to choose the Carbide project name the same as the folder name, otherwise it will give error at import. While importing project, be sure also to choose the right workspace path (e.g., the folder containing group, src, inc of each project).
Py_XT_Creator - movie on YouTube says:
- enter name, UID
- import bld.inf in Carbide - select All Build config
- Build Configuration\Set Active - Phone Release (GCCE)
- Go to Project Properties\SIS builder tab, give Add, choose PKG File the one sis\....pkg

