Fix compilation

This commit is contained in:
Peter Wagenet 2018-09-12 14:53:02 -07:00
parent e9f58a5967
commit f79f91ab6f
26 changed files with 27 additions and 429 deletions

View File

@ -73,14 +73,6 @@ script: |
gem push helix_runtime-*.gem
popd
echo -e "Publishing libcruby-sys crate...\n"
# need to do this since there's a .gitignore with *.lib files
# there's a bug in Cargo, where include isn't overriding exclude
rm -rf .git
pushd crates/libcruby-sys
HELIX_LIB_DIR=$PWD cargo publish
popd
echo -e "Publishing helix crate...\n"
cargo publish
fi

View File

@ -28,9 +28,6 @@ libc = "0.2.0"
[dependencies.libcruby-sys]
git = "https://github.com/tildeio/libcruby-sys.git"
branch = "helix"
# path = "crates/libcruby-sys"
# path = "/Users/peterwagenet/Development/Ruby/libcruby-sys"
# version = "0.7.5"
[dependencies.cstr-macro]
path = "crates/cstr-macro"

View File

@ -1 +0,0 @@
*.lib

View File

@ -1,20 +0,0 @@
[package]
name = "libcruby-sys"
version = "0.7.5"
authors = ["Godhuda <engineering+godhuda@tilde.io>"]
description = "Ruby bindings"
repository = "https://github.com/tildeio/helix"
license = "ISC"
build = "build.rs"
include = [
"**/*.rs",
"Cargo.toml",
"ruby_info.rb",
# Keep in sync with version
"helix-runtime-0-7-5.i386.lib",
"helix-runtime-0-7-5.x86_64.lib"
]
[dependencies]
libc = ">= 0.1.0"

View File

@ -1,65 +0,0 @@
use std::{env,fs};
use std::path::Path;
use std::process::Command;
fn main() {
// TODO: Clean this all up. There has to be a prettier way.
let target = env::var("TARGET").expect("TARGET required");
let manifest_dir_str = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR required");
let version_str = env::var("CARGO_PKG_VERSION").expect("CARGO_PKG_VERSION required").replace(".", "-");
let root = Path::new(manifest_dir_str.as_str());
let lib_root_str = env::var("HELIX_LIB_DIR").unwrap_or(manifest_dir_str.clone());
let lib_root = Path::new(lib_root_str.as_str());
// Best way I could find to tell if we're packaging vs just building
let is_packaging = root.parent().expect("root has no parent").ends_with("target/package");
let libname32 = format!("helix-runtime-{}.i386", version_str);
let libname64 = format!("helix-runtime-{}.x86_64", version_str);
let libname = if target.starts_with("x86_64") { libname64.clone() } else { libname32.clone() };
// Not required for non-Windows, but it needs to be part of the package
if is_packaging && (!lib_root.join(format!("{}.lib", libname32)).exists() ||
!lib_root.join(format!("{}.lib", libname64)).exists()) {
panic!("{}.lib and {}.lib must exist when packaging. Please run ./prepackage.sh and set HELIX_LIB_DIR.", libname32, libname64);
}
if target.contains("windows") && !lib_root.join(format!("{}.lib", libname)).exists() {
panic!("{}.lib must exist when running. Set HELIX_LIB_DIR to ruby/windows_build for development.", libname);
}
if target.contains("windows") {
let out_dir_str = env::var("OUT_DIR").expect("OUT_DIR required");
let out_dir = Path::new(out_dir_str.as_str());
// Read info about current Ruby install
let raw_ruby_info = Command::new("ruby")
.arg(root.join("ruby_info.rb"))
.output()
.expect("failed to get Ruby info");
let raw_ruby_output = String::from_utf8_lossy(&raw_ruby_info.stdout);
let mut raw_ruby_lines = raw_ruby_output.lines();
let ruby_libdir = Path::new(raw_ruby_lines.next().expect("Ruby info has no libdir"));
let libruby = raw_ruby_lines.next().expect("Ruby info has no LIBRUBY");
let libruby_so = raw_ruby_lines.next().expect("Ruby info has no LIBRUBY_SO");
if raw_ruby_lines.next() != None {
panic!("Unexpected information returned in Ruby info");
}
let ruby_libname = libruby_so.split('.').next().expect("can't extract Ruby lib name");
// Copy .dll.a file to .lib since Rust msvc looks for .lib files only
fs::copy(ruby_libdir.join(libruby), out_dir.join(ruby_libname).with_extension("lib"))
.expect("unable to copy libruby");
// Set up linker
println!("cargo:rustc-flags=-L {libpath} -l dylib={libruby} -L {root} -l helix-runtime:{libname}",
libpath=out_dir.to_str().expect("can't get str from out_dir"),
libruby=ruby_libname,
root=lib_root.to_str().expect("can't get str from root dir"),
libname=libname);
}
}

