diff --git a/c-to-rust/Makefile b/c-to-rust/Makefile index 1107f66..0e9dce1 100644 --- a/c-to-rust/Makefile +++ b/c-to-rust/Makefile @@ -10,12 +10,11 @@ all: target/double target: mkdir -p $@ -target/double: target/main.o target/libdouble_input.a +target/double: target/main.o target/debug/libdouble_input.a $(CC) -o $@ $^ $(LDFLAGS) -target/libdouble_input.a: src/lib.rs Cargo.toml +target/debug/libdouble_input.a: src/lib.rs Cargo.toml cargo build - (cd target && ln -nsf debug/libdouble_input-*.a libdouble_input.a) target/main.o: src/main.c | target $(CC) -o $@ -c $< diff --git a/node-to-rust/Makefile b/node-to-rust/Makefile index 76eba3e..9d381e5 100644 --- a/node-to-rust/Makefile +++ b/node-to-rust/Makefile @@ -4,12 +4,11 @@ else EXT := so endif -all: target/libdouble_input.$(EXT) node_modules/ffi +all: target/debug/libdouble_input.$(EXT) node_modules/ffi 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 - (cd target && ln -nsf debug/libdouble_input-*$(EXT) libdouble_input.$(EXT)) node_modules/ffi: npm install ffi diff --git a/node-to-rust/src/main.js b/node-to-rust/src/main.js index 0748788..5d40d17 100644 --- a/node-to-rust/src/main.js +++ b/node-to-rust/src/main.js @@ -1,6 +1,6 @@ var ffi = require('ffi'); -var lib = ffi.Library('target/libdouble_input', { +var lib = ffi.Library('target/debug/libdouble_input', { 'double_input': [ 'int', [ 'int' ] ] }); diff --git a/perl-to-rust/Makefile b/perl-to-rust/Makefile index a49e37e..94c1c5e 100644 --- a/perl-to-rust/Makefile +++ b/perl-to-rust/Makefile @@ -4,12 +4,11 @@ else EXT := so endif -all: target/libdouble_input.so +all: target/debug/libdouble_input.$(EXT) 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 - (cd target && ln -nsf debug/libdouble_input-*$(EXT) libdouble_input.so) clean: rm -rf target diff --git a/perl-to-rust/src/main.pl b/perl-to-rust/src/main.pl index 24265cc..0099bf6 100644 --- a/perl-to-rust/src/main.pl +++ b/perl-to-rust/src/main.pl @@ -2,7 +2,7 @@ use v5.10; use FFI::Raw; my $double_input = FFI::Raw->new( - "target/libdouble_input.so", + "target/debug/libdouble_input.so", 'double_input', FFI::Raw::int, # return value FFI::Raw::int # arg #1 diff --git a/python-to-rust/Makefile b/python-to-rust/Makefile index 9dd7bcb..d7338e9 100644 --- a/python-to-rust/Makefile +++ b/python-to-rust/Makefile @@ -4,12 +4,11 @@ else EXT := so endif -all: target/libdouble_input.so +all: target/debug/libdouble_input.$(EXT) 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 - (cd target && ln -nsf debug/libdouble_input-*$(EXT) libdouble_input.so) clean: rm -rf target diff --git a/python-to-rust/src/main.py b/python-to-rust/src/main.py index 19a02c6..31fb1af 100644 --- a/python-to-rust/src/main.py +++ b/python-to-rust/src/main.py @@ -1,6 +1,12 @@ 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 input = 4 diff --git a/ruby-to-rust/Makefile b/ruby-to-rust/Makefile index a39306a..065886d 100644 --- a/ruby-to-rust/Makefile +++ b/ruby-to-rust/Makefile @@ -4,12 +4,11 @@ else EXT := so endif -all: target/libdouble_input.so +all: target/debug/libdouble_input.$(EXT) 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 - (cd target && ln -nsf debug/libdouble_input-*$(EXT) libdouble_input.so) clean: rm -rf target diff --git a/ruby-to-rust/src/main.rb b/ruby-to-rust/src/main.rb index e106332..146de37 100644 --- a/ruby-to-rust/src/main.rb +++ b/ruby-to-rust/src/main.rb @@ -1,8 +1,14 @@ require 'ffi' +if RUBY_PLATFORM.include?('darwin') + EXT = 'dylib' +else + EXT = 'so' +end + module Hello extend FFI::Library - ffi_lib 'target/libdouble_input.so' + ffi_lib 'target/debug/libdouble_input.' + EXT attach_function :double_input, [ :int ], :int end