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

Invalid arch detection when installing Dart? #26

Open
MangelMaxime opened this issue Sep 20, 2023 · 8 comments
Open

Invalid arch detection when installing Dart? #26

MangelMaxime opened this issue Sep 20, 2023 · 8 comments

Comments

@MangelMaxime
Copy link

Hello,

I am using dsm to install Dart inside a devcontainer running on a Mac M1.

And I believe running dsm install 3.1.2 installs the wrong architecture version of Dart.

Indeed, when trying to run dart after the installation I get the following error:

qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

If I run dsm install --arch arm64 3.1.2, then all is good I can invoke dart.

I believe it detect the wrong architecture because if I run dsm install --arch x64 latest then I get the same error as when running dsm install latest.

Is it related to #2 ?

Running uname -m inside the VM gives me aarch64

Reproduction

Dockfile I am using:

# Use x86_64 architecture to avoid all the small pains
# coming from alpine over ARM --platform=linux/amd64
FROM mcr.microsoft.com/devcontainers/base:debian
# Install the xz-utils package
RUN apt-get update && apt-get install -y xz-utils

# Options
# Let it here to avoid conflicts with Microsoft options !!!
ARG DOTNET_VERSION=6.0.406
ARG NODE_VERSION=18.8.0
ARG PYTHON_VERSION=3.11.5
ARG DART_VERSION=3.1.2

USER vscode

# Change the default shell to zsh
SHELL ["/bin/zsh", "-c"]

# # Install .NET
WORKDIR /home/vscode

# Instal dart
RUN curl -fsSL https://dsm-vm.vercel.app/install.sh | bash
RUN echo "# Load dart path" >> .zshrc
RUN echo 'export PATH="/home/vscode/.dsm:$PATH"' >> .zshrc
RUN echo 'eval "`dsm env zsh`"' >> .zshrc
# RUN source .zshrc && dsm install $DART_VERSION
# RUN source .zshrc && dsm use $DART_VERSION

# Force docker to load the zsh profile
# This should be the last steps
CMD [ "/bin/zsh" ]
  1. docker build --tag fable-dev .
  2. docker run -it --rm fable-dev
  3. dsm install latest
  4. dart <- See that this fails with the reported error
@Yakiyo
Copy link
Owner

Yakiyo commented Sep 21, 2023

Yes this issue related to #2 unfortunately i'm really not familar with architectures and which arch supports which and etc. At present, the only way would be is to manually set the arch with --arch. This can of course be made to be only required once, using one of the two following methods

  • Append export DSM_ARCH=arm64 in ~/.zshrc
  • Or use eval "`dsm env --arch arm64 zsh`" in stead of just "dsm env zsh"

Both of the above method sets the DSM_ARCH env var to arm64 so any call to dsm after them will use the env var for arch value.

I hope this should solve the issue?

@MangelMaxime
Copy link
Author

MangelMaxime commented Sep 21, 2023

In my case, I indeed use --arch arm64.

Because, I am using dsm as part of a dev container setup I created a small script:

#!/bin/zsh

if [[ $(uname -m) == 'aarch64' ]]; then
    dsm install --arch arm64 $1;
else
    dsm install $1;
fi

I don't know rust well and don't everything that is happening inside https://github.com/Yakiyo/dsm/blob/main/src/arch.rs

But am I correct to guess that the code in https://github.com/Yakiyo/dsm/blob/main/src/arch.rs is actually decided at compilation time?

I am saying that because from my research #[cfg(...)] seems to be a conditional compiler configuration.

With this hypothesis, is it possible that the problem is not actually arch.rs but the install.sh script which install the wrong release of dsm? In this case, this would means that

dsm/tools/install.sh

Lines 71 to 79 in 22f9794

if [ "$OS" = "linux" ]; then
case "$(uname -m)" in
arm | armv7*)
FILENAME="arm-unknown-linux-gnueabihf"
;;
*)
FILENAME="x86_64-unknown-linux-musl"
esac
elif [ "$OS" = "darwin" ]; then

Should be changed to arm | armv7*| aarch64) ?

Inside of my VM if I run the following script which is a copy of the filename function from dsm install script. I get as a result dsm-x86_64-unknown-linux-musl.

#!/bin/bash

set -e

OS=$(echo `uname -s`|tr '[:upper:]' '[:lower:]')

case "$OS" in
    mingw*) OS='windows';;
    msys*) OS='windows';;
esac

filename() {
  if [ "$OS" = "linux" ]; then
    case "$(uname -m)" in
      arm | armv7*)
        FILENAME="arm-unknown-linux-gnueabihf"
        ;;
      *)
        FILENAME="x86_64-unknown-linux-musl"
    esac
  elif [ "$OS" = "darwin" ]; then
    FILENAME="x86_64-apple-darwin"
  elif [ "$OS" = "windows" ]; then
    FILENAME="x86_64-pc-windows-msvc.exe"
  else
    echo "OS $OS is not supported."
    echo "If you think that's a bug - please file an issue to https://github.com/Yakiyo/dsm/issues"
    exit 1
  fi
  FILE="dsm-$FILENAME"
}

filename
echo $FILE

If I change arm | armv7*) to arm | armv7* | aarch64) then I get dsm-arm-unknown-linux-gnueabihf which I believe is the correct binary regarding my Linux VM which is running on an ARM Apple M1 mac.

According to the most trusted source on internet Wikipedia:

AArch64 or ARM64 is the 64-bit extension of the ARM architecture family.

Joke aside, I think doing the change I propose would solve my problem. I don't know if there are others edges not covered however.

@Yakiyo
Copy link
Owner

Yakiyo commented Sep 22, 2023

yes the things in arch.rs are decided at compile time and are hardcoded in the app. Ig the issue itself was in the installation script. Thanks for pointing that out. I'll fix the script and that should hopefully prevent any more similar issues in the future. Thanks for mentioning it.

@MangelMaxime
Copy link
Author

MangelMaxime commented Sep 22, 2023

Hum, I have another problem now.

When using the new installation script it is now installing arm-unknown-linux-gnueabihf version of dsm. But when trying to run dsm I now get this error:

qemu-arm: Could not open '/lib/ld-linux-armhf.so.3': No such file or directory

Which is a bit worth that before, because before I was able to run dsm it just didn't choose the right arch for dart.

I feel like on linux aarch64 we can't run the arm-unknown-linux-gnueabihf build of dsm. And need another release of dsm for aarch64 architecture. I tired to look at how to build dsm locally to make such a build and test ideas on how to fix the arch.rs file too but I don't know how to do that.

Would it be possible to explain to me how I can produce a build of dsm and decide which target_arch I build it for?

PS: I think reverting the changes made to the install.sh script is better for now. Sorry about that, I didn't think of the problem of running dsm itself.

@Yakiyo
Copy link
Owner

Yakiyo commented Sep 22, 2023

arch.rs uses conditional compilation for hardcoding architecture values at compile time.
You can tinker with it as you want.

#[cfg(all(
    target_pointer_width = "32", // target pointer width here - 32bit/64bit
    any(target_arch = "arm", target_arch = "aarch64") // target arch here
))]
pub fn platform_arch() -> &'static str {
    "armv7"
}

all and any are some handy funcs. in the above example any(target_arch = "arm", target_arch = "aarch64") means it will use the function if, the target arch is either arm or aarch64. The entire cfg part can be written as following in boolean terms.

target_pointer == 32 && (target_arch == "arm" || target_arch == "aarch64")

You can tinker with it as you want and see what happens.

@MangelMaxime
Copy link
Author

Thanks for the explanation on the compiler directives.

I was more looking to the cargo or rust command to run to compile the project and specify which architectures we are targeting. Something like cargo build --arch aarch64, I tried to look at the repo code but didn't really understand what the CI pipelines where doing sorry.

@Yakiyo
Copy link
Owner

Yakiyo commented Sep 23, 2023

Generally cargo builds on the default system target. But it can be configured to build for a different target, though not a specific architecture. Here's the relevant docs on the --target flag: link

@MangelMaxime
Copy link
Author

Ok thank you, I will give it a try

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