View File

@ -1,12 +0,0 @@
#!/bin/bash
set -e
set -x
pushd ../../ruby
bundle install
bundle exec rake native_lib_files
popd
cp ../../ruby/windows_build/helix-runtime-*.i386.lib .
cp ../../ruby/windows_build/helix-runtime-*.x86_64.lib .

View File

@ -1,5 +0,0 @@
require 'rbconfig'
puts RbConfig::CONFIG['libdir'] # C:/Ruby23/lib
puts RbConfig::CONFIG['LIBRUBY'] # libmsvcrt-ruby230.dll.a
puts RbConfig::CONFIG['LIBRUBY_SO'] # msvcrt-ruby230.dll

View File

@ -1,303 +0,0 @@
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
extern crate libc;
use std::ffi::CStr;
use std::mem::size_of;
pub const PKG_VERSION: &'static str = env!("CARGO_PKG_VERSION");
pub fn check_version() {
let raw_version = unsafe { CStr::from_ptr(HELIX_RUNTIME_VERSION) };
let version = raw_version.to_str().expect("HELIX_RUNTIME_VERSION must be defined");
if PKG_VERSION != version {
panic!("libcsys-ruby version ({}) doesn't match helix_runtime version ({}).", PKG_VERSION, version);
}
if size_of::<usize>() != size_of::<u32>() && size_of::<usize>() != size_of::<u64>() {
panic!("unsupported architecture, size_of::<usize>() = {}", size_of::<usize>());
}
}
pub type void = libc::c_void;
pub type c_func = *const void;
pub type c_string = *const libc::c_char;
// pub type c_func = extern "C" fn(...);
#[repr(C)]
#[derive(Eq, PartialEq, Hash, Copy, Clone, Debug)]
pub struct ID(*mut void);
unsafe impl Sync for ID {}
#[repr(C)]
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
pub struct VALUE(*mut void);
#[repr(C)]
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
pub struct RubyException(isize);
impl RubyException {
pub fn new() -> RubyException {
RubyException(0)
}
pub fn empty() -> RubyException {
RubyException(0)
}
pub fn for_tag(tag: isize) -> RubyException {
RubyException(tag)
}
}
pub const EMPTY_EXCEPTION: RubyException = RubyException(0);
#[repr(C)]
pub enum st_retval {
ST_CONTINUE,
ST_STOP,
ST_DELETE,
// ST_CHECK
}
#[cfg_attr(windows, link(name="helix-runtime"))]
extern "C" {
#[link_name = "HELIX_RUNTIME_VERSION"]
pub static HELIX_RUNTIME_VERSION: c_string;
#[link_name = "HELIX_Qfalse"]
pub static Qfalse: VALUE;
#[link_name = "HELIX_Qtrue"]
pub static Qtrue: VALUE;
#[link_name = "HELIX_Qnil"]
pub static Qnil: VALUE;
#[link_name = "HELIX_PRIsVALUE"]
pub static PRIsVALUE: c_string;
#[link_name = "HELIX_SPRINTF_TO_S"]
pub static SPRINTF_TO_S: c_string;
#[link_name = "HELIX_SPRINTF_INSPECT"]
pub static SPRINTF_INSPECT: c_string;
#[link_name = "rb_cObject"]
pub static rb_cObject: VALUE;
#[link_name = "rb_cBasicObject"]
pub static rb_cBasicObject: VALUE;
#[link_name = "rb_eRuntimeError"]
pub static rb_eRuntimeError: VALUE;
#[link_name = "rb_eTypeError"]
pub static rb_eTypeError: VALUE;
#[link_name = "HELIX_RSTRING_LEN"]
pub fn RSTRING_LEN(string: VALUE) -> isize;
#[link_name = "HELIX_RSTRING_PTR"]
pub fn RSTRING_PTR(string: VALUE) -> c_string;
#[link_name = "HELIX_rb_utf8_str_new"]
pub fn rb_utf8_str_new(string: c_string, len: libc::c_long) -> VALUE;
#[link_name = "HELIX_RARRAY_LEN"]
pub fn RARRAY_LEN(array: VALUE) -> isize;
#[link_name = "HELIX_RARRAY_PTR"]
pub fn RARRAY_PTR(array: VALUE) -> *mut VALUE;
#[link_name = "HELIX_RARRAY_CONST_PTR"]
pub fn RARRAY_CONST_PTR(array: VALUE) -> *const VALUE;
#[link_name = "HELIX_RHASH_SIZE"]
pub fn RHASH_SIZE(hash: VALUE) -> isize;
#[link_name = "HELIX_RB_TYPE_P"]
pub fn RB_TYPE_P(val: VALUE, rb_type: isize) -> bool;
#[link_name = "HELIX_RB_NIL_P"]
pub fn RB_NIL_P(val: VALUE) -> bool;
#[link_name = "HELIX_RTEST"]
pub fn RTEST(val: VALUE) -> bool;
#[link_name = "HELIX_TYPE"]
pub fn TYPE(val: VALUE) -> isize;
pub fn rb_check_type(v: VALUE, rb_type: isize);
#[link_name = "HELIX_NUM2U64"]
pub fn NUM2U64(v: VALUE) -> u64;
#[link_name = "HELIX_U642NUM"]
pub fn U642NUM(num: u64) -> VALUE;
#[link_name = "HELIX_NUM2I64"]
pub fn NUM2I64(v: VALUE) -> i64;
#[link_name = "HELIX_I642NUM"]
pub fn I642NUM(num: i64) -> VALUE;
#[link_name = "HELIX_NUM2U32"]
pub fn NUM2U32(v: VALUE) -> u32;
#[link_name = "HELIX_U322NUM"]
pub fn U322NUM(num: u32) -> VALUE;
#[link_name = "HELIX_NUM2I32"]
pub fn NUM2I32(v: VALUE) -> i32;
#[link_name = "HELIX_I322NUM"]
pub fn I322NUM(num: i32) -> VALUE;
#[link_name = "HELIX_NUM2F64"]
pub fn NUM2F64(v: VALUE) -> f64;
#[link_name = "HELIX_F642NUM"]
pub fn F642NUM(num: f64) -> VALUE;
#[link_name = "HELIX_OBJ_FROZEN"]
pub fn OBJ_FROZEN(v: VALUE) -> bool;
#[link_name = "HELIX_CLASS_OF"]
pub fn CLASS_OF(v: VALUE) -> VALUE;
#[link_name = "HELIX_T_OBJECT"]
pub static T_OBJECT: isize;
#[link_name = "HELIX_T_STRING"]
pub static T_STRING: isize;
#[link_name = "HELIX_T_ARRAY"]
pub static T_ARRAY: isize;
#[link_name = "HELIX_T_HASH"]
pub static T_HASH: isize;
#[link_name = "HELIX_T_TRUE"]
pub static T_TRUE: isize;
#[link_name = "HELIX_T_FALSE"]
pub static T_FALSE: isize;
#[link_name = "HELIX_T_SYMBOL"]
pub static T_SYMBOL: isize;
#[link_name = "HELIX_T_FIXNUM"]
pub static T_FIXNUM: isize;
#[link_name = "HELIX_T_FLOAT"]
pub static T_FLOAT: isize;
#[link_name = "HELIX_T_BIGNUM"]
pub static T_BIGNUM: isize;
#[link_name = "HELIX_T_DATA"]
pub static T_DATA: isize;
// unknown if working?
// fn rb_define_variable(name: c_string, value: *const VALUE);
pub fn rb_obj_class(obj: VALUE) -> VALUE;
pub fn rb_obj_classname(obj: VALUE) -> c_string;
pub fn rb_const_get(class: VALUE, name: ID) -> VALUE;
pub fn rb_define_global_const(name: c_string, value: VALUE);
pub fn rb_define_module(name: c_string) -> VALUE;
pub fn rb_define_module_under(namespace: VALUE, name: c_string) -> VALUE;
pub fn rb_define_class(name: c_string, superclass: VALUE) -> VALUE;
pub fn rb_define_class_under(namespace: VALUE, name: c_string, superclass: VALUE) -> VALUE;
pub fn rb_define_alloc_func(class: VALUE, func: extern "C" fn(class: VALUE) -> VALUE);
pub fn rb_define_method(class: VALUE, name: c_string, func: c_func, arity: isize);
pub fn rb_define_singleton_method(class: VALUE, name: c_string, func: c_func, arity: isize);
pub fn rb_undef_method(class: VALUE, name: c_string);
pub fn rb_enc_get_index(obj: VALUE) -> isize;
pub fn rb_utf8_encindex() -> isize;
pub fn rb_sprintf(specifier: c_string, ...) -> VALUE;
pub fn rb_inspect(value: VALUE) -> VALUE;
pub fn rb_intern(string: c_string) -> ID;
pub fn rb_intern_str(string: VALUE) -> ID;
pub fn rb_sym2id(symbol: VALUE) -> ID;
pub fn rb_id2sym(id: ID) -> VALUE;
pub fn rb_id2str(id: ID) -> VALUE;
pub fn rb_ary_new() -> VALUE;
pub fn rb_ary_new_capa(capa: isize) -> VALUE;
pub fn rb_ary_entry(ary: VALUE, offset: isize) -> VALUE;
pub fn rb_ary_push(ary: VALUE, item: VALUE) -> VALUE;
pub fn rb_hash_new() -> VALUE;
pub fn rb_hash_aref(hash: VALUE, key: VALUE) -> VALUE;
pub fn rb_hash_aset(hash: VALUE, key: VALUE, value: VALUE) -> VALUE;
pub fn rb_hash_foreach(hash: VALUE, f: extern "C" fn(key: VALUE, value: VALUE, farg: *mut void) -> st_retval, farg: *mut void);
pub fn rb_gc_mark(value: VALUE);
pub fn rb_funcall(value: VALUE, mid: ID, argc: libc::c_int, ...) -> VALUE;
pub fn rb_funcallv(value: VALUE, mid: ID, argc: libc::c_int, argv: *const VALUE) -> VALUE;
pub fn rb_scan_args(argc: libc::c_int, argv: *const VALUE, fmt: c_string, ...);
pub fn rb_block_given_p() -> bool;
pub fn rb_yield(value: VALUE) -> VALUE;
pub fn rb_obj_dup(value: VALUE) -> VALUE;
pub fn rb_obj_init_copy(value: VALUE, orig: VALUE) -> VALUE;
pub fn rb_raise(exc: VALUE, string: c_string, ...) -> !;
pub fn rb_jump_tag(state: RubyException) -> !;
pub fn rb_protect(try: extern "C" fn(v: *mut void) -> VALUE,
arg: *mut void,
state: *mut RubyException)
-> VALUE;
#[link_name = "HELIX_rb_str_valid_encoding_p"]
pub fn rb_str_valid_encoding_p(string: VALUE) -> bool;
#[link_name = "HELIX_rb_str_ascii_only_p"]
pub fn rb_str_ascii_only_p(string: VALUE) -> bool;
#[link_name = "HELIX_Data_Wrap_Struct"]
pub fn Data_Wrap_Struct(klass: VALUE, mark: extern "C" fn(*mut void), free: extern "C" fn(*mut void), data: *mut void) -> VALUE;
#[link_name = "HELIX_Data_Get_Struct_Value"]
pub fn Data_Get_Struct_Value(obj: VALUE) -> *mut void;
#[link_name = "HELIX_Data_Set_Struct_Value"]
pub fn Data_Set_Struct_Value(obj: VALUE, data: *mut void);
}
#[inline]
pub unsafe fn NUM2USIZE(v: VALUE) -> usize {
if size_of::<usize>() == size_of::<u32>() {
NUM2U32(v) as usize
} else {
NUM2U64(v) as usize
}
}
#[inline]
pub unsafe fn USIZE2NUM(num: usize) -> VALUE {
if size_of::<usize>() == size_of::<u32>() {
U322NUM(num as u32)
} else {
U642NUM(num as u64)
}
}
#[inline]
pub unsafe fn NUM2ISIZE(v: VALUE) -> isize {
if size_of::<isize>() == size_of::<i32>() {
NUM2I32(v) as isize
} else {
NUM2I64(v) as isize
}
}
#[inline]
pub unsafe fn ISIZE2NUM(num: isize) -> VALUE {
if size_of::<isize>() == size_of::<i32>() {
I322NUM(num as i32)
} else {
I642NUM(num as i64)
}
}

