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

Build SkiaSharp for Linux Arm #633

Closed
nicolasr75 opened this issue Sep 9, 2018 · 11 comments
Closed

Build SkiaSharp for Linux Arm #633

nicolasr75 opened this issue Sep 9, 2018 · 11 comments
Projects

Comments

@nicolasr75
Copy link

Description

I try to build SkiaSharp for Linux Arm. I followed the Wiki here
https://github.com/mono/SkiaSharp/wiki/Building-on-Linux
I used the xamarin-mobile-bindings branch and followed the steps in the Wiki.
To create the build files I used

./bin/gn gen 'out/linux/x64' --args='
    is_official_build=true skia_enable_tools=false
    target_os="linux" target_cpu="arm"
    skia_use_icu=false skia_use_sfntly=false skia_use_piex=true
    skia_use_system_expat=false skia_use_system_freetype2=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false
    skia_enable_gpu=true
    extra_cflags=[ "-DSKIA_C_DLL" ]
    linux_soname_version="60.3.0"'

which is the command line from the Wiki but I replaced the target_cpu with arm.

Expected Behavior

Build the .so file without any error.

Actual Behavior

c++: error: unrecognized command line option ‘-mfpu=neon’
c++: error: unrecognized command line option ‘-mthumb’

At that point I am not Linux expert enough to know how to resolve it. The command line shown above does not specify these arguments so they must have been auto generated. Any idea?

Basic Information

  • Linux: Ubuntu 14.04
@mattleibow
Copy link
Contributor

Ah, this might be taht your GCC is not the correct version... The xamarin-mobile-bindings branch requires at least 4.8 I believe. I do know the new branch comming soon will require 5.x.

What version of GCC are you using?

@mattleibow mattleibow added this to New in Triage via automation Sep 9, 2018
@nicolasr75
Copy link
Author

nicolasr75 commented Sep 9, 2018

Thanks for the quick response!

gcc (Ubuntu 4.8.5-2ubuntu1~14.04.1) 4.8.5

I guess I don't need the newest SkiaSharp version though. I just need a 1.60.* version because my AvaloniaUI application doesn't work anymore after I updated Avalonia to the newest version. I guess their code depends on 1.60.*. I tried to build 1.60.1 as described in the Wiki but the branch isn't found anymore. Any idea?

@nicolasr75
Copy link
Author

I get a similar error on Debian with

gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516

Maybe there is a misunderstanding on my side. I was under the impression that I could cross-compile SkiaSharp on an x64 system but probably that is not possible with the default gcc. Actually my first attempt was to compile it directly on my target ARM device (RPI) but there I get

./gn: cannot execute binary file: Exec format error

@mattleibow
Copy link
Contributor

Ah. I think I see what is happening, you must cross-compile, but you can't just use gcc raw - you need the cross-compiler.

To do this, you need to specify the other flags - see the Customizing section of the wiki. You will have to add the cc, cxx, and ar options to the list - each pointing to their respective tool.

See also: https://stackoverflow.com/questions/32359110/gcc-keeps-saying-mfpu-neon-is-an-unrecognoized-command

@nicolasr75
Copy link
Author

Ok, sorry to bother you again. I found this https://github.com/raspberrypi/tools
Added the bin directory to the path, set cc, cxx and ar as you wrote.

It compiled a few files and stopped with fontconfig.h could not be found.
So I took my RPI and installed fontconfig via
sudo apt install libfontconfig-dev
Copied over the files to the RPI tools directory on my Debian and tried again.
After a few more files I get:

In file included from ../../../src/sksl/lex.layout.cpp:9:0:
lex.layout.c:1423:17: error: 'void yyunput(int, char*, yyscan_t)' defined but not used [-Werror=unused-function]
cc1plus: error: unrecognized command line option "-Wno-implicit-fallthrough" [-Werror]
cc1plus: all warnings being treated as errors
[316/972] compile ../../../src/sksl/SkSLSPIRVCodeGenerator.cpp
ninja: build stopped: subcommand failed.

The compiler in the tools says
arm-linux-gnueabihf-g++ (crosstool-NG crosstool-ng-1.22.0-88-g8460611) 4.9.3

As I understand it, these are warnings that are treated as errors due to the -Werror flag. Couldn't I simply turn this off? I have no idea where though, the args.gn file does not contain the flag.

@mattleibow
Copy link
Contributor

mattleibow commented Sep 11, 2018

Ah,we appear to be moving! This is the exact same issue, but for newer warnings. https://groups.google.com/forum/m/#!topic/skia-discuss/WybRL5GoVHI

Basically, add extra_cflags = [ "-w" ] to the args to allow all warnings.

In the next release, warnings are ignored for release builds by default, so this will soon not be needed.

@nicolasr75
Copy link
Author

Thanks, that did the trick. After adding the missing libfontconfig.so, it finally built completely.

I had hoped it would have been easier though. For Linux experts all the problems I faced (cross compilation, compiler version, missing packages, compiler and linker errors) may seem trivial but interestingly enough nobody on the web gives a clear description. I am just wondering because I think there could be done so many great things with .NET Core and this library (optionally via Avalonia UI) especially on ARM devices. It would really be helpful to have a subsection in the Wiki that goes a little into the details about building it for ARM.

There seem to be quite a few people that want to get interesting projects done on a Raspberry Pi but I could imagine that many of them fail to build the library and use other tools.

I could maybe set up a Github project for it myself but as I see it, a better place would be the Wiki. I know the Raspberry is just one platform, but wouldn't it be better nevertheless to have a working description for this one platform?

Thanks again for your time and keep up the good work!

Triage automation moved this from New to Complete / Invalid Sep 11, 2018
@LordBenjamin
Copy link

LordBenjamin commented Dec 29, 2018

Adding a step-by-step summary since it's taken me quite a while to work through this:

# check out skia and depot_tools as per https://github.com/mono/SkiaSharp/wiki/Building-on-Linux
git clone git clone https://github.com/mono/skia.git -b v1.68.0-preview28
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

# check out RPI compilers as per https://github.com/mono/SkiaSharp/issues/633#issuecomment-420025558 and add to path
git clone https://github.com/raspberrypi/tools.git
export PATH="$PATH:<path-to-rpi-checkout>/tools/arm-bcm2708/arm-linux-gnueabihf/bin"

# installed libfontconfig on my RPI and then copied
# fcfreetype.h,  fcprivate.h and  fontconfig.h
# to
# <path-to-rpi-checkout>/tools/arm-bcm2708/arm-linux-gnueabihf/arm-linux-gnueabihf/include/fontconfig

# copied
# libfontconfig.a  libfontconfig.so  libfontconfig.so.1  libfontconfig.so.1.8.0
# to
# <path-to-rpi-checkout>/tools/arm-bcm2708/arm-linux-gnueabihf/arm-linux-gnueabihf/lib

# would it be possible to avoid the copy steps by installing libfontconfig:armhf directly on the build machine? I tried but couldn't get it to install

# change to skia directory - all work done here from now on
cd skia

# run git-sync-deps script (as per normal instructions)
python tools/git-sync-deps

# modified command line to use ARM cross-compilers from the RPI tools
./bin/gn gen 'out/linux/x64' --args='
    cc = "arm-linux-gnueabihf-gcc"
    cxx = "arm-linux-gnueabihf-g++"
    is_official_build=true skia_enable_tools=false
    target_os="linux" target_cpu="arm"
    skia_use_icu=false skia_use_sfntly=false skia_use_piex=true
    skia_use_system_expat=false skia_use_system_freetype2=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false
    skia_enable_gpu=true
    extra_cflags=[ "-DSKIA_C_DLL" ]
    linux_soname_version="68.0.0"'

# compile
../depot_tools/ninja 'SkiaSharp' -C 'out/linux/x64'

@mattleibow
Copy link
Contributor

@LordBenjamin Thanks for this work! I will try and get this into a real cake target or as a separate script soon. Just an FYI, I copied your comment to #453 (comment) so that we can track all new linux platforms there.

@LordBenjamin
Copy link

@mattleibow Glad it's useful! Hopefully having this scripted will make it a lot more accessible to others.

@xiangzhai
Copy link

:mips-interest

@mono mono locked as resolved and limited conversation to collaborators Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
Triage
  
Done
Development

No branches or pull requests

4 participants