Skip to content
Tcl Source Code Artifact [8a7ad8d6a4]
Login

Artifact [8a7ad8d6a4]

Artifact 8a7ad8d6a41fcc1b590196c8e59b29c948fcea34:



		NaTcl : Tcl in Nacl


Overview
--------

NaCl == Native Client is Google's neat sandboxing technology, allowing
to  run  untrusted  code  compiled  natively,  in  the  context  of  a
browser. See http://code.google.com/p/nativeclient/.

The idea  is that with Tcl  running in this context,  and a supporting
browser (currently,  Chrome only; possibly FF +  Nacl plugin shortly),
one could  develop client-side  code mainly in  Tcl, with a  very thin
layer of JS in the page; so, basically, Tcl to control the HTML5 DOM !

Building Tcl for Nacl
---------------------

 - install the NaCl SDK (for me native_client_sdk_0_1_721_0)

 - set your PATH so that nacl-gcc et al become reachable

 - untar the present archive as an 'nacl' subdir in a Tcl source tree,
   as a sibling of 'unix"

 - cd inside it

 - run  './nacl.genconf' (which  is  a ./configure  command line  with
   proper flags)

 - run 'patch -p0 < Makefile.patch' to fix the generated Makefile

 - run 'make'. This creates tcl.nmf and tcl.nexe (for x86-32)

 - launch the  NaCl-provided python-based  webserver, and make  it see
   your nacl dir somewhere in its document tree: python httpd.py 5103

 - (once) open about:flags in Chrome and enable Native Client

 - start 'chromedebug' (provided), and  point Chrome to the index.html
   in nacl.

 - (every  time)  make  sure  no  non-chromedebug  chrome  process  is
   running, otherwise it  will be used instead, and  NaCl will fail to
   load.

 - note:  'chromedebug' just  sets an  env  var for  debug output  (on
   stderr), and  stars chrome with '--no-sandbox',  which is currently
   needed for NaCl to be really enabled on Linux.

Overview of the porting method
------------------------------

Nacl  comes with  a  very incomplete  libc  and set  of headers.   The
strategy,  then,  is to  simply  "plug"  missing  syscalls or  library
functions with either explicitly  failing stubs (returning -1 or NULL,
and  setting errno)  or emulators,  and to  build a  big  include file
(naclcompat.h) with  all the necessary  type and macro  definitions to
compile.
 
Of course,  when one  of the  failing stubs is  called at  runtime, an
error is raised.  But one cannot hope much more, it's  a sandbox for a
reason.

This approach allows to compile Tcl for Nacl without changing a single
line of the original source distribution; all new things are in the
nacl subdir. Moreover, many files are just symlinks to ../unix. Here
they are, since fossil wrongly extracts them as files:

	configure -> ../unix/configure
	tclLoadDl.c -> ../unix/tclLoadDl.c
	tclUnixChan.c -> ../unix/tclUnixChan.c
	tclUnixCompat.c -> ../unix/tclUnixCompat.c
	tclUnixEvent.c -> ../unix/tclUnixEvent.c
	tclUnixFCmd.c -> ../unix/tclUnixFCmd.c
	tclUnixFile.c -> ../unix/tclUnixFile.c
	tclUnixInit.c -> ../unix/tclUnixInit.c
	tclUnixNotfy.c -> ../unix/tclUnixNotfy.c
	tclUnixPipe.c -> ../unix/tclUnixPipe.c
	tclUnixSock.c -> ../unix/tclUnixSock.c
	tclUnixThrd.c -> ../unix/tclUnixThrd.c
	tclUnixTime.c -> ../unix/tclUnixTime.c