View File

@ -1,5 +1,6 @@
source 'https://rubygems.org'
gem 'libcruby_sys', git: 'https://github.com/tildeio/libcruby-sys', branch: 'helix'
gem 'helix_runtime', path: '../../ruby'
gem 'rake', '~> 10.0'
gem 'rspec', '~> 3.4'

View File

@ -1,5 +1,6 @@
source 'https://rubygems.org'
gem 'libcruby_sys', git: 'https://github.com/tildeio/libcruby-sys', branch: 'helix'
gem 'helix_runtime', path: '../../ruby'
gem 'rake', '~> 10.0'
gem 'rspec', '~> 3.4'

View File

@ -1,5 +1,6 @@
source 'https://rubygems.org'
gem 'libcruby_sys', git: 'https://github.com/tildeio/libcruby-sys', branch: 'helix'
gem 'helix_runtime', path: '../../ruby'
gem 'rake', '~> 10.0'
gem 'rspec', '~> 3.4'

View File

@ -2,5 +2,6 @@ source 'https://rubygems.org'
gemspec
gem 'libcruby_sys', git: 'https://github.com/tildeio/libcruby-sys', branch: 'helix'
gem 'helix_runtime', path: '../../ruby'
gem 'activesupport', '5.1.0.beta1'

View File

