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

[PKG REQUEST] SimpleX Chat CLI for x86_64 #34

Open
AlbydST opened this issue Sep 18, 2024 · 11 comments
Open

[PKG REQUEST] SimpleX Chat CLI for x86_64 #34

AlbydST opened this issue Sep 18, 2024 · 11 comments

Comments

@AlbydST
Copy link

AlbydST commented Sep 18, 2024

Repository

https://github.com/simplex-chat/simplex-chat

Description

The first messaging network operating without user identifiers of any kind (See also the CLI version).

Binary Releases?

Yes, available here.

Needs to be compiled?

Yes, releases are dynamic.

Compilation Instructions:

Can be compiled statically as seen here.

Analysis of official binary:

# file simplex-chat-ubuntu-22_04-x86-64
simplex-chat-ubuntu-22_04-x86-64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=9a8b87e6860fd260c2612e14bc71b2e09a20, not stripped
# ldd simplex-chat-ubuntu-22_04-x86-64`:
        /lib64/ld-linux-x86-64.so.2 (0x7f8a3869f000)
	libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f8a3869f000)
	libz.so.1 => /lib/libz.so.1 (0x7f8a38689000)
	libcrypto.so.3 => /lib/libcrypto.so.3 (0x7f8a38200000)
	libgmp.so.10 => /lib/libgmp.so.10 (0x7f8a385f9000)
	libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f8a3869f000)

(Tested with versions v6.0.4 and v6.1.0-beta.0)

@Azathothas
Copy link
Owner

Azathothas commented Sep 19, 2024

Unfortunately, that Dockerfile you linked doesn't build for me.
It errors out, complaining about missing dependencies. Maybe it worked when the PR was originally made, but between then and now, the code has changed significantly that it now doesn't work on the latest version of simplex chat.
Perhaps the original author @shumvgolove can help us here.

I have also requested this pkg over at @leleliu008 's leleliu008/ppkg-formula-repository-official-core#6

I am hopeful that there's a way we can compile it statically, however if not, I will probably consider using staticx on it.

Edit:
Here's a staticx binary: https://pub.ajam.dev/temp/simplex-chat

🌀 ❯ sha256sum simplex-chat
f66eb32be56a08cb83ddac3c5224110f7a73ee2af4503153816575ef52b30a13  simplex-chat

do let me know if this works as expected

@AlbydST
Copy link
Author

AlbydST commented Sep 19, 2024

This is quite strange, as it appears to build just fine for me. Can you confirm that this fails aswell? If yes, what's the error?

git clone --depth 1 https://github.com/simplex-chat/simplex-chat.git simplex-chat
cd simplex-chat
rm -fv Dockerfile
wget https://raw.githubusercontent.com/simplex-chat/simplex-chat/2abee7edf8cd1c975c9336aa7885f6f818b88d7e/Dockerfile
DOCKER_BUILDKIT=1 docker build .

@Azathothas
Copy link
Owner

I didn't use the Dockerfile directly, I copied the steps so it would be reproducible for both aarch64 & x86_64 and wouldn't rely on an external source.
The script currently (It's broken) is here: https://github.com/Azathothas/Toolpacks/blob/main/.github/scripts/x86_64_Linux/bins/simplex-chat.sh
Perhaps I missed some steps or made some silly mistakes. It might have also been that I added some extra ccflags/ldflags.
If you can fix that script, It would be much appreciated.
Preferably, it would also be much nicer if we don't have to stick to a hardcoded version of ghc/cabal (So I wouldn't have to increase version manually)

Running docker build using the docker file directly:

#/tmp/toolpacks/Uwa4SFh_linux_x86_64 is an empty dir
/tmp/toolpacks/Uwa4SFh_linux_x86_64$ git clone --depth 1 https://github.com/simplex-chat/simplex-chat.git simplex-chat
cd simplex-chat
rm -fv Dockerfile
wget https://raw.githubusercontent.com/simplex-chat/simplex-chat/2abee7edf8cd1c975c9336aa7885f6f818b88d7e/Dockerfile
DOCKER_BUILDKIT=1 docker build .
Cloning into 'simplex-chat'...
remote: Enumerating objects: 2647, done.
remote: Counting objects: 100% (2647/2647), done.
remote: Compressing objects: 100% (2270/2270), done.
remote: Total 2647 (delta 285), reused 1551 (delta 194), pack-reused 0 (from 0)
Receiving objects: 100% (2647/2647), 91.13 MiB | 24.66 MiB/s, done.
Resolving deltas: 100% (285/285), done.
removed 'Dockerfile'
--2024-09-20 04:21:32--  https://raw.githubusercontent.com/simplex-chat/simplex-chat/2abee7edf8cd1c975c9336aa7885f6f818b88d7e/Dockerfile
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.110.133, 185.199.111.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1720 (1.7K) [text/plain]
Saving to: 'Dockerfile'

Dockerfile                        100%[===========================================================>]   1.68K  --.-KB/s    in 0s

2024-09-20 04:21:32 (25.9 MB/s) - 'Dockerfile' saved [1720/1720]

[+] Building 521.9s (16/18)                                                                                            docker:default
 => [internal] load build definition from Dockerfile                                                                             0.0s
 => => transferring dockerfile: 1.76kB                                                                                           0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                 0.0s
 => [internal] load .dockerignore                                                                                                0.0s
 => => transferring context: 2B                                                                                                  0.0s
 => [build-stage  1/13] FROM docker.io/library/alpine:latest                                                                     0.0s
 => [internal] load build context                                                                                                1.6s
 => => transferring context: 227.75MB                                                                                            1.5s
 => [build-stage  2/13] RUN apk add --no-cache     curl     git     xz     grep     ghc-dev     gmp-dev     zlib-static     zl  25.8s
 => [build-stage  3/13] RUN curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERAC  122.7s
 => [build-stage  4/13] RUN ghcup set ghc "9.6.3" &&     ghcup set cabal "3.10.1.0"                                              0.5s
 => [build-stage  5/13] RUN cabal install --install-method=copy --installdir=/usr/local/bin hpack-0.36.0                       340.0s
 => [build-stage  6/13] COPY . /project                                                                                          2.2s
 => [build-stage  7/13] WORKDIR /project                                                                                         0.0s
 => [build-stage  8/13] RUN cp ./scripts/cabal.project.local.linux ./cabal.project.local                                         0.2s
 => [build-stage  9/13] RUN sed -i '/- -Wunused-type-patterns/a\  - -O2\n\  - -split-sections\n\  - -with-rtsopts=-N\n\  - -sta  0.3s
 => [build-stage 10/13] RUN hpack                                                                                                0.4s
 => [build-stage 11/13] RUN cabal update                                                                                        25.4s
 => ERROR [build-stage 12/13] RUN cabal build -j exe:simplex-chat                                                                4.4s
------
 > [build-stage 12/13] RUN cabal build -j exe:simplex-chat:
1.258 HEAD is now at aab7b5a support tagging objects with single field
2.256 HEAD is now at 9aa09f1 allow base versions < 4.19
4.033 Cleared directory 'sqlcipher'
4.040 Submodule 'sqlcipher' (https://github.com/sqlcipher/sqlcipher.git) unregistered for path 'sqlcipher'
4.231 HEAD is now at f814ee6 update .gitmodules
4.308 Submodule 'sqlcipher' (https://github.com/sqlcipher/sqlcipher.git) registered for path 'sqlcipher'
4.314 Cloning into '/project/dist-newstyle/src/direct-sq_-1924b92d6e0c4e68/sqlcipher'...
4.314 fatal: could not open '/project/dist-newstyle/src/direct-sq_-1924b92d6e0c4e68/sqlcipher/.git' for writing: File exists
4.315 fatal: clone of 'https://github.com/sqlcipher/sqlcipher.git' into submodule path '/project/dist-newstyle/src/direct-sq_-1924b92d6e0c4e68/sqlcipher' failed
4.315 Failed to clone 'sqlcipher'. Retry scheduled
4.315 BUG: submodule considered for cloning, doesn't need cloning any more?
4.316 fatal: could not get a repository handle for submodule 'sqlcipher'
------
Dockerfile:51
--------------------
  49 |     # Compile simplex-chat
  50 |     RUN cabal update
  51 | >>> RUN cabal build -j exe:simplex-chat
  52 |
  53 |     # Strip the binary from debug symbols to reduce size
--------------------
ERROR: failed to solve: process "/bin/sh -c cabal build -j exe:simplex-chat" did not complete successfully: exit code: 128



@leleliu008
Copy link

I can successfully build it. see this : https://github.com/leleliu008/test/actions/runs/10961122341/job/30437305432

but not a fully statically linked executable.

It should create fully statically linked executables, but cabal has many bugs, I have not found a workaround.

@leleliu008
Copy link

simplex-chat/simplex-chat#3942 this PR actually not produce a fully statically linked execvutable, it's actually dynamically linked.

@shumvgolove
Copy link

shumvgolove commented Sep 20, 2024

Hello there!

Thanks for pinging me, I've actually forgot that I've created this PR :^)

Maybe it worked when the PR was originally made, but between then and now, the code has changed significantly that it now doesn't work on the latest version of simplex chat.

To my surprise, it works to this day just fine:

❯ git clone https://github.com/simplex-chat/simplex-chat
Cloning into 'simplex-chat'...
remote: Enumerating objects: 95223, done.
remote: Counting objects: 100% (3075/3075), done.
remote: Compressing objects: 100% (1417/1417), done.
remote: Total 95223 (delta 1779), reused 2454 (delta 1282), pack-reused 92148 (from 1)
Receiving objects: 100% (95223/95223), 238.81 MiB | 26.18 MiB/s, done.
Resolving deltas: 100% (60007/60007), done.
❯ cd simplex-chat
apps  docs      images    scripts  tests    cabal.project  flake.lock  fourmolu.yaml  libsimplex.dll.def  package.yaml  README.md
blog  fastlane  packages  src      website  Dockerfile     flake.nix   install.sh     LICENSE             PRIVACY.md    simplex-chat.cabal
❯ git checkout master
branch 'master' set up to track 'origin/master'.
Switched to a new branch 'master'
❯ curl -LO 'https://raw.githubusercontent.com/simplex-chat/simplex-chat/2abee7edf8cd1c975c9336aa7885f6f818b88d7e/Dockerfile'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1720  100  1720    0     0   4249      0 --:--:-- --:--:-- --:--:--  4246
❯ DOCKER_BUILDKIT=1 docker build --output . .
[+] Building 1212.2s (19/19) FINISHED                                                                                              docker:default
 => [internal] load build definition from Dockerfile                                                                                         0.0s
 => => transferring dockerfile: 1.76kB                                                                                                       0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                             0.0s
 => [internal] load .dockerignore                                                                                                            0.0s
 => => transferring context: 2B                                                                                                              0.0s
 => CACHED [build-stage  1/13] FROM docker.io/library/alpine:latest                                                                          0.0s
 => [internal] load build context                                                                                                            0.8s
 => => transferring context: 400.25MB                                                                                                        0.8s
 => [build-stage  2/13] RUN apk add --no-cache     curl     git     xz     grep     ghc-dev     gmp-dev     zlib-static     zlib-dev     o  20.1s
 => [build-stage  3/13] RUN curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 sh      61.6s 
 => [build-stage  4/13] RUN ghcup set ghc "9.6.3" &&     ghcup set cabal "3.10.1.0"                                                          0.3s 
 => [build-stage  5/13] RUN cabal install --install-method=copy --installdir=/usr/local/bin hpack-0.36.0                                   278.8s 
 => [build-stage  6/13] COPY . /project                                                                                                      0.6s 
 => [build-stage  7/13] WORKDIR /project                                                                                                     0.0s 
 => [build-stage  8/13] RUN cp ./scripts/cabal.project.local.linux ./cabal.project.local                                                     0.1s 
 => [build-stage  9/13] RUN sed -i /- -Wunused-type-patterns/a\  - -O2\n\  - -split-sections\n\  - -with-rtsopts=-N\n\  - -static\n\cc-opt  0.1s 
 => [build-stage 10/13] RUN hpack                                                                                                            0.2s 
 => [build-stage 11/13] RUN cabal update                                                                                                    23.2s 
 => [build-stage 12/13] RUN cabal build -j exe:simplex-chat                                                                                826.3s
 => [build-stage 13/13] RUN bin=$(find /project/dist-newstyle -name "simplex-chat" -type f -executable) &&     mv "$bin" ./ &&     strip ./  0.5s 
 => [export-stage 1/1] COPY --from=build-stage /project/simplex-chat /                                                                       0.1s 
 => exporting to image                                                                                                                       0.1s 
 => => exporting layers                                                                                                                      0.1s 
 => => writing image sha256:72a0aa4d9ab5dd2d330d4fe9a84147af519a11749104dbab8fb0fd802c4b2344                                                 0.0s
 => exporting to client directory                                                                                                            0.1s
 => => copying files 82.47MB                                                                                                                 0.1s

Not sure what's the issue you're getting

simplex-chat/simplex-chat#3942 this PR actually not produce a fully statically linked execvutable, it's actually dynamically linked.

Nope, it does produce the static executable (at least on x86_64).

Running from Alpine Linux:

❯ ldd simplex-chat
/lib/ld-musl-x86_64.so.1: simplex-chat: Not a valid dynamic program
❯ ./simplex-chat -v
SimpleX Chat v6.1.0.3
To update run: curl -o- https://raw.githubusercontent.com/simplex-chat/simplex-chat/master/install.sh | bash

Running from Arch Linux:

[sh ~]$ ldd ./simplex-chat
	not a dynamic executable
[sh ~]$ ./simplex-chat -v
SimpleX Chat v6.1.0.3
To update run: curl -o- https://raw.githubusercontent.com/simplex-chat/simplex-chat/master/install.sh | bash

@leleliu008
Copy link

leleliu008 commented Sep 20, 2024

many options specified via cabal v2-install do not work, but options specified via simplex-chat.cabal works.

This works now: https://github.com/leleliu008/test/actions/runs/10963768364/job/30445930259

@Azathothas
Copy link
Owner

Thank you, @leleliu008, for figuring it out. Any ETA when the formula/simplex-chat.yml be updated with these changes so it builds?
I could repurpose workflow you linked but it again has hard-coded versions, along with patching the package.yaml file to get it to build.

@AlbydST
I am against this approach because it's very likely (& as confirmed in my tests), it will eventually stop working, and I don't have the time to come up with these patches.

@shumvgolove
I have tried to reproduce your docker file on Debian, Ubuntu and alpine (The three major build environment, this repo uses), all of them fail. Perhaps it's something on my end, as you say it still works and the workflow by @leleliu008 is also almost the same.
Along with your PR: simplex-chat/simplex-chat#3942 Mar 22, 2024
There's also already issues asking for the same thing at:

All of these are unresolved, so I had rather wait for the official maintainers themselves to say (preferably do) something about it.

So for now, I think the best compromise is to just add the staticx version, which is pulled straight from official releases simplex-chat-ubuntu-22_04-x86-64 and repacked as a staticx archive.
I had already linked and asked if it worked to @AlbydST, but received no answers.

Here's a staticx binary: https://pub.ajam.dev/temp/simplex-chat

🌀 ❯ sha256sum simplex-chat
f66eb32be56a08cb83ddac3c5224110f7a73ee2af4503153816575ef52b30a13  simplex-chat

do let me know if this works as expected

If you would like to reproduce that, here's how:

!#This is copy-pasted from a build-recipe, So please remove sections not relevant to your setup.
#Build (debian-glibc)
pushd "$($TMPDIRS)" >/dev/null 2>&1
 docker stop "debian-builder-unstable" 2>/dev/null ; docker rm "debian-builder-unstable" 2>/dev/null
 docker run --privileged --net="host" --name "debian-builder-unstable" "azathothas/debian-builder-unstable:latest" \
  bash -l -c '
  #Setup ENV
   mkdir -p "/build-bins" && pushd "$(mktemp -d)" >/dev/null 2>&1
   sudo apt-get update -y -qq
   sudo apt-get install -y -qq libpcre3 libgmp3-dev xdg-utils zlib1g-dev
   sudo apt-get update -y -qq
  #Fetch
   eget "https://github.com/simplex-chat/simplex-chat" --asset "chat" --asset "ubuntu-22_04" --asset "x86_64" --asset "^desktop" --asset "^deb" --to "./simplex-chat"
   staticx --loglevel DEBUG "./simplex-chat" --strip "/build-bins/simplex-chat"
  #strip & info 
   objcopy --remove-section=".comment" --remove-section=".note.*" "/build-bins/simplex-chat"
   strip --strip-debug --strip-dwo --strip-unneeded -R ".comment" -R ".gnu.version" "/build-bins/simplex-chat"
   file "/build-bins/simplex-chat" && du -sh "/build-bins/simplex-chat"
   popd >/dev/null 2>&1
  '
#Copy & Meta
 docker cp "debian-builder-unstable:/build-bins/." "$(pwd)/"
 find "." -maxdepth 1 -type f -exec file -i "{}" \; | grep "application/.*executable" | cut -d":" -f1 | xargs realpath
 #Meta
 find "." -maxdepth 1 -type f -exec sh -c 'file "{}"; du -sh "{}"' \;
 sudo rsync -av --copy-links --exclude="*/" "./." "$BINDIR"
#Delete Containers
 docker stop "debian-builder-unstable" 2>/dev/null ; docker rm "debian-builder-unstable"
 popd >/dev/null 2>&1  
  

The tldr is, I would need a script that can build simplex-chat cli reliably, without too many patches and that's guaranteed not to break with updates.
If that's not possible, then staticx or even dockerc variant is what I think should be added.

@leleliu008
Copy link

sed -i '/- -Wunused-type-patterns/a\ - -O2\n\ - -split-sections\n\ - -with-rtsopts=-N\n\ - -static\n\cc-options: -static\n\ld-options: -static -pthread' package.yaml

this line is the most important patch, it modify the package.yaml, then use hpack command regenerate simplex-chat.cabal, cabal reads simplex-chat.cabal then pass options to ghc. Theoretically, these options should be supplied via cabal v2-install command , Actually, it does not work. I did not try other command like cabal build cabal install

@leleliu008
Copy link

https://github.com/leleliu008/ppkg-package-manually-build/actions/runs/10973554214

@xplshn
Copy link
Contributor

xplshn commented Nov 8, 2024

Wow @leleliu008, you always deliver :)
Keep up the good work <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants