Update examples for Rust master

This commit is contained in:
Alex Crichton
2015-05-19 09:41:22 -07:00
parent aece96458f
commit 640bfb9da8
9 changed files with 26 additions and 19 deletions

View File

@@ -10,12 +10,11 @@ all: target/double
target: target:
mkdir -p $@ mkdir -p $@
target/double: target/main.o target/libdouble_input.a target/double: target/main.o target/debug/libdouble_input.a
$(CC) -o $@ $^ $(LDFLAGS) $(CC) -o $@ $^ $(LDFLAGS)
target/libdouble_input.a: src/lib.rs Cargo.toml target/debug/libdouble_input.a: src/lib.rs Cargo.toml
cargo build cargo build
(cd target && ln -nsf debug/libdouble_input-*.a libdouble_input.a)
target/main.o: src/main.c | target target/main.o: src/main.c | target
$(CC) -o $@ -c $< $(CC) -o $@ -c $<

View File

@@ -4,12 +4,11 @@ else
EXT := so EXT := so
endif endif
all: target/libdouble_input.$(EXT) node_modules/ffi all: target/debug/libdouble_input.$(EXT) node_modules/ffi
node src/main.js node src/main.js
target/libdouble_input.$(EXT): src/lib.rs Cargo.toml target/debug/libdouble_input.$(EXT): src/lib.rs Cargo.toml
cargo build cargo build
(cd target && ln -nsf debug/libdouble_input-*$(EXT) libdouble_input.$(EXT))
node_modules/ffi: node_modules/ffi:
npm install ffi npm install ffi

View File

@@ -1,6 +1,6 @@
var ffi = require('ffi'); var ffi = require('ffi');
var lib = ffi.Library('target/libdouble_input', { var lib = ffi.Library('target/debug/libdouble_input', {
'double_input': [ 'int', [ 'int' ] ] 'double_input': [ 'int', [ 'int' ] ]
}); });

View File

@@ -4,12 +4,11 @@ else
EXT := so EXT := so
endif endif
all: target/libdouble_input.so all: target/debug/libdouble_input.$(EXT)
perl src/main.pl perl src/main.pl
target/libdouble_input.so: src/lib.rs Cargo.toml target/debug/libdouble_input.$(EXT): src/lib.rs Cargo.toml
cargo build cargo build
(cd target && ln -nsf debug/libdouble_input-*$(EXT) libdouble_input.so)
clean: clean:
rm -rf target rm -rf target

View File

@@ -2,7 +2,7 @@ use v5.10;
use FFI::Raw; use FFI::Raw;
my $double_input = FFI::Raw->new( my $double_input = FFI::Raw->new(
"target/libdouble_input.so", "target/debug/libdouble_input.so",
'double_input', 'double_input',
FFI::Raw::int, # return value FFI::Raw::int, # return value
FFI::Raw::int # arg #1 FFI::Raw::int # arg #1

View File

@@ -4,12 +4,11 @@ else
EXT := so EXT := so
endif endif
all: target/libdouble_input.so all: target/debug/libdouble_input.$(EXT)
python src/main.py python src/main.py
target/libdouble_input.so: src/lib.rs Cargo.toml target/debug/libdouble_input.$(EXT): src/lib.rs Cargo.toml
cargo build cargo build
(cd target && ln -nsf debug/libdouble_input-*$(EXT) libdouble_input.so)
clean: clean:
rm -rf target rm -rf target

View File

@@ -1,6 +1,12 @@
from ctypes import cdll from ctypes import cdll
from sys import platform
lib = cdll.LoadLibrary('target/libdouble_input.so') if platform == "darwin":
ext = "dylib"
else:
ext = "so"
lib = cdll.LoadLibrary('target/debug/libdouble_input.' + ext)
double_input = lib.double_input double_input = lib.double_input
input = 4 input = 4

View File

@@ -4,12 +4,11 @@ else
EXT := so EXT := so
endif endif
all: target/libdouble_input.so all: target/debug/libdouble_input.$(EXT)
ruby src/main.rb ruby src/main.rb
target/libdouble_input.so: src/lib.rs Cargo.toml target/debug/libdouble_input.$(EXT): src/lib.rs Cargo.toml
cargo build cargo build
(cd target && ln -nsf debug/libdouble_input-*$(EXT) libdouble_input.so)
clean: clean:
rm -rf target rm -rf target

View File

@@ -1,8 +1,14 @@
require 'ffi' require 'ffi'
if RUBY_PLATFORM.include?('darwin')
EXT = 'dylib'
else
EXT = 'so'
end
module Hello module Hello
extend FFI::Library extend FFI::Library
ffi_lib 'target/libdouble_input.so' ffi_lib 'target/debug/libdouble_input.' + EXT
attach_function :double_input, [ :int ], :int attach_function :double_input, [ :int ], :int
end end