Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "cargo build" work #695

Closed
ry opened this issue Sep 6, 2018 · 11 comments
Closed

Make "cargo build" work #695

ry opened this issue Sep 6, 2018 · 11 comments
Milestone

Comments

@ry
Copy link
Member

ry commented Sep 6, 2018

And probably tools/setup.py. Step towards distributing a crate.

@ry
Copy link
Member Author

ry commented Sep 21, 2018

@qti3e has a good but incomplete start on the problem in #724.

Some hints at taking it further:

  1. The call to ./tools/build.py can be optimized. We don't need to build the deno executable with gn, as cargo is going to do that. Thus ./tools/build.py libdeno is sufficient.

  2. The resulting libdeno static library will be located at out/debug/obj/libdeno.a.

  3. You need to tell cargo where to access that - That is going to be added somewhere in this file:

    deno/src/libdeno.rs

    Lines 8 to 39 in 3ad48bd

    #[repr(C)]
    pub struct DenoC {
    _unused: [u8; 0],
    }
    #[repr(C)]
    #[derive(PartialEq)]
    pub struct deno_buf {
    pub alloc_ptr: *mut u8,
    pub alloc_len: usize,
    pub data_ptr: *mut u8,
    pub data_len: usize,
    }
    type DenoRecvCb = unsafe extern "C" fn(d: *const DenoC, buf: deno_buf);
    extern "C" {
    pub fn deno_init();
    pub fn deno_v8_version() -> *const c_char;
    pub fn deno_set_flags(argc: *mut c_int, argv: *mut *mut c_char);
    pub fn deno_new(data: *const c_void, cb: DenoRecvCb) -> *const DenoC;
    pub fn deno_delete(d: *const DenoC);
    pub fn deno_last_exception(d: *const DenoC) -> *const c_char;
    pub fn deno_get_data(d: *const DenoC) -> *const c_void;
    pub fn deno_set_response(d: *const DenoC, buf: deno_buf);
    pub fn deno_send(d: *const DenoC, buf: deno_buf);
    pub fn deno_execute(
    d: *const DenoC,
    js_filename: *const c_char,
    js_source: *const c_char,
    ) -> c_int;
    }

    The bit you're going to add will probably look like this

#[link(name = "libdeno", kind = "static")]

See https://doc.rust-lang.org/book/ffi.html

@cedric05
Copy link
Contributor

i will try

@ry
Copy link
Member Author

ry commented Oct 19, 2018

@cedric05 Great. To be clear the goal here is that when someone types "cargo build" in the deno source directory, it builds.

Please base your work off of #724

@cedric05
Copy link
Contributor

okay

@cedric05
Copy link
Contributor

i'm getting following error, i guess i will have to follow 3 step you mentioned

  = note: /home/neptune/sp/deno/target/debug/deps/deno-ff27ba049ae5592f.3tgk41ovx18117wj.rcgu.o: In function `deno::isolate::Isolate::new':
          /home/neptune/sp/deno/src/isolate.rs:112: undefined reference to `deno_new'
          /home/neptune/sp/deno/target/debug/deps/deno-ff27ba049ae5592f.3tgk41ovx18117wj.rcgu.o: In function `deno::isolate::Isolate::execute':
          /home/neptune/sp/deno/src/isolate.rs:158: undefined reference to `deno_execute'
          /home/neptune/sp/deno/src/isolate.rs:166: undefined reference to `deno_last_exception'
          /home/neptune/sp/deno/target/debug/deps/deno-ff27ba049ae5592f.3tgk41ovx18117wj.rcgu.o: In function `deno::isolate::Isolate::respond':
          /home/neptune/sp/deno/src/isolate.rs:179: undefined reference to `deno_respond'
          /home/neptune/sp/deno/target/debug/deps/deno-ff27ba049ae5592f.3tgk41ovx18117wj.rcgu.o: In function `deno::isolate::Isolate::timeout':
          /home/neptune/sp/deno/src/isolate.rs:204: undefined reference to `deno_respond'
          /home/neptune/sp/deno/target/debug/deps/deno-ff27ba049ae5592f.3tgk41ovx18117wj.rcgu.o: In function `deno::isolate::Isolate::check_promise_errors':
          /home/neptune/sp/deno/src/isolate.rs:215: undefined reference to `deno_check_promise_errors'
          /home/neptune/sp/deno/target/debug/deps/deno-ff27ba049ae5592f.3tgk41ovx18117wj.rcgu.o: In function `<deno::isolate::Isolate as core::ops::drop::Drop>::drop':
          /home/neptune/sp/deno/src/isolate.rs:252: undefined reference to `deno_delete'
          /home/neptune/sp/deno/target/debug/deps/deno-ff27ba049ae5592f.450nl13o14wrnoia.rcgu.o: In function `deno::flags::v8_set_flags':
          /home/neptune/sp/deno/src/flags.rs:270: undefined reference to `deno_set_v8_flags'
          /home/neptune/sp/deno/target/debug/deps/deno-ff27ba049ae5592f.492egky4ngi3hkcv.rcgu.o: In function `deno::version::get_v8_version':
          /home/neptune/sp/deno/src/version.rs:9: undefined reference to `deno_v8_version'
          /home/neptune/sp/deno/target/debug/deps/deno-ff27ba049ae5592f.f5147171kq3h2v3.rcgu.o: In function `deno::isolate::Isolate::new::{{closure}}':
          /home/neptune/sp/deno/src/isolate.rs:109: undefined reference to `deno_init'
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

error: Could not compile `deno`.

Caused by:
  process didn't exit successfully: `rustc --crate-name deno src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=ff27ba049ae5592f -C extra-filename=-ff27ba049ae5592f --out-dir /home/neptune/sp/deno/target/debug/deps -C incremental=/home/neptune/sp/deno/target/debug/incremental -L dependency=/home/neptune/sp/deno/target/debug/deps --extern tokio_io=/home/neptune/sp/deno/target/debug/deps/libtokio_io-f4d81d8b521091fb.rlib --extern lazy_static=/home/neptune/sp/deno/target/debug/deps/liblazy_static-2aa4224001108f09.rlib --extern hyper=/home/neptune/sp/deno/target/debug/deps/libhyper-819a771cf26a37c5.rlib --extern url=/home/neptune/sp/deno/target/debug/deps/liburl-beaf58483d7c3c8a.rlib --extern hyper_rustls=/home/neptune/sp/deno/target/debug/deps/libhyper_rustls-28601428ab90d4c3.rlib --extern flatbuffers=/home/neptune/sp/deno/target/debug/deps/libflatbuffers-da4f99da674e657a.rlib --extern tempfile=/home/neptune/sp/deno/target/debug/deps/libtempfile-21b7dc35ec740dea.rlib --extern tokio_executor=/home/neptune/sp/deno/target/debug/deps/libtokio_executor-c2af44c0ca7242ee.rlib --extern dirs=/home/neptune/sp/deno/target/debug/deps/libdirs-49e35b654dfb1b48.rlib --extern tokio_threadpool=/home/neptune/sp/deno/target/debug/deps/libtokio_threadpool-b8f90de470f41ec0.rlib --extern tokio=/home/neptune/sp/deno/target/debug/deps/libtokio-77f84ee7fde8c8d8.rlib --extern ring=/home/neptune/sp/deno/target/debug/deps/libring-bbd7ed641b521efb.rlib --extern log=/home/neptune/sp/deno/target/debug/deps/liblog-6f0ca99ee8f4043a.rlib --extern libc=/home/neptune/sp/deno/target/debug/deps/liblibc-a8b8970a7c24467a.rlib --extern futures=/home/neptune/sp/deno/target/debug/deps/libfutures-ce091056f3e90f6e.rlib --extern tokio_fs=/home/neptune/sp/deno/target/debug/deps/libtokio_fs-d88b6bcd8e101296.rlib --extern remove_dir_all=/home/neptune/sp/deno/target/debug/deps/libremove_dir_all-5e5c4eaf3bebbe82.rlib --extern rand=/home/neptune/sp/deno/target/debug/deps/librand-22765f50e97bddd0.rlib -L native=. -l static=deno -L native=/home/neptune/sp/deno/target/debug/build/ring-b719b2fa3f9de9f1/out` (exit code: 101)

@cedric05
Copy link
Contributor

cedric05 commented Oct 21, 2018

after going through all the build files, scripts are generating deno_bin.o (object) which are passed to clang with required libraries to produce executable, not sure why.

@cedric05
Copy link
Contributor

cedric05 commented Oct 21, 2018

going with the same approach giving me following error

/checkout/src/libcore/macros.rs:26: undefined reference to `core::panicking::panic_fmt'
target/debug/deps/libunicode_bidi-5f4ef65a7665eeb3.rlib

any idea ?

@cedric05
Copy link
Contributor

i tried multiple ways. not able to build. anyone else can take up this.

@ry
Copy link
Member Author

ry commented Oct 31, 2018

Recent work:
#1127
#1125
#1128

@ry
Copy link
Member Author

ry commented Oct 31, 2018

#1128 has added build.rs and allows users to call cargo check

however cargo build is not working due to linker errors. Here is a WIP patch that works on OSX and Linux: https://gist.github.com/ry/413fab741d1b858583261908380febdb

@ry ry added this to the v0.2 milestone Nov 1, 2018
@ry ry changed the title Add build.rs file that calls tools/build.py Make "cargo build" work Nov 1, 2018
@ry ry modified the milestones: v0.2, v0.3 Nov 15, 2018
@ry ry mentioned this issue Nov 19, 2018
7 tasks
@ry
Copy link
Member Author

ry commented Dec 20, 2018

Landed in 73e80b0

@ry ry closed this as completed Dec 20, 2018
hardfist pushed a commit to hardfist/deno that referenced this issue Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants