chakra-core / ChakraCore

ChakraCore is an open source Javascript engine with a C API.
MIT License
9.12k stars 1.2k forks source link

[OS X] ChakraCore is built against different SDK than Rust which prevents linking ChakraCore into Rust projects #1492

Closed dilijev closed 8 years ago

dilijev commented 8 years ago

See https://github.com/Microsoft/ChakraCore/issues/1441#issuecomment-242277297

FYI @fishrock123

obastemur commented 8 years ago

1493 should take care of this.

dilijev commented 8 years ago

@Fishrock123 Can you confirm whether this issue was fixed for you by #1493 ?

obastemur commented 8 years ago

Closing this one for now. From the discussion at #1493 there should be other things to consider (no longer SDK difference)

@Fishrock123 once you can share the steps, please open up an issue with the details so we may look into. Thanks!

obastemur commented 7 years ago

Prepared the bash script below for anyone looking into calling ChakraCore from Rust

CHAKRA_BUILD_FOLDER=$1

if [ ! -d $CHAKRA_BUILD_FOLDER ]; then
  echo "usage: compile.sh <path to ChakraCore BuildLinux folder>"
  exit 0
fi

# UPDATE THIS to Rustlib path on your system
# !!! You should also update a4729905
RUSTLIBS="/usr/local/Cellar/rust/1.13.0/lib/rustlib/x86_64-apple-darwin/lib"

cc -m64 -L $RUSTLIBS helloWorld.0.o -o helloWorld -Wl,-dead_strip \
-nodefaultlibs -L $RUSTLIBS \
 $RUSTLIBS/libstd-a4729905.rlib \
 $RUSTLIBS/libpanic_unwind-a4729905.rlib \
 $RUSTLIBS/libunwind-a4729905.rlib \
 $RUSTLIBS/librand-a4729905.rlib \
 $RUSTLIBS/libcollections-a4729905.rlib \
 $RUSTLIBS/librustc_unicode-a4729905.rlib \
 $RUSTLIBS/liballoc-a4729905.rlib \
 $RUSTLIBS/liballoc_jemalloc-a4729905.rlib \
 $RUSTLIBS/liblibc-a4729905.rlib \
 $RUSTLIBS/libcore-a4729905.rlib \
 $RUSTLIBS/libcompiler_builtins-a4729905.rlib \
 -Wl,-force_load \
 $CHAKRA_BUILD_FOLDER/pal/src/libChakra.Pal.a \
 $CHAKRA_BUILD_FOLDER/lib/Common/Core/libChakra.Common.Core.a \
 $CHAKRA_BUILD_FOLDER/lib/Jsrt/libChakra.Jsrt.a \
 /usr/local/opt/icu4c/lib/libicudata.a \
 /usr/local/opt/icu4c/lib/libicuuc.a \
 /usr/local/opt/icu4c/lib/libicui18n.a \
 -framework CoreFoundation -framework Security \
 -lm -ldl -Wno-c++11-compat-deprecated-writable-strings \
 -Wno-deprecated-declarations -Wno-unknown-warning-option \
 -l System -l pthread -l c -l m -lstdc++ -std=c++11
Fishrock123 commented 7 years ago

@obastemur Still trying to get around to this again... some day.

How is this script intended to be used?

obastemur commented 7 years ago

@Fishrock123 Compile the rust file i.e. HelloWorld.rs into helloWorld.o and run the script above. It will link all of them into a single binary.

dilijev commented 7 years ago

@obastemur @liminzhu Is there any place for a script like that in the wiki, samples, or other documentation, so it doesn't just get lost in this issue?

obastemur commented 7 years ago

@dilijev unless we don't put a working rust sample and keep track of it, I don't think it is a good idea to locate such script to our wiki or any other official document.

Sample script above, I just wanted to clear out couple of tricky steps for people interested using ChakraCore from Rust. Search engines should lead to this page whenever they need it.

dilijev commented 7 years ago

@obastemur fair enough. Anything we can do to make this easier to find for people looking for this? I guess searching our issues for "Rust" is enough.

darfink commented 7 years ago

I will try to have my build script up to date, but right now it is automated and works on Windows, macOS & Linux (all tested on x64 static & dynamic). Besides linking it also generates an interface file of the entire API usable in Rust.

For any rustaceans interested: https://github.com/darfink/chakracore-rs/tree/master/chakracore-sys It will be published on Crates.io this week.

obastemur commented 7 years ago

@darfink I haven't tested but sounds really good! Thanks!