-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
lib/ukrust: Fix helloworld-rust application compilation error #1163
Conversation
Fix sub-problem of issue#1147 when enable libukrust, which will throw an error that `fatal error: 'uk/bits/libid.h' file not found` because of wrong commands order. this header file is needed by `bindings_helper.h` but command generates 'uk/bits/libid/h' is ahead from the bindgen command. Signed-off-by: Chris Wu <cocodery@outlook.com>
This commit aims to fix issue#1147 which compile apps with enabled libukrust 1. ukrust/Makefile.uk: fix command line argument with high-version bindgen, from 'size_t-is-usize' to 'no-size_t-is-usize'. 2. ukrust/src/allocator.rs: fix previous defined symbol by comment them, becasue rustc will help to resolve, and add new symbol '__rust_no_alloc_shim_is_unstable' for locate. Signed-off-by: Chris Wu <cocodery@outlook.com>
unsafe { bindings::__ukrust_sys_malloc(size as u64) as *mut u8 } | ||
} | ||
// #[no_mangle] | ||
// pub extern "Rust" fn __rust_alloc(size: usize, _align: usize) -> *mut u8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended in this PR? I think without __rust_alloc
we won't be able to allocate anything on the heap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact this is another question need to solve later.
This is a multiple definition
problem. If enable these functions, rustc will report these errors.
And the target of this PR aims to run helloworld-rust
at least becasue ukrust
cannot be used yet. Maybe the upgrade of rust cause this problem.
In issue#1147 is more detailed.
UK_SRCS-y += $(2) | ||
UK_PREPROCESS-y += $(3) | ||
$(eval $(call vprefix_lib,$(1),CLEAN-y) += $(call build_clean,$(3))) | ||
# $(3): $(2) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used this rule to gather all the rust sources, but I'm now sure how it would work if you remove them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this part only related with AWK file. And I enable all uklibs to compile unikraft, no error is reported. And I manually move this part into lib/uklibid/Makefile.uk
.
The reason of removing them is mentioned in my commit message. Rust-bindgen file need uk/include/libid.h which generated from an awk file, but because UK_PREPARE
is executed before UK_PREPROCESS
, so one error that not find uk/include/libid.h
occurs.
In issue#1147 is more detailed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be instead solved by stating the dependencies with the bingen rule. Please note that also external libraries are using these AWK rules. I assume bindgen
should run just before a rust unit is compiled, so the rust compile rule should have bindgen as dependency (or actually the files it created) and bindgen should run after UK_PREPROCESS target was reached. So I think the bingen rule should have an order-only pre-requisite to the preprocess target: <...> | preprocess
Would something like this work?
@mkroening , does it make sense to have this PR in? Or would your |
Maybe? That depends on the exact issue that @cocodery is trying to solve. My catalog PR describes building full Rust applications. This PR fixes @vladandrew's approach for building Rust libraries together with a C application, that I don't know much of. I could acquaint myself with the approach if necessary, though. :) |
This PR is trying to solve compilation failure when runing rust libraries with C application. |
With my approach for full Rust applications, Is there a special reason you are going for Rust libraries and C apps, @cocodery? You can try having the whole app in Rust. That way, Rust libraries work, as well as |
Aha, not any special reason, but want to try solve this issue. |
Hmmm, I'm wondering when develop I roll back When use heap, they have the similar output, multiple definition of But I'm not very familier with rustc command arguments. Is there someone availiable to work together? |
@mkroening I think the main reason |
I am sure you are aware of the official docs. If you need to discuss things or need help with |
Description of changes
This change, first manually move awk-generation commands to UK_PREPARE, because the bindgen command need uk/bits/libid but it's generated later than bindgen command. Secondly, fix command-line argument used by bindgen, and comment redefinition symbol. Then, helloworld-rust can successfully run.
Prerequisite checklist
checkpatch.uk
on your commit series before opening this PR;Base target
x86_64
or N/A]kvm
,xen
or N/A]app-python3
or N/A]Additional configuration
Maybe you need a high version bindgen, >= 0.60.0
You can download latest version through bindgen
Closes #1147