@ -1,5 +1,6 @@
source 'https://rubygems.org'
gem 'libcruby_sys', git: 'https://github.com/tildeio/libcruby-sys', branch: 'helix'
gem 'helix_runtime', path: '../../ruby'
gem 'rake', '~> 10.0'
gem 'rspec', '~> 3.4'

View File

@ -1,5 +1,6 @@
source 'https://rubygems.org'
gem 'libcruby_sys', git: 'https://github.com/tildeio/libcruby-sys', branch: 'helix'
gem 'helix_runtime', path: '../../ruby'
gem 'rake', '~> 10.0'
gem 'rspec', '~> 3.4'

View File

@ -1,5 +1,6 @@
source 'https://rubygems.org'
gem 'libcruby_sys', git: 'https://github.com/tildeio/libcruby-sys', branch: 'helix'
gem 'helix_runtime', path: '../../ruby'
gem 'rake', '~> 10.0'
gem 'rspec', '~> 3.4'

View File

@ -1,5 +1,6 @@
source 'https://rubygems.org'
gem 'libcruby_sys', git: 'https://github.com/tildeio/libcruby-sys', branch: 'helix'
gem 'helix_runtime', path: '../../ruby'
gem 'rake', '~> 10.0'
gem 'rspec', '~> 3.4'

View File

@ -1,5 +1,6 @@
source 'https://rubygems.org'
gem 'libcruby_sys', git: 'https://github.com/tildeio/libcruby-sys', branch: 'helix'
gem 'helix_runtime', path: '../../ruby'
gem 'rake', '~> 10.0'
gem 'rspec', '~> 3.4'

View File

@ -2,4 +2,5 @@ source 'https://rubygems.org'
gemspec
gem 'libcruby_sys', git: 'https://github.com/tildeio/libcruby-sys', branch: 'helix'
gem 'helix_runtime', path: '../../ruby'

View File

@ -1,4 +1,5 @@
source 'https://rubygems.org'
gem 'libcruby_sys', git: 'https://github.com/tildeio/libcruby-sys', branch: 'helix'
gem 'helix_runtime', path: '../../ruby'
gem 'rake', '~> 10.0'

View File

@ -2,3 +2,5 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in ruby.gemspec
gemspec
gem 'libcruby_sys', git: 'https://github.com/tildeio/libcruby-sys', branch: 'helix'

View File

@ -132,5 +132,5 @@ if RUBY_PLATFORM =~ /mingw/
task "compile:native" => :native_lib_files
end
task :rspec => :compile
# task :rspec => :compile
task :default => :rspec

View File

@ -4,4 +4,4 @@ if RUBY_PLATFORM =~ /mingw/
system "rake native_def_file"
end
create_makefile "helix_runtime/native"
# create_makefile "helix_runtime/native"

View File

@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_dependency "libcruby_sys"
spec.add_dependency "rake", ">= 10.0"
spec.add_dependency "thor", [">= 0.19.4", "< 2.0"]
spec.add_dependency "tomlrb", "~> 1.2.4"

View File

@ -4,10 +4,9 @@ require 'helix_runtime/project'
require 'helix_runtime/parent_project'
begin
# require "helix_runtime/native"
require "/Users/peterwagenet/Development/Ruby/libcruby-sys/lib/libcruby_sys"
require "libcruby-sys"
rescue LoadError
warn "Unable to load helix_runtime/native. Please run `rake compile` in #{File.expand_path("../..", __FILE__)}."
warn "Unable to load libcruby-sys."
end
module HelixRuntime
@ -46,13 +45,14 @@ module HelixRuntime
def self.copy_dll
if IS_WINDOWS
so_path = File.expand_path("../helix_runtime/native.#{Platform.dlext}", __FILE__)
raise "Unable to find native bundle at #{so_path}" unless File.exists?(so_path)
raise "not implemented"
# so_path = File.expand_path("../helix_runtime/native.#{Platform.dlext}", __FILE__)
# raise "Unable to find native bundle at #{so_path}" unless File.exists?(so_path)
bindir = RbConfig::CONFIG['bindir']
raise "Unable to determine Ruby bindir" unless bindir
# bindir = RbConfig::CONFIG['bindir']
# raise "Unable to determine Ruby bindir" unless bindir
FileUtils.cp so_path, File.join(bindir, dll_filename)
# FileUtils.cp so_path, File.join(bindir, dll_filename)
else
# No-op
end

View File

@ -3,9 +3,10 @@ require "mkmf"
root_dir = File.expand_path("../../../../../..", __FILE__)
dir_config "dummy"
find_header "helix_runtime.h", "#{root_dir}/ext/helix_runtime/native"
# find_header "helix_runtime.h", "#{root_dir}/ext/helix_runtime/native"
if RUBY_PLATFORM =~ /mingw/
riase "not implemented"
append_ldflags("-L#{root_dir}/windows_build -lhelix-runtime-#{HelixRuntime::VERSION.gsub('.', '-')}")
end

View File

@ -74,7 +74,7 @@ impl ClassDefinition {
pub fn undefine_class_method(&self, name: *const c_char) {
unsafe {
sys::rb_undef_method(sys::rb_obj_class(self.class.0), name);
sys::rb_undef_method(sys::CLASS_OF(self.class.0), name);
}
}
}