Skip to content

Instantly share code, notes, and snippets.

@kubo39
Created December 12, 2013 11:32
Show Gist options
  • Select an option

  • Save kubo39/7926649 to your computer and use it in GitHub Desktop.

Select an option

Save kubo39/7926649 to your computer and use it in GitHub Desktop.
experimental ruby from go (work in progress)
RUBY := ruby
RUBY_CFLAGS := $(shell $(RUBY) -e "puts RbConfig::CONFIG['rubyhdrdir'] + ' -I' + RbConfig::CONFIG['rubyarchhdrdir']")
RUBY_LDFLAGS := $(shell $(RUBY) -e "puts '-L' + RbConfig::CONFIG['rubylibdir']")
CGO_LDFLAGS := "$(RUBY_LDFLAGS)"
CGO_CFLAGS := "-I$(RUBY_CFLAGS)"
# default to gc, but allow caller to override on command line
GO_COMPILER:=$(GC)
ifeq ($(GO_COMPILER),)
GO_COMPILER:="gc"
endif
build_cwd = CGO_LDFLAGS=$(CGO_LDFLAGS) CGO_CFLAGS=$(CGO_CFLAGS) go build -compiler=$(GO_COMPILER) .
install_cwd = CGO_LDFLAGS=$(CGO_LDFLAGS) CGO_CFLAGS=$(CGO_CFLAGS) go install -compiler=$(GO_COMPILER) .
all: install
install:
$(install_cwd)
build:
$(build_cwd)
package main
/*
#include "/usr/local/include/ruby-2.0.0/ruby.h"
#include <stdlib.h>
#include <string.h>
*/
import "C"
import "fmt"
type VALUE struct {
ptr *C.VALUE
}
func main() {
fmt.Println("start")
}
@kubo39
Copy link
Author

kubo39 commented Dec 12, 2013

(^ν^) :~/_go/src/github.com/kubo39/go-ruby $ make
CGO_LDFLAGS="-L/usr/local/lib/ruby/2.0.0" CGO_CFLAGS="-I/usr/local/include/ruby-2.0.0 -I/usr/local/include/ruby-2.0.0/i686-linux" go install -compiler="gc" .
(^ν^) :~/_go/src/github.com/kubo39/go-ruby $ go run ruby.go 
# command-line-arguments
/usr/local/include/ruby-2.0.0/ruby/ruby.h:24:25: fatal error: ruby/config.h: No such file or directory
compilation terminated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment