code-server icon indicating copy to clipboard operation
code-server copied to clipboard

Add RISC-V support

Open benz0li opened this issue 1 year ago • 16 comments

What is your suggestion?

Build releases for Linux/RISCV64.

Why do you want this feature?

The next stable version of Debian (13, aka trixie) adds RISC-V support.

Are there any workarounds to get this functionality today?

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

Are you interested in submitting a PR for this?

Maybe.

benz0li avatar Aug 19 '24 10:08 benz0li

Cross references:

  • https://github.com/coder/code-server/discussions/6266
  • https://github.com/microsoft/vscode/issues/206766

Please upvote https://github.com/microsoft/vscode/issues/206766 to add RISC-V support for Code - OSS.

benz0li avatar Aug 19 '24 10:08 benz0li

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

  • https://gitlab.b-data.ch/coder/code-server/-/releases/v4.92.2/downloads/builds/code-server-4.92.2-linux-riscv64.tar.gz
  • https://gitlab.b-data.ch/coder/code-server/-/releases/v4.92.2/downloads/builds/code-server-4.92.2-riscv64.rpm
  • https://gitlab.b-data.ch/coder/code-server/-/releases/v4.92.2/downloads/builds/code-server_4.92.2_riscv64.deb

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 avatar Aug 19 '24 18:08 benz0li

On a RISC-V machine[^1] that runs Debian unstable (sid) and has Docker installed:

[^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)

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.

benz0li avatar Aug 20 '24 05:08 benz0li

--- 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 avatar Aug 20 '24 05:08 benz0li

ℹ️ 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 " > [email protected]" 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 [email protected]: 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/[email protected]" has unmet peer dependency "tslib@*".
warning " > [email protected]" has unmet peer dependency "@bazel/bazelisk@>=1.7.5".
warning " > [email protected]" 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 avatar Aug 20 '24 05:08 benz0li

❗ 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 : https://github.com/nodejs/build/issues/2876 resolved[^1]?

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

benz0li avatar Aug 20 '24 05:08 benz0li

@sakthivel-axim @karthick-govindaraj @archanox Could any of you confirm that the Linux/RISC-V releases of code-server mentioned in https://github.com/coder/code-server/issues/6951#issuecomment-2297215969 actually work?

Thank you.

benz0li avatar Aug 20 '24 09:08 benz0li

@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
× [email protected] - code-server
     Loaded: loaded (/lib/systemd/system/[email protected]; 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]: [email protected]: Scheduled restart job, restart counter is at 5.
Aug 20 21:12:31 k1 systemd[1]: Stopped [email protected] - code-server.
Aug 20 21:12:31 k1 systemd[1]: [email protected]: Start request repeated too quickly.
Aug 20 21:12:31 k1 systemd[1]: [email protected]: Failed with result 'exit-code'.
Aug 20 21:12:31 k1 systemd[1]: Failed to start [email protected] - code-server.
pierce@k1:~$ 

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

archanox avatar Aug 20 '24 11:08 archanox

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

benz0li avatar Aug 20 '24 11:08 benz0li

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:~$ 

archanox avatar Aug 20 '24 11:08 archanox

@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 build[^1] with an unofficial Linux/RISC-V Node.js binary from https://unofficial-builds.nodejs.org/.

[^1]: Docker v27.1.2 on x86_64 with emulators installed

Maybe that produces a different result.


Time measurements:

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

benz0li avatar Aug 20 '24 11:08 benz0li

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 avatar Aug 20 '24 14:08 benz0li

@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 avatar Aug 21 '24 03:08 benz0li

Runtime requirement: libatomic1 (debian:sid image)

code-server_riscv64

ldd /opt/code-server/lib/node[^1] returns

[^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).

        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.

benz0li avatar Aug 21 '24 09:08 benz0li

@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.

benz0li avatar Aug 21 '24 13:08 benz0li

@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.

archanox avatar Aug 21 '24 14:08 archanox

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!

karthick-govindaraj avatar Sep 02 '24 11:09 karthick-govindaraj

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 avatar Sep 02 '24 11:09 benz0li

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

benz0li avatar Sep 02 '24 20:09 benz0li

@benz0li image

karthick-govindaraj avatar Sep 03 '24 04:09 karthick-govindaraj

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

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

karthick-govindaraj avatar Sep 03 '24 04:09 karthick-govindaraj

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

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

Same URLs:

  • https://gitlab.b-data.ch/coder/code-server/-/releases/v4.92.2/downloads/builds/code-server-4.92.2-linux-riscv64.tar.gz
  • https://gitlab.b-data.ch/coder/code-server/-/releases/v4.92.2/downloads/builds/code-server-4.92.2-riscv64.rpm
  • https://gitlab.b-data.ch/coder/code-server/-/releases/v4.92.2/downloads/builds/code-server_4.92.2_riscv64.deb

benz0li avatar Sep 03 '24 04:09 benz0li

@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

benz0li avatar Sep 03 '24 04:09 benz0li

@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 avatar Sep 03 '24 05:09 karthick-govindaraj

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

image

karthick-govindaraj avatar Sep 03 '24 11:09 karthick-govindaraj

Did you miss anything while building Code Server?

Nothing that I am aware of.

benz0li avatar Sep 03 '24 11:09 benz0li

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.

karthick-govindaraj avatar Sep 03 '24 11:09 karthick-govindaraj

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.gz[^1])

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

Q.E.F.

benz0li avatar Sep 03 '24 12:09 benz0li

(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.!

karthick-govindaraj avatar Sep 04 '24 04:09 karthick-govindaraj

@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 avatar Sep 04 '24 05:09 benz0li