regolith-labs / ore

ORE is a cryptocurrency everyone can mine.
https://ore.supply
687 stars 235 forks source link

fix failed test on non x86 target #19

Closed Metal-joker closed 4 months ago

Metal-joker commented 7 months ago

This pr replaced bs64: '0.1.2' to base64: '0.22.0' to ensure test is able to run on non x86 target.

The original dependency bs64 version '0.1.2' encounters issues with its encode function due to flawed fallback logic. Specifically, when the target architecture is not x86, the macro is_x86_feature_detected! triggers a panic. This same behavior is observed in the decode function as well.

entry:

    pub fn encode(self, input: &[u8]) -> String {
        let mut output = vec![0u8; encode_len(input.len())];
        avx2::encode_with_fallback(&mut output, input);
        unsafe { String::from_utf8_unchecked(output) }
    }

impl:

pub fn encode_with_fallback(dest: &mut [u8], str: &[u8]) -> usize {
    if is_x86_feature_detected!("avx2") {
        unsafe { encode(dest, str) }
    } else {
        simple::encode(str, dest)
    }
}

error:

error: This macro cannot be used on the current target.
                                   You can prevent it from being used in other architectures by
                                   guarding it behind a cfg(any(target_arch = "x86", target_arch = "x86_64")).
  --> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bs64-0.1.2/src/avx2/mod.rs:73:8
   |
73 |     if is_x86_feature_detected!("avx2") {
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info)

error: This macro cannot be used on the current target.
                                   You can prevent it from being used in other architectures by
                                   guarding it behind a cfg(any(target_arch = "x86", target_arch = "x86_64")).
   --> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bs64-0.1.2/src/avx2/mod.rs:159:8
    |
159 |     if is_x86_feature_detected!("avx2") {
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this error originates in the macro `is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info)