ccgx

command module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

CCGX: Generate C++ bindings from GX code

Installation

  1. Install a recent version of Go (see All Releases)
  2. Install ccgx using the following command:
    $ GOBIN=<target folder> go install github.com/gx-org/ccgx@latest
    
    (if GOBIN is not specified, the default is ~/go/bin/ccgx)
  3. Install gopjrt, the XLA backend used by GX:
    $ export GOPJRT_NOSUDO=true
    $ export GOPJRT_INSTALL_DIR=$HOME/gopjrtbin
    $ export CGO_CFLAGS="-I $GOPJRT_INSTALL_DIR/include"
    $ export LD_LIBRARY_PATH=$GOPJRT_INSTALL_DIR/lib
    $ curl -sSf https://raw.githubusercontent.com/gomlx/gopjrt/main/cmd/install_linux_amd64.sh | bash
    
    Note that GOPJRT_INSTALL_DIR is going to be used later in CMakeLists.txt.

Running helloworld

This example explains how to run the example in ccgx/examples/helloworld.

  1. Create the project folder:
    $ mkdir helloworld
    $ cd helloworld
    
  2. Create a minimal helloworld.gx file such as:
    package helloworld
    
    import _ "github.com/gx-org/xlapjrt/gx"
    
    // Hello returns a constant array of two axes of size 2 and 3.
    func Hello() [2][3]float32 {
    	return [2][3]float32{
    		{1, 2, 3},
    		{4, 5, 6},
    	}
    }
    
    Note the import which adds a dependency to the XLA backend. See ccgx/examples/helloworld/helloworld.gx as a reference.
  3. Run the following command to create go.mod and go.sum:
    $ ccgx mod init helloworld
    
    These files manage all the dependencies of the project and their versions for reproducable builds. After new dependencies are added or removed in GX source files, run:
    $ ccgx mod tidy 
    
    to update go.mod from the latest imports in the GX source files.
  4. Run the following command to generate a corresponding C++ source and header files:
    $ ccgx bind --cmake
    
    The files are generated in the gxdeps folder.
  5. Create the C++ file helloworld.cc and its CMakeLists.txt
  6. Compile and run the project with cmake:
    $ mkdir build
    $ cd build
    $ cmake ..
    $ make
    $ ./helloworld
    

Disclaimer

This is not an official Google DeepMind product (experimental or otherwise), it is just code that happens to be owned by Google-DeepMind. GX is experimental and work in progress. As of today, we do not consider any part of the language as stable. Breaking changes will happen on a regular basis.

You are welcome to send PR or to report bugs. We will do our best to answer but there is no guarantee that you will get a response.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal
cmd
cmd/bind
Package bind provides the Cobra bind command
Package bind provides the Cobra bind command
cmd/carchive
Package carchive provides the Cobra carchive command.
Package carchive provides the Cobra carchive command.
cmd/debug
Package debug provides debugging helper functions.
Package debug provides debugging helper functions.
cmd/link
Package link provides the Cobra link command.
Package link provides the Cobra link command.
cmd/mod
Package mod implements the mod command and subcommands.
Package mod implements the mod command and subcommands.
cmd/pack
Package bind provides the Cobra bind command
Package bind provides the Cobra bind command
exec
Package exec encapsulates go stdlib exec package with debug information.
Package exec encapsulates go stdlib exec package with debug information.
gotc
Package gotc provides functions to invoke the Go toolchain.
Package gotc provides functions to invoke the Go toolchain.
gxtc
Package gxtc provides functions to invoke the GX toolchain.
Package gxtc provides functions to invoke the GX toolchain.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL