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

Add RISC-V (64-bit) support #6951

Closed
benz0li opened this issue Aug 19, 2024 · 31 comments
Closed

Add RISC-V (64-bit) support #6951

benz0li opened this issue Aug 19, 2024 · 31 comments
Labels
enhancement Some improvement that isn't a feature

Comments

@benz0li
Copy link
Contributor

benz0li commented Aug 19, 2024

What is your suggestion?

Build releases for Linux/RISC-V (64-bit).

Why do you want this feature?

The next stable version of Debian (13, aka trixie) is expected to ship with RISC-V 64-bit support.

Are there any workarounds to get this functionality today?

Do not know yet: I am trying to build code-server in a ubuntu:20.04 image.

Are you interested in submitting a PR for this?

Maybe.

@benz0li benz0li added the enhancement Some improvement that isn't a feature label Aug 19, 2024
@benz0li
Copy link
Contributor Author

benz0li commented Aug 19, 2024

Cross references:

Please upvote microsoft/vscode#206766 to add RISC-V support for Code - OSS.

@benz0li
Copy link
Contributor Author

benz0li commented Aug 19, 2024

@sakthivel-axim Could you test one of the following release files:

THE LINUX/RISCV64 RELEASE FILES ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.

@code-server There will be follow-up posts on how these release files were created.

@benz0li
Copy link
Contributor Author

benz0li commented Aug 20, 2024

On a RISC-V machine1 that runs Debian unstable (sid) and has Docker installed:

Host

Dockerfile:

FROM debian:sid

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
  ## Install Prerequisites
  && apt-get install -y --no-install-recommends \
    bats \
    build-essential \
    git \
    git-lfs \
    gnupg \
    jq \
    libkrb5-dev \
    libsecret-1-dev \
    libx11-dev \
    libxkbfile-dev \
    libxt6 \
    nodejs \
    python-is-python3 \
    python3-dev \
    python3-pip \
    python3-venv \
    quilt \
    rsync \
    unzip \
  ## Clean up
  && rm -rf /var/lib/apt/lists/*

RUN apt-get update \
  ## Install npm and yarn
  && apt-get install -y --no-install-recommends npm \
  && npm install --global yarn \
  ## Clean up
  && rm -rf /var/lib/apt/lists/*

ARG GO_VERSION=1.23.0 

ENV PATH=/root/go/bin:$PATH

  ## Install go and nfpm
RUN curl -sSLO "https://go.dev/dl/go$GO_VERSION.linux-riscv64.tar.gz" \
  && tar -C /root -xzf "go$GO_VERSION.linux-riscv64.tar.gz" \
  && go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest

Build image:

docker build -t code-server-builder .

Run container:

docker run --rm -ti code-server-builder

Container

Clone code-server:

git clone https://github.com/coder/code-server.git
cd code-server

Clone vscode submodule:

git submodule update --init

Apply patches

quilt push -a

playwright/chromium is not (yet) available for Linux/RISC-V. And since electron [therefore] also lacks RISC-V support, https://github.com/microsoft/vscode/blob/26a90463972295bcb960b7487a7c69afa06626eb/build/azure-pipelines/oss/product-build-pr-cache-linux.yml#L62-L63 is required:

export ELECTRON_SKIP_BINARY_DOWNLOAD=1
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1

Install dependencies:

yarn

--- Build steps

Export version:

export VERSION=0.0.0

Build code-server:

yarn build
yarn build:vscode
yarn release

ℹ️ yarn build:vscode took several hours. The time will be measured more accurately next time.

Footnotes

  1. In my case: https://github.com/utmapp/mac.getutm.app/issues/31 (QEMU v7.2 RV64 on AArch64; extended to 8 cores, 16 GB RAM, 64 GB disk)

@benz0li
Copy link
Contributor Author

benz0li commented Aug 20, 2024

--- Release steps

Export version:

export VERSION=0.0.0

Build code-server:

yarn build
yarn build:vscode
KEEP_MODULES=1 yarn release

Modify version:

npm version --prefix release "$VERSION"
tmp=$(mktemp)
jq ".codeServerVersion = \"$VERSION\"" release/lib/vscode/product.json > "$tmp" && mv "$tmp" release/lib/vscode/product.json
chmod 644 release/lib/vscode/product.json

Build release packages:

yarn release:standalone
yarn test:integration
yarn package

@benz0li
Copy link
Contributor Author

benz0li commented Aug 20, 2024

ℹ️ Without

export ELECTRON_SKIP_BINARY_DOWNLOAD=1
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1

command yarn exits with Error: ERROR: Playwright does not support chromium on <unknown>.

Container logs

yarn install v1.22.22
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
[4/5] Linking dependencies...
[5/5] Building fresh packages...
$ ./ci/dev/postinstall.sh
Installing dependencies for /root/projects/coder/code-server/test
yarn install v1.22.22
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning " > ts-jest@27.1.2" has unmet peer dependency "typescript@>=3.8 <5.0".
[4/4] Building fresh packages...
Done in 122.14s.
Installing dependencies for /root/projects/coder/code-server/test/e2e/extensions/test-extension
yarn install v1.22.22
[1/5] Validating package.json...
warning code-server-extension@0.0.1: The engine "vscode" appears to be invalid.
[2/5] Resolving packages...
[3/5] Fetching packages...
[4/5] Linking dependencies...
[5/5] Building fresh packages...
Done in 12.50s.
Installing dependencies for /root/projects/coder/code-server/lib/vscode
yarn install v1.22.22
$ node build/npm/preinstall.js
[1/4] Resolving packages...
[2/4] Fetching packages...
info There appears to be trouble with your network connection. Retrying...
[3/4] Linking dependencies...
warning "@microsoft/1ds-core-js > @microsoft/applicationinsights-core-js@2.8.15" has unmet peer dependency "tslib@*".
warning " > tsec@0.2.7" has unmet peer dependency "@bazel/bazelisk@>=1.7.5".
warning " > tsec@0.2.7" has unmet peer dependency "@bazel/concatjs@>=5.3.0".
[4/4] Building fresh packages...
[1/21] ⠈ @parcel/watcher
[6/21] ⠁ @vscode/sqlite3
[15/21] ⠁ @swc/core
[16/21] ⠁ @playwright/browser-chromium
error /root/projects/coder/code-server/lib/vscode/node_modules/@playwright/browser-chromium: Command failed.
Exit code: 1
Command: node install.js
Arguments: 
Directory: /root/projects/coder/code-server/lib/vscode/node_modules/@playwright/browser-chromium
Output:
/root/projects/coder/code-server/lib/vscode/node_modules/playwright-core/lib/server/registry/index.js:695
    if (!downloadURLs.length) throw new Error(`ERROR: Playwright does not support ${descriptor.name} on ${_hostPlatform.hostPlatform}`);
                                    ^

Error: ERROR: Playwright does not support chromium on <unknown>
    at Registry._downloadExecutable (/root/projects/coder/code-server/lib/vscode/node_modules/playwright-core/lib/server/registry/index.js:695:37)
    at Object._install (/root/projects/coder/code-server/lib/vscode/node_modules/playwright-core/lib/server/registry/index.js:362:28)
    at Registry.install (/root/projects/coder/code-server/lib/vscode/node_modules/playwright-core/lib/server/registry/index.js:629:26)




error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

@benz0li
Copy link
Contributor Author

benz0li commented Aug 20, 2024

❗ This is a proof of concept (PoC). If Node.js for Debian unstable (sid) is updated to v22, this may no longer work.

The situation will become (more) stable once Debian 13 (aka trixie) is released – in summer 2025.

  1. Debian stable: Official support for RISC-V
  2. Node.js : RISC-V to Experimental tier nodejs/build#2876 resolved1?

Footnotes

  1. Unofficial RISC-V binaries available at https://unofficial-builds.nodejs.org

@benz0li
Copy link
Contributor Author

benz0li commented Aug 20, 2024

@sakthivel-axim @karthick-govindaraj @archanox Could any of you confirm that the Linux/RISC-V releases of code-server mentioned in #6951 (comment) actually work?

Thank you.

@archanox
Copy link

@benz0li I tried the linked deb install above, and setup the service, but it didn't come up.

pierce@k1:~$ sudo systemctl status  code-server@$USER
× code-server@pierce.service - code-server
     Loaded: loaded (/lib/systemd/system/code-server@.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Tue 2024-08-20 21:12:31 AEST; 1min 24s ago
   Duration: 25ms
    Process: 13607 ExecStart=/usr/bin/code-server (code=exited, status=127)
   Main PID: 13607 (code=exited, status=127)
        CPU: 29ms

Aug 20 21:12:31 k1 systemd[1]: code-server@pierce.service: Scheduled restart job, restart counter is at 5.
Aug 20 21:12:31 k1 systemd[1]: Stopped code-server@pierce.service - code-server.
Aug 20 21:12:31 k1 systemd[1]: code-server@pierce.service: Start request repeated too quickly.
Aug 20 21:12:31 k1 systemd[1]: code-server@pierce.service: Failed with result 'exit-code'.
Aug 20 21:12:31 k1 systemd[1]: Failed to start code-server@pierce.service - code-server.
pierce@k1:~$ 

I'm not sure if I'm missing a step or a dependency.

@benz0li
Copy link
Contributor Author

benz0li commented Aug 20, 2024

@archanox What happens if you simply execute /usr/bin/code-server?

@archanox
Copy link

pierce@k1:~$ /usr/bin/code-server
/usr/lib/code-server/lib/node: error while loading shared libraries: libnode.so.115: cannot open shared object file: No such file or directory
pierce@k1:~$ 

@benz0li
Copy link
Contributor Author

benz0li commented Aug 20, 2024

@archanox Thank you for the feedback.

On a AArch64 machine, ldd /opt/code-server/lib/node returns

        linux-vdso.so.1 (0x0000ffffb4272000)
        libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000ffffb4210000)
        libstdc++.so.6 => /lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000ffffb3ff0000)
        libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000ffffb3f50000)
        libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000ffffb3f10000)
        libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000ffffb3ee0000)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000ffffb3d30000)
        /lib/ld-linux-aarch64.so.1 (0x0000ffffb4235000)

On a RISC-V machine, ldd /opt/code-server/lib/node returns

        linux-vdso.so.1 (0x00007fff9f294000)
        libnode.so.115 => not found
        libc.so.6 => /lib/riscv64-linux-gnu/libc.so.6 (0x00007fff9f127000)
        /lib/ld-linux-riscv64-lp64d.so.1 (0x00007fff9f295000)

I will start a build1 with an unofficial Linux/RISC-V Node.js binary from https://unofficial-builds.nodejs.org/.

Maybe that produces a different result.


Time measurements:

  • yarn: 44 minutes 31 seconds
  • yarn build:vscode: 6 hours 30 minutes 8 seconds

Footnotes

  1. Docker v27.1.2 on x86_64 with emulators installed

@benz0li
Copy link
Contributor Author

benz0li commented Aug 20, 2024

On a non-'RISC-V' machine:

Dockerfile (using an unofficial Linux/RISC-V Node.js binary):

FROM ubuntu:20.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
  ## Install Prerequisites
  && apt-get install -y --no-install-recommends \
    bats \
    build-essential \
    git \
    git-lfs \
    gnupg \
    jq \
    libkrb5-dev \
    libsecret-1-dev \
    libx11-dev \
    libxkbfile-dev \
    libxt6 \
    python-is-python3 \
    python3-dev \
    python3-pip \
    python3-venv \
    quilt \
    rsync \
    unzip \
  ## Clean up
  && rm -rf /var/lib/apt/lists/*

ARG NODE_VERSION=20.14.0

RUN apt-get update \
  && apt-get install -y --no-install-recommends curl \
  ## Install Node.js (https://github.com/nodejs/docker-node)
  && curl -fsSLO --compressed "https://unofficial-builds.nodejs.org/download/release/v$NODE_VERSION/node-v$NODE_VERSION-linux-riscv64.tar.xz" \
  && tar -xJf "node-v$NODE_VERSION-linux-riscv64.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
  && rm "node-v$NODE_VERSION-linux-riscv64.tar.xz" \
  ## Remove unused OpenSSL headers to save ~34MB. See this NodeJS issue: https://github.com/nodejs/node/issues/46451
  && find /usr/local/include/node/openssl/archs -mindepth 1 -maxdepth 1 ! -name linux-riscv64 -exec rm -rf {} \; \
  && ln -s /usr/local/bin/node /usr/local/bin/nodejs \
  ## Clean up Node.js installation
  && rm -f /usr/local/bin/yarn \
  && bash -c 'mv /usr/local/{CHANGELOG.md,LICENSE,README.md} \
    /usr/local/share/doc/node' \
  ## Enable corepack (yarn, [p]npm)
  && corepack enable \
  ## Clean up
  && rm -rf /var/lib/apt/lists/*

ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0

ARG GO_VERSION=1.23.0 

ENV PATH=/root/go/bin:$PATH

  ## Install go and nfpm
RUN curl -sSLO "https://go.dev/dl/go$GO_VERSION.linux-riscv64.tar.gz" \
  && tar -C /root -xzf "go$GO_VERSION.linux-riscv64.tar.gz" \
  && go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest

Install emulator:

# Docker CE
docker run --privileged --rm tonistiigi/binfmt:master --install riscv64
# Docker Desktop
docker run --privileged --rm tonistiigi/binfmt:desktop-master --install riscv64

Build image:

docker build --platform linux/riscv64 -t code-server-builder .

Run container:

docker run --rm --platform linux/riscv64 -ti code-server-builder

@benz0li
Copy link
Contributor Author

benz0li commented Aug 21, 2024

@archanox The Linux/RISC-V releases of code-server have been rebuilt and uploaded (same links). Please try again.

Please test whether extensions can be installed successfully. Because yarn test:integration returned the following error:

yarn run v1.22.22
$ ./ci/dev/test-integration.sh
Set CODE_SERVER_PATH to test another build of code-server
Running tests with code-server binary: 'release-standalone/bin/code-server'
Determining test suites to run...ts-jest[versions] (WARN) Version 5.5.2 of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=3.8.0 <5.0.0-0). Please do not report issues in ts-jest if you are using unsupported versions.
ts-jest[versions] (WARN) Version 5.5.2 of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=3.8.0 <5.0.0-0). Please do not report issues in ts-jest if you are using unsupported versions.
ts-jest[versions] (WARN) Version 5.5.2 of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=3.8.0 <5.0.0-0). Please do not report issues in ts-jest if you are using unsupported versions.
 PASS  test/integration/help.test.ts (28.905 s)
 FAIL  test/integration/installExtension.test.ts (31.624 s)
  ● --install-extension › should use EXTENSIONS_GALLERY when set

    thrown: "Exceeded timeout of 5000 ms for a test.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

      12 |     setupFlags = ["--extensions-dir", tempDir]
      13 |   })
    > 14 |   it("should use EXTENSIONS_GALLERY when set", async () => {
         |   ^
      15 |     const extName = "author.extension"
      16 |     await expect(
      17 |       runCodeServerCommand([...setupFlags, "--install-extension", extName], {

      at test/integration/installExtension.test.ts:14:3
      at Object.<anonymous> (test/integration/installExtension.test.ts:4:1)

A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them.
Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        38.05 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@benz0li
Copy link
Contributor Author

benz0li commented Aug 21, 2024

Runtime requirement: libatomic1 (debian:sid image)

code-server_riscv64

ldd /opt/code-server/lib/node1 returns

        linux-vdso.so.1 (0x00007fffbcf8a000)
        libdl.so.2 => /lib/riscv64-linux-gnu/libdl.so.2 (0x00007fffbcf80000)
        libatomic.so.1 => /lib/riscv64-linux-gnu/libatomic.so.1 (0x00007fffbcf78000)
        libstdc++.so.6 => /lib/riscv64-linux-gnu/libstdc++.so.6 (0x00007fffbcc00000)
        libm.so.6 => /lib/riscv64-linux-gnu/libm.so.6 (0x00007fffbceff000)
        libgcc_s.so.1 => /lib/riscv64-linux-gnu/libgcc_s.so.1 (0x00007fffbcee3000)
        libpthread.so.0 => /lib/riscv64-linux-gnu/libpthread.so.0 (0x00007fffbcee0000)
        libc.so.6 => /lib/riscv64-linux-gnu/libc.so.6 (0x00007fffbca9d000)
        /lib/ld-linux-riscv64-lp64d.so.1 (0x00007fffbcf8b000)

now.

Footnotes

  1. Using QEMU v7.2 RV64 on AArch64 because Docker v27.1.2 on x86_64 with emulators installed exits with unknown exit code (139).

@benz0li
Copy link
Contributor Author

benz0li commented Aug 21, 2024

@archanox I have rebuilt once more using Node.js v20.14.0 to match the version that was used to build VS Code v1.92.2.

Thank you for testing. Feedback is welcome.

@archanox
Copy link

@benz0li unfortunately I made some irreversible changes to my environment, and I'm not sure how to get into recovery mode. So it may be a while before I can test again.

@karthick-govindaraj
Copy link

hi @benz0li

I’ve successfully installed the package from this link on the StarFive VisionFive 2 board, which is based on the RISC-V architecture. The package is working as expected,

Screenshot from 2024-09-02 11-42-46

but I’m encountering some errors in the terminal. Could you please take a look?

Screenshot from 2024-09-02 11-43-22

Really great work, much appreciated!

@benz0li
Copy link
Contributor Author

benz0li commented Sep 2, 2024

Error: /lib/riscv64-linux-gnu/libstdc++.so.6: version 'CXXABI 1.3.15' not found

@karthick-govindaraj What Linux distribution and version are you running code-server with?

(I could rebuild code-server using ubuntu:22.04 (CXXABI 1.3.13) or even ubuntu:20.04 (CXXABI 1.3.12) to increase compatibility)

2024-09-02T15:01:32+02:00: A rebuild using ubuntu:20.04 (CXXABI 1.3.12) is currently ongoing.
2024-09-02T22:40:52+02:00: Build done

@benz0li
Copy link
Contributor Author

benz0li commented Sep 2, 2024

@karthick-govindaraj To increase compatibility, I rebuilt again using ubuntu:20.04.

@karthick-govindaraj
Copy link

@benz0li
image

@karthick-govindaraj
Copy link

@karthick-govindaraj To increase compatibility, I rebuilt again using ubuntu:20.04.

can you share the latest build will check and update you.!

@benz0li
Copy link
Contributor Author

benz0li commented Sep 3, 2024

@benz0li
Copy link
Contributor Author

benz0li commented Sep 3, 2024

@karthick-govindaraj On your Debian machine, what does

strings /lib/*-linux-gnu/libstdc++.so.6 | grep CXXABI

return?


P.S.: If strings: command not found, then apt-get update && apt-get install binutils

P.P.S.: If strings: '/lib/*-linux-gnu/libstdc++.so.6': No such file, then apt-get update && apt-get install libstdc++6

@karthick-govindaraj
Copy link

@benz0li

$ strings /lib/*-linux-gnu/libstdc++.so.6 | grep CXXABI
CXXABI_1.3
CXXABI_1.3.1
CXXABI_1.3.2
CXXABI_1.3.3
CXXABI_1.3.4
CXXABI_1.3.5
CXXABI_1.3.6
CXXABI_1.3.7
CXXABI_1.3.8
CXXABI_1.3.9
CXXABI_1.3.10
CXXABI_1.3.11
CXXABI_1.3.12
CXXABI_1.3.13
CXXABI_TM_1

@karthick-govindaraj
Copy link

hi @benz0li
I am exploring Code Server and noticed that the debugger option is missing. Did you miss anything while building Code Server?

image

@benz0li
Copy link
Contributor Author

benz0li commented Sep 3, 2024

Did you miss anything while building Code Server?

Nothing that I am aware of.

@karthick-govindaraj
Copy link

I have installed Code Server on a Linux machine, and the UI of the debugger tab looks similar to VS Code.

image

After installing the debugger extension, we can set breakpoints and debug the program, as shown in the image below.

image

In your build, I haven't seen any way to access debugging.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 3, 2024

I am exploring Code Server and noticed that the debugger option is missing.

I cannot confirm that:

debug

(Installed using code-server-4.92.2-linux-riscv64.tar.gz1)

Q.E.F.

Footnotes

  1. The DEB and RPM packages should also work. Everything is built the same way as for the other architectures.

@karthick-govindaraj
Copy link

karthick-govindaraj commented Sep 4, 2024

(Installed using code-server-4.92.2-linux-riscv64.tar.gz)

@benz0li
in code-server-4.92.2-linux-riscv64.tar.gz debug option working thanks.!

@benz0li
Copy link
Contributor Author

benz0li commented Sep 4, 2024

@karthick-govindaraj Thank you for testing!

ℹ️ Please be aware that not all extensions [that rely on Linux binaries] will work on Linux/RISC-V.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 7, 2024

@karthick-govindaraj @archanox Unofficial and untested builds are now published at https://gitlab.b-data.ch/coder/code-server/-/releases.
ℹ️ Available for Linux/RISC-V and Linux/PowerPC64le. A build for Linux/s390x was unsuccessful.

FYI @code-asher

@benz0li benz0li closed this as completed Sep 7, 2024
@benz0li benz0li changed the title Add RISC-V support Add RISC-V (64-bit) support Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Some improvement that isn't a feature
Projects
None yet
Development

No branches or pull requests

3 participants