sctg-development / sctgdesk-server

Rendez-vous server, API server and web console for Rustdesk 100% in Rust ( integrated version, for standalone see https://github.com/sctg-development/sctgdesk-api-server )
https://sctg-development.github.io/sctgdesk-api-server
GNU Affero General Public License v3.0
89 stars 16 forks source link

add armhf to build actions + small problem #14

Closed cocoon closed 2 weeks ago

cocoon commented 2 weeks ago

Would be great if you could add: armhf as target to the build artifacts like in the official ones, as I cannot run arm64.

Additionally I found out, that if I use a renamed .exe for the rustdesk-program (official v1.3.1), like: rustdesk-host=192.168.1.101,key=abcdeFghijK..=.exe or rustdesk-host=192.168.1.101

The addressbook could not be accessed correctly.

POST /api/ab/get:
   >> No matching routes for POST /api/ab/get.
   >> No 404 catcher registered. Using Rocket default.

and:

POST /api/heartbeat application/json:
   >> Matched: (heartbeat) POST /api/heartbeat application/json
   >> Data guard `Json < HeartbeatRequest >` failed: Parse("{\"id\":\"12345678\",\"modified_at\":1720000000,\"ver\":1002000}", Error("missing field `uuid`", line: 1, column: 56)).
   >> Outcome: Error(422 Unprocessable Entity)
   >> No 422 catcher registered. Using Rocket default.

I tried to add api=xyz, but it does not add http:// automatically and these are illegal chars in a filename.

And the offical config string seems to be encrypted with a fixed key, so I see no option here currntly to set it in the filename?

used the current standalone nighlty build on windows: windows_x86_64_nightly.exe --address 0.0.0.0

aeltorio commented 2 weeks ago

Hi @cocoon , Thank you for your interest in my work,

Would be great if you could add: armhf

Do you mean Docker images, binaries or both ?

cocoon commented 2 weeks ago

Just the binaries.

Yes I am interested, and nice to see it directly implemented in Rust 👍 Even better to have both, standalone and integrated, nice work!

I am still playing around, maybe the API Key could be changed like this easily ...

https://rustdesk.com/docs/en/dev/build/all/

aeltorio commented 2 weeks ago

@cocoon a first test https://github.com/sctg-development/sctgdesk-server/actions/runs/11340240075/job/31536320437 is in progress

cocoon commented 2 weeks ago

Great thanks, that was quick. Seems to need some more love to build successfully.

eltorio commented 2 weeks ago

Hi,

I'm currently working on resolving the issue, but there are a few challenges:

You can follow the progress in the armhf branch. If you appreciate my work, please consider giving it a star! 🤩

Thanks,
Ronan

cocoon commented 2 weeks ago

I "love" these "hurdles" to get things (cross) compiled 🙄 Tried to get your branch compiled on windows and also failed to make it happy today ^^

Star is done 👍

Update: successfully compiled on windows for windows now

cocoon commented 2 weeks ago

Experimented a bit and might have some progress, but stuck here now: https://github.com/cocoon/sctgdesk-server_armhf/actions/runs/11363684261/job/31608160667#step:9:805

aeltorio commented 2 weeks ago

Regarding cross-compiling:

I’ve made some progress. You can check the details here.

Regarding the Docker build

I believe I have a solution. It’s currently being tested locally. I managed to solve the issue with QEMU emulating 32-bit platforms on 64-bit hosts. The idea is to force Cargo to use the Git CLI and run from a tmpfs. This workaround is a bit tricky.

Here’s the Dockerfile:

# Set up cargo config to use git tool
# this workaround is needed because QEMU emulating 32 bits platfom on 64 bits host
# see https://github.com/rust-lang/cargo/issues/8719
RUN mv /root/.cargo /tmp && rm -rf /root/.cargo && mkdir -p /root/.cargo 
RUN --mount=type=tmpfs,target=/root/.cargo mkdir -p /root/.cargo \
    && cp -av /tmp/.cargo/* /root/.cargo/ && ls -lR /root/.cargo \
    && if [ ! -f /root/.cargo/config.toml ]; then \
        echo "" > /root/.cargo/config.toml; \
    fi && \
    awk 'BEGIN{net_section=0;git_fetch_found=0;printed=0}/^\[net\]/{net_section=1;print;next}/^\[/{if(net_section&&!git_fetch_found){print "git-fetch-with-cli = true";printed=1}net_section=0;print;next}net_section&&/^git-fetch-with-cli\s*=/{print "git-fetch-with-cli = true";git_fetch_found=1;next}{print}END{if(!printed&&!git_fetch_found){if(!net_section)print "\n[net]";print "git-fetch-with-cli = true"}}' /root/.cargo/config.toml > /root/.cargo/config.tmp && \
    mv /root/.cargo/config.tmp /root/.cargo/config.toml \
    && . /root/.cargo/env && cd /build \ 
    && cargo update -p sctgdesk-api-server \
    && DATABASE_URL=sqlite://$(pwd)/db_v2.sqlite3 cargo build --release \
    && mkdir -p /build/ubuntu-jammy/bin \
    && cp /build/target/release/hbbr /build/ubuntu-jammy/bin/ \
    && cp /build/target/release/hbbs /build/ubuntu-jammy/bin/ \
    && cp /build/target/release/rustdesk-utils /build/ubuntu-jammy/bin/
cocoon commented 2 weeks ago

using QEMU sounds clever! Interesting. Just had the same problem that it tried to use "-m64".

aeltorio commented 2 weeks ago

My actual process is defined in /.github/workflows/multiarch-docker-hub.yml.

  1. Building the Multiarch Docker Image:

    • Using docker buildx for platforms linux/arm64 and linux/amd64, (buildx use QEMU) I create a multiarch Docker image based on Ubuntu 22.04 / Debian Bookworm.
    • The build occurs in an intermediate builder image, where some Debian packages are also created.
    • Although this method is slower, it accurately simulates a real build on the target platform, making it safer than cross-compiling.
    • The resulting image is named sctg/sctgdesk-server-integration.
  2. Extracting Binaries and Debian Packages:

    • I mount the sctg/sctgdesk-server-integration image and extract the binaries and Debian packages.
    • based on sctg/sctgdesk-server-integration I create the sctg/sctgdesk-server multiarch images

Currently, the test build for armhf is in progress locally.

image
  1. Cross-compiling The issue you hit is due to rs-cc who invent a -m64 parameter that's why in the armhf branch I tested with llvm.
    It works but sqlx is not a pure rust package it relies on libsqlite3 and its C headers. That why my builds fail. It needs to find the crosscompiled libsqlite3

  2. Windows and MacOS The are natively created with a Windows and a macOS runner

aeltorio commented 2 weeks ago

@cocoon Good news the integration image was built locally successfully docker.io/sctg/sctgdesk-server-integration:armhf@sha256:794e843bd87922d3d7a3aeea9749f8b01409e17ae2f516e33ad959593c07764b.

Cross fingers https://github.com/sctg-development/sctgdesk-server/actions/runs/11366891675/job/31618301236

aeltorio commented 2 weeks ago

@cocoon ,

Good news! The docker buildx method succeeded.

The Docker images are now available for the following platforms: linux/amd64, linux/arm, and linux/armhf. The multi-architecture image is tagged as latest or 1.1.99-46-armhf. You can pull it using:

docker pull sctg/sctgdesk-server:1.1.99-46-armhf

The ARM 32-bit binaries have been successfully extracted and are available in the GitHub pre-release named 1.1.99-46-armhf.

Although this method is slow on GitHub workers (taking around 5h15), I have decided to stop researching cross-compilation for now. If you manage to improve this process, please feel free to submit a PR.

Best,
Ronan

cocoon commented 2 weeks ago

Yay, congratulations, it at least succeded! 🚀 (5h 15m 13s 😆)

But, it doesn't want to run on my device.

Tried these: https://github.com/sctg-development/sctgdesk-server/releases/download/1.1.99-46-armhf/linux-ubuntu-22.04_1.1.99-46-armhf_armhf.zip https://github.com/sctg-development/sctgdesk-server/releases/download/1.1.99-46-armhf/rustdesk-server-hbbr_1.1.99-46-armhf_armhf.deb https://github.com/sctg-development/sctgdesk-server/releases/download/1.1.99-46-armhf/rustdesk-server-hbbs_1.1.99-46-armhf_armhf.deb

In my case I am running it on an OpenWRT ASUS Router AX88U. The official ones are working. So I thought it might not a big problem.

This is what I can see: hbbs = your build _hbbs = official 1.1.2

./hbbs
-sh: ./hbbs: not found
strace ./hbbs
execve("./hbbs", ["./hbbs"], 0x7ffcc71740 /* 19 vars */) = -1 ENOENT (No such file or directory)
strace: exec: No such file or directory
+++ exited with 1 +++
strace ./hbbr
execve("./hbbr", ["./hbbr"], 0x7fe4532410 /* 19 vars */) = -1 ENOENT (No such file or directory)
strace: exec: No such file or directory
+++ exited with 1 +++

strace for offical one:

strace ./_hbbs
execve("./_hbbs", ["./_hbbs"], 0x7ff14d3140 /* 19 vars */ <unfinished ...>
[ Process PID=963 runs in 32 bit mode. ]
strace: WARNING: Proper structure decoding for this personality is not supported, please consider building strace with mpers support enabled.
<... execve resumed>)                   = 0
mmap2(NULL, 472, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xf71b1000
set_tls(0xf71b1078)                     = 0
set_tid_address(0x4e22a8)               = 963
...
file hbbr
file: Compiled magic version [544] does not match with shared library magic version [540]

file: could not find any valid magic files! (No such file or directory)
file hbbs
file: Compiled magic version [544] does not match with shared library magic version [540]

file: could not find any valid magic files! (No such file or directory)

But it is the same for the working offical one:

 file _hbbs
file: Compiled magic version [544] does not match with shared library magic version [540]

file: could not find any valid magic files! (No such file or directory)

https://github.com/RMerl/asuswrt-merlin.ng/wiki/Compile-Firmware-from-source

cocoon commented 2 weeks ago

Thank you very much for trying, I will see if I can get it running somehow.

aeltorio commented 2 weeks ago

Wow, running hbbs+hhbr on a router is quite a challenge!

I’m not very familiar with OpenWrt, but I tested it on a Raspberry Pi with an ARMv7 processor and (I believe) a Debian distribution, and it worked.

file hbbs
file: Compiled magic version  does not match with shared library magic version 
file: could not find any valid magic files! (No such file or directory)

This indicates that the binary format is correct (so it’s the right 32-bit processor), but it’s not linked with the same shared library. Debian Bookworm and Ubuntu Jammy use GLIBC 2.35.

I have some OpenWrt APs and I checked that OpenWrt 23 is linked to musl version 1.2.4. You might need to modify the Docker buildx process to link against musl.

Alternatively, you could try linking against static musl by adding the musl-dev apt package and using the armv7-unknown-linux-musleabihf cargo target.

cocoon commented 2 weeks ago

I have some OpenWrt APs and I checked that OpenWrt 23 is linked to musl version 1.2.4. You might need to modify the Docker buildx process to link against musl.

Alternatively, you could try linking against static musl by adding the musl-dev apt package and using the armv7-unknown-linux-musleabihf cargo target.

Yes something like that, thanks for the hints!

Wow, running hbbs+hhbr on a router is quite a challenge!

Yes, I already max it out with many different stuff, I experimented what I can get running on it without problems.

I have my custom rust processes running on it for some home automation with custom alexa skill, including adb calls to different devices like TVs etc, nanomqtt, working rock solid. First I had been using python, but that was too heavy, that is where I started to port it to rust as a poc and it was just working too great, especially as the build target for these things just worked from Windows (was using Linaro gcc sometimes).

I even had mysql dbs running on it with heavy tuning of the config, but had to manually enable swapping for it onto usb device. I removed that for now. It was working but ...

aeltorio commented 2 weeks ago

Does Docker run on OpenWRT? Apart from storage, it has a low CPU overhead. With Docker Compose, it’s very easy to run my server, and it will work since the architecture is compatible.

cocoon commented 2 weeks ago

Does Docker run on OpenWRT?

To be honest, I never thought about it and so have not tried, but I would guess no ... I will check ...

aeltorio commented 2 weeks ago

I'm trying a static build with musl:
https://github.com/sctg-development/sctgdesk-server/blob/armhf/Dockerfile-integration

cocoon commented 2 weeks ago

So docker seems to be a no. no entware packages and just others asking for it with no repsonse.

I'm trying a static build with musl

Wonderful, thanks! Will test!

aeltorio commented 2 weeks ago

@cocoon Please try https://github.com/sctg-development/sctgdesk-server/releases/tag/1.1.99-46-musl It was compiled using musl and it shoud be static.
On my Raspberry pi armh it is reported as not a dynamic executable so I'm confident… Ronan

cocoon commented 2 weeks ago

1000% thanks, the new musl builds work like a charm. You were much quicker, I started to install a new fresh Ubuntu VM with docker. Will be nice to have if I need to compile something special like this again 👍