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

android arm64 support #513

Open
Lundis opened this issue Mar 27, 2022 · 15 comments
Open

android arm64 support #513

Lundis opened this issue Mar 27, 2022 · 15 comments

Comments

@Lundis
Copy link
Contributor

Lundis commented Mar 27, 2022

It seems that android arm64 (AKA aarch64 / arm64-v8a) is the standard now (meaning you cant technically use this library for android). I suppose adding support for it is as "simple" as cd80a89

I would do it myself but I'm guessing you already have SDL cross-compiling set up (which does not exactly seem trivial according to SDL's docs). Seeing how I have no experience compiling C libraries I'm not sure I would figure it out in any reasonable timeframe. Anyhow if you are able to somewhat easily do this, I will do the testing of it for you, and also update the android example (which is really outdated).

If you don't have time for this, maybe you could point me in the right direction?

@Lundis
Copy link
Contributor Author

Lundis commented Mar 28, 2022

I just found https://github.com/veandco/sdl2-static-library-build-scripts

I can probably work with that.

@veeableful
Copy link
Contributor

Ahh sorry, I haven't managed to finalize the scripts. I will push what I have now tomorrow so it will be more up-to-date.

@Lundis
Copy link
Contributor Author

Lundis commented Mar 28, 2022

No worries. I'm thinking that library might be good for me to practise my github actions skills. If you would be interested in an automated solution? I have gained some experience with docker recently which I could put to use to have github produce the static libs.

I noticed that it's set up for the older android NDKs though, which I am not sure if supported arm64 (new ones use LLVM and is much easier to configure). In any case I can take care of updating that at the same time

@veeableful
Copy link
Contributor

That would be extremely helpful! I have met a couple stumbling blocks in building for android and darwin arm64 architecture so I greatly appreciate any help on those matters!

@Lundis
Copy link
Contributor Author

Lundis commented Mar 28, 2022

I started working on it: veandco/sdl2-static-library-build-scripts#1 Now it should be possible to build using that container. No time for that today though. I'll add some instructions also later on.

@veeableful
Copy link
Contributor

Thanks @Lundis! I have also pushed the current state of the repository which may have affected the list of packages installed in the Dockerfile.

@n-i-x
Copy link

n-i-x commented Sep 1, 2022

Hey there! Any progress on this? I was trying to build an SDL app for an aarch64 linux embedded system and getting an error:

# error "No ABI matched"

I'm assuming this is because there are no SDL libs for this platform. I'm happy to compile them myself if there are some instructions, but I haven't been able to find any.

@veeableful
Copy link
Contributor

Hi @n-i-x, you could try downloading the latest SDL2 library from GitHub at https://github.com/libsdl-org/SDL/releases

After extracting it, you could build it like this:

cd SDL2-2.24.0
mkdir build
cd build
../configure --prefix=$HOME/.local
make -j`nproc`
make install

and then make sure pkg-config can find it by setting the environment variable:

export PKG_CONFIG_PATH="$HOME/.local/lib/pkgconfig:$PKG_CONFIG_PATH" # perhaps put this in .profile or .bashrc
pkg-config --cflags sdl2 # to test if pkg-config can find it

After that, I believe you should be able to use the binding.

@n-i-x
Copy link

n-i-x commented Sep 4, 2022

I don't think that'll let me statically compile though will it? I have all the .a files from the device I'm targeting and tried adding them to the repo... but it couldn't find them. Not sure what I missed.

@n-i-x
Copy link

n-i-x commented Sep 4, 2022

FYI, I tried compiling SDL 2.0.7 (the version included in the embedded device) using your instructions and then building one of the examples and I get the following error:

$ GOOS=linux GOARCH=arm64 go build main.go
# command-line-arguments
./main.go:6:16: undefined: sdl.Init
./main.go:6:25: undefined: sdl.INIT_EVERYTHING
./main.go:9:12: undefined: sdl.Quit
./main.go:11:21: undefined: sdl.CreateWindow
./main.go:11:46: undefined: sdl.WINDOWPOS_UNDEFINED
./main.go:12:17: undefined: sdl.WINDOW_SHOWN
./main.go:24:14: undefined: sdl.Rect
./main.go:30:20: undefined: sdl.PollEvent

I've tried go mod tidy and go get -v github.com/veandco/go-sdl2/sdl and it sill gives me that error. If I don't try to cross-compile then it works fine.

@gen2brain
Copy link
Collaborator

@n-i-x That is because you need to explicitly enable cgo with CGO_ENABLED=1, Go will by default disable cgo when ever you try to cross-compile. It is a common error when one wants to cross-compile a cgo project just like that.

When you add CGO_ENABLED, the next error will probably be something that tells you that you must use the C compiler/toolchain for the target architecture, i.e. to set CC. Btw. you must also compile SDL with the same toolchain, not with your host CC.

@n-i-x
Copy link

n-i-x commented Sep 4, 2022

Okay I tried all of that except compiling sdl with the aarch64 gcc I’ll try that next and report back.

@n-i-x
Copy link

n-i-x commented Sep 4, 2022

$ export PKG_CONFIG_PATH="$HOME/.local/lib/pkgconfig:$PKG_CONFIG_PATH"
$ pkg-config --cflags sdl2
-D_REENTRANT -I/config/.local/include/SDL2

Then when trying to cross-compile I get the following:

$ CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc GOOS=linux GOARCH=arm64 go build -tags static -ldflags "-s -w"
<snip>
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: /tmp/go-link-1068906841/000042.o: in function `delHintCallback':
/config/go/pkg/mod/github.com/veandco/go-sdl2@v0.4.25/sdl/hints.c:18: undefined reference to `SDL_DelHintCallback'
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: /tmp/go-link-1068906841/000043.o: in function `LogSetOutputFunction':
/config/go/pkg/mod/github.com/veandco/go-sdl2@v0.4.25/sdl/log.c:5: undefined reference to `SDL_LogSetOutputFunction'
collect2: error: ld returned 1 exit status

Is there something I need to do to make sure cgo can see the the libs in ~/.local? I have PKG_CONFIG_PATH="$HOME/.local/lib/pkgconfig:$PKG_CONFIG_PATH" exported. I'm also trying to compile SDL 2.0.7 which is the SDL included in the embedded device I'm working with, would I need to use a more updated SDL? I would assume if I am statically compiling against those SDL libs the SDL version wouldn't matter, so I'll try that next.

@n-i-x
Copy link

n-i-x commented Sep 4, 2022

I also wonder if I just need to compile SDL -image,-mixer,-ttf,-gfx to get all the references needed by the bindings... I'll make my way through compiling those libs for aarch64 as well. I really appreciate you helping me through this.

@veeableful
Copy link
Contributor

veeableful commented Sep 6, 2022

Hi @n-i-x, the SDL2 build instructions written above are for dynamic compilation as we don't have static libraries for android arm64 yet. There shouldn't be a need to install the other SDL2 libraries such as SDL2_image if only sdl is imported.

All SDL2 versions should also work with the binding according to the Github Actions test but perhaps there's special case with android arm64. If so, could you let me know how to reproduce your environment?

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

4 participants