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

kclvm-runtime fails to buid on aarch64 #982

Closed
AdmiralNemo opened this issue Jan 15, 2024 · 4 comments · Fixed by #986
Closed

kclvm-runtime fails to buid on aarch64 #982

AdmiralNemo opened this issue Jan 15, 2024 · 4 comments · Fixed by #986

Comments

@AdmiralNemo
Copy link

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

On an aarch64 machine (I used a t4g.medium AWS EC2 instance):

git clone --depth=1 https://github.com/kcl-lang/kcl.git  && cd kcl   && make build

2. What did you expect to see? (Required)

Compilation succeeds as on x86_64

3. What did you see instead (Required)

  Compiling kclvm-runtime v0.7.3 (/root/kcl/kclvm/runtime)
error[E0308]: mismatched types
  --> runtime/src/api/utils.rs:39:47
   |
39 |     let s = unsafe { std::ffi::CStr::from_ptr(s) }.to_str().unwrap();
   |                      ------------------------ ^ expected `*const u8`, found `*const i8`
   |                      |
   |                      arguments to this function are incorrect
   |
   = note: expected raw pointer `*const u8`
              found raw pointer `*const i8`
note: associated function defined here
  --> /build/rustc-ZBSOmY/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/core/src/ffi/c_str.rs:260:25

error[E0308]: mismatched types
   --> runtime/src/context/api.rs:195:24
    |
195 |     let method = c2str(method);
    |                  ----- ^^^^^^ expected `*const i8`, found `*const u8`
    |                  |
    |                  arguments to this function are incorrect
    |
    = note: expected raw pointer `*const i8`
               found raw pointer `*const u8`
note: function defined here
   --> runtime/src/api/utils.rs:38:15
    |
38  | pub(crate) fn c2str<'a>(s: *const i8) -> &'a str {
    |               ^^^^^     ------------

error[E0308]: mismatched types
   --> runtime/src/context/api.rs:197:41
    |
197 |     let args = kclvm_value_from_json(p, args);
    |                ---------------------    ^^^^ expected `*const i8`, found `*const u8`
    |                |
    |                arguments to this function are incorrect
    |
    = note: expected raw pointer `*const i8`
               found raw pointer `*const u8`
note: function defined here
   --> runtime/src/value/api.rs:432:26
    |
432 | pub unsafe extern "C" fn kclvm_value_from_json(
    |                          ^^^^^^^^^^^^^^^^^^^^^
433 |     ctx: *mut kclvm_context_t,
434 |     s: *const kclvm_char_t,
    |     ----------------------

error[E0308]: mismatched types
   --> runtime/src/context/api.rs:198:43
    |
198 |     let kwargs = kclvm_value_from_json(p, kwargs);
    |                  ---------------------    ^^^^^^ expected `*const i8`, found `*const u8`
    |                  |
    |                  arguments to this function are incorrect
    |
    = note: expected raw pointer `*const i8`
               found raw pointer `*const u8`
note: function defined here
   --> runtime/src/value/api.rs:432:26
    |
432 | pub unsafe extern "C" fn kclvm_value_from_json(
    |                          ^^^^^^^^^^^^^^^^^^^^^
433 |     ctx: *mut kclvm_context_t,
434 |     s: *const kclvm_char_t,
    |     ----------------------

error[E0308]: mismatched types
   --> runtime/src/context/api.rs:208:5
    |
193 | ) -> *const c_char {
    |      ------------- expected `*const u8` because of return type
...
208 |     result_json
    |     ^^^^^^^^^^^ expected `*const u8`, found `*const i8`
    |
    = note: expected raw pointer `*const u8`
               found raw pointer `*const i8`

error[E0308]: arguments to this function are incorrect
  --> runtime/src/stdlib/plugin.rs:44:23
   |
44 |     let result_json = kclvm_plugin_invoke_json(method, args_json, kwargs_json);
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: expected `*const u8`, found `*const i8`
  --> runtime/src/stdlib/plugin.rs:44:56
   |
44 |     let result_json = kclvm_plugin_invoke_json(method, args_json, kwargs_json);
   |                                                        ^^^^^^^^^
   = note: expected raw pointer `*const u8`
              found raw pointer `*const i8`
note: expected `*const u8`, found `*const i8`
  --> runtime/src/stdlib/plugin.rs:44:67
   |
44 |     let result_json = kclvm_plugin_invoke_json(method, args_json, kwargs_json);
   |                                                                   ^^^^^^^^^^^
   = note: expected raw pointer `*const u8`
              found raw pointer `*const i8`
note: function defined here
  --> runtime/src/stdlib/plugin.rs:66:19
   |
66 | pub extern "C" fn kclvm_plugin_invoke_json(
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^
67 |     method: *const i8,
   |     -----------------
68 |     args: *const c_char,
   |     -------------------
69 |     kwargs: *const c_char,
   |     ---------------------

error[E0308]: mismatched types
   --> runtime/src/stdlib/plugin.rs:50:42
    |
50  |     let ptr = kclvm_value_from_json(ctx, result_json);
    |               ---------------------      ^^^^^^^^^^^ expected `*const i8`, found `*const u8`
    |               |
    |               arguments to this function are incorrect
    |
    = note: expected raw pointer `*const i8`
               found raw pointer `*const u8`
note: function defined here
   --> runtime/src/value/api.rs:432:26
    |
432 | pub unsafe extern "C" fn kclvm_value_from_json(
    |                          ^^^^^^^^^^^^^^^^^^^^^
433 |     ctx: *mut kclvm_context_t,
434 |     s: *const kclvm_char_t,
    |     ----------------------

For more information about this error, try `rustc --explain E0308`.
error: could not compile `kclvm-runtime` (lib) due to 7 previous errors
warning: build failed, waiting for other jobs to finish...
make: *** [Makefile:26: build] Error 101
subprocess exited with status 2
subprocess exited with status 2

4. What is your KCL components version? (Required)

kcl.git 1742047

@Peefy
Copy link
Contributor

Peefy commented Jan 15, 2024

Hello @AdmiralNemo. Thank you for your feedback. This may be due to Rust FFI type of core::ffi::c_char varies on different machines, and I will try using the generic fix later to address this issue. #983

@Peefy
Copy link
Contributor

Peefy commented Jan 15, 2024

Related Issue: kcl-lang/cli#31 and #985

@AdmiralNemo
Copy link
Author

Thanks for the quick response! With the latest commit, I'm seeing some different but related compilation errors:

error[E0308]: mismatched types
  --> runtime/src/context/api.rs:93:50
   |
93 |         p.set_kcl_location_info(None, Some(c2str(filename)), Some(line), Some(col));
   |                                            ----- ^^^^^^^^ expected `*const u8`, found `*const i8`
   |                                            |
   |                                            arguments to this function are incorrect
   |
   = note: expected raw pointer `*const u8`
              found raw pointer `*const i8`
note: function defined here
  --> runtime/src/api/utils.rs:40:15
   |
40 | pub(crate) fn c2str<'a>(s: *const c_char) -> &'a str {
   |               ^^^^^     ----------------

error[E0308]: mismatched types
   --> runtime/src/context/api.rs:107:33
    |
107 |         p.set_kcl_pkgpath(c2str(pkgpath));
    |                           ----- ^^^^^^^ expected `*const u8`, found `*const i8`
    |                           |
    |                           arguments to this function are incorrect
    |
    = note: expected raw pointer `*const u8`
               found raw pointer `*const i8`
note: function defined here
   --> runtime/src/api/utils.rs:40:15
    |
40  | pub(crate) fn c2str<'a>(s: *const c_char) -> &'a str {
    |               ^^^^^     ----------------

error[E0308]: mismatched types
   --> runtime/src/context/api.rs:119:36
    |
119 |         ctx.set_kcl_filename(c2str(filename));
    |                              ----- ^^^^^^^^ expected `*const u8`, found `*const i8`
    |                              |
    |                              arguments to this function are incorrect
    |
    = note: expected raw pointer `*const u8`
               found raw pointer `*const i8`
note: function defined here
   --> runtime/src/api/utils.rs:40:15
    |
40  | pub(crate) fn c2str<'a>(s: *const c_char) -> &'a str {
    |               ^^^^^     ----------------

error[E0308]: mismatched types
   --> runtime/src/context/api.rs:208:5
    |
193 | ) -> *const c_char {
    |      ------------- expected `*const u8` because of return type
...
208 |     result_json
    |     ^^^^^^^^^^^ expected `*const u8`, found `*const i8`
    |
    = note: expected raw pointer `*const u8`
               found raw pointer `*const i8`

error[E0308]: mismatched types
   --> runtime/src/value/api.rs:196:33
    |
196 |         if v.is_null() || *v == '\0' as i8 {
    |                                 ^^^^^^^^^^ expected `u8`, found `i8`

error[E0277]: can't compare `u8` with `i8`
   --> runtime/src/value/api.rs:196:30
    |
196 |         if v.is_null() || *v == '\0' as i8 {
    |                              ^^ no implementation for `u8 == i8`
    |
    = help: the trait `PartialEq<i8>` is not implemented for `u8`
    = help: the following other types implement trait `PartialEq<Rhs>`:
              <u8 as PartialEq<serde_json::Value>>
              <u8 as PartialEq>

error[E0308]: mismatched types
   --> runtime/src/value/api.rs:546:36
    |
543 | pub unsafe extern "C" fn kclvm_value_Str_ptr(p: *const kclvm_value_ref_t) -> *const kclvm_char_t {
    |                                                                              ------------------- expected `*const u8` because of return type
...
546 |         Value::str_value(ref v) => v.as_ptr() as *const i8,
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^ expected `*const u8`, found `*const i8`
    |
    = note: expected raw pointer `*const u8`
               found raw pointer `*const i8`

error[E0308]: mismatched types
  --> runtime/src/stdlib/builtin_api.rs:17:35
   |
17 |     ctx.builtin_option_init(c2str(key), c2str(value));
   |                             ----- ^^^ expected `*const u8`, found `*const i8`
   |                             |
   |                             arguments to this function are incorrect
   |
   = note: expected raw pointer `*const u8`
              found raw pointer `*const i8`
note: function defined here
  --> runtime/src/api/utils.rs:40:15
   |
40 | pub(crate) fn c2str<'a>(s: *const c_char) -> &'a str {
   |               ^^^^^     ----------------

error[E0308]: mismatched types
  --> runtime/src/stdlib/builtin_api.rs:17:47
   |
17 |     ctx.builtin_option_init(c2str(key), c2str(value));
   |                                         ----- ^^^^^ expected `*const u8`, found `*const i8`
   |                                         |
   |                                         arguments to this function are incorrect
   |
   = note: expected raw pointer `*const u8`
              found raw pointer `*const i8`
note: function defined here
  --> runtime/src/api/utils.rs:40:15
   |
40 | pub(crate) fn c2str<'a>(s: *const c_char) -> &'a str {
   |               ^^^^^     ----------------

error[E0308]: mismatched types
  --> runtime/src/stdlib/plugin.rs:44:48
   |
44 |     let result_json = kclvm_plugin_invoke_json(method, args_json, kwargs_json);
   |                       ------------------------ ^^^^^^ expected `*const u8`, found `*const i8`
   |                       |
   |                       arguments to this function are incorrect
   |
   = note: expected raw pointer `*const u8`
              found raw pointer `*const i8`
note: function defined here
  --> runtime/src/stdlib/plugin.rs:66:19
   |
66 | pub extern "C" fn kclvm_plugin_invoke_json(
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^
67 |     method: *const c_char,
   |     ---------------------

error[E0308]: mismatched types
   --> runtime/src/_kcl_run.rs:190:34
    |
190 |             kclvm_value_Str(ctx, b"{}\0" as *const u8 as *const kclvm_char_t)
    |             ---------------      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `*const u8`, found `*const i8`
    |             |
    |             arguments to this function are incorrect
    |
    = note: expected raw pointer `*const u8`
               found raw pointer `*const i8`
note: function defined here
   --> runtime/src/value/api.rs:190:26
    |
190 | pub unsafe extern "C" fn kclvm_value_Str(
    |                          ^^^^^^^^^^^^^^^
191 |     ctx: *mut kclvm_context_t,
192 |     v: *const kclvm_char_t,
    |     ----------------------

error[E0308]: mismatched types
   --> runtime/src/_kcl_run.rs:203:39
    |
203 |             std::ptr::copy(c_str_ptr, result_buffer, return_len as usize);
    |             --------------            ^^^^^^^^^^^^^ expected `*mut u8`, found `*mut i8`
    |             |
    |             arguments to this function are incorrect
    |
    = note: expected raw pointer `*mut u8`
               found raw pointer `*mut i8`
note: function defined here
   --> /build/rustc-ZBSOmY/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/core/src/intrinsics.rs:2710:21

@Peefy
Copy link
Contributor

Peefy commented Jan 15, 2024

@AdmiralNemo Sorry, see this PR: #986, it is merged. You can try it again. 🙏 Pls note the build deps. https://github.com/kcl-lang/kcl/blob/main/scripts/docker/kcl-builder-arm64/Dockerfile

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

Successfully merging a pull request may close this issue.

2 participants