Skip to content

Instantly share code, notes, and snippets.

@terasakisatoshi
Created October 9, 2020 08:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save terasakisatoshi/8a95eb8b676a29ad3f5fe4a717ff3254 to your computer and use it in GitHub Desktop.
Save terasakisatoshi/8a95eb8b676a29ad3f5fe4a717ff3254 to your computer and use it in GitHub Desktop.
Script to Build Julia locally for RaspberryPi4
#! /bin/bash
# Usage:
# 1. Copy this file to your raspberry pi e.g. /home/pi
# 2. Run this file `bash build_locally.sh`
# 3. Tested on Raspberry Pi4 with 4 or 8 GB
sudo apt-get update && sudo apt-get install -y \
build-essential libatomic1 python gfortran perl wget m4 cmake pkg-config \
nghttp2 libmbedtls-dev \
git
JL_VERSION=master
JL_BUILD_DIR=build-julia-${JL_VERSION}
# get JL_COMMIT_HASH via `git rev-parse --short HEAD`
JL_COMMIT_HASH=8987f7ac6d
JL_BUILD_DIR=build-julia-${JL_VERSION}-${JL_COMMIT_HASH}
git clone https://github.com/JuliaLang/julia.git $JL_BUILD_DIR && \
cd ${JL_BUILD_DIR} && git checkout ${JL_COMMIT_HASH} && cd ..
cat > ${JL_BUILD_DIR}/Make.user << EOF
CXXFLAGS=-D_GLIBCXX_USE_CXX11_ABI=0
prefix=/home/pi/julia-${JL_VERSION}-${JL_COMMIT_HASH}
USE_BINARYBUILDER=0
LDFLAGS=-latomic
CFLAGS += "-mfpu=neon-vfpv4"
CXXFLAGS += "-mfpu=neon-vfpv4"
MARCH="armv7-a"
JULIA_CPU_TARGET="armv7-a\;armv7-a,neon\;armv7-a,neon,vfp4"
USE_SYSTEM_NGHTTP2=1
USE_SYSTEM_MBEDTLS=1
EOF
cd ${JL_BUILD_DIR} && make -j `nproc` && sudo make install && cd ..
@terasakisatoshi
Copy link
Author

image

@terasakisatoshi
Copy link
Author

#! /bin/bash

# Usage:
# 1. Copy this file to your raspberry pi e.g. /home/pi
# 2. Run this file `bash build_locally.sh`
# 3. Tested on Raspberry Pi4 with 4 or 8 GB

sudo apt-get update && sudo apt-get install -y \
    build-essential libatomic1 python gfortran perl wget m4 cmake pkg-config \
    nghttp2 libmbedtls-dev \
    git

JL_VERSION=master
JL_BUILD_DIR=build-julia-${JL_VERSION}
# get JL_COMMIT_HASH via `git rev-parse --short HEAD`
JL_COMMIT_HASH=28ff641fa9
JL_BUILD_DIR=build-julia-${JL_VERSION}-${JL_COMMIT_HASH}
git clone https://github.com/JuliaLang/julia.git $JL_BUILD_DIR && \
    cd ${JL_BUILD_DIR} && git checkout ${JL_COMMIT_HASH} && cd ..

cat > ${JL_BUILD_DIR}/Make.user << EOF
CXXFLAGS=-D_GLIBCXX_USE_CXX11_ABI=0
prefix=/home/pi/julia-${JL_VERSION}-${JL_COMMIT_HASH}
USE_BINARYBUILDER=0
LDFLAGS=-latomic
CFLAGS += "-mfpu=neon-vfpv4"
CXXFLAGS += "-mfpu=neon-vfpv4"
MARCH="armv7-a"
JULIA_CPU_TARGET="armv7-a\;armv7-a,neon\;armv7-a,neon,vfp4"
USE_SYSTEM_NGHTTP2=1
USE_SYSTEM_MBEDTLS=1
EOF

cd ${JL_BUILD_DIR} && make -j `nproc` && sudo make install && cd ..

image

@GregMc
Copy link

GregMc commented Apr 6, 2021

Could you just help a little bit more - I have built 1.6.0 onto my Raspberry Pi 4 ( it took about four hours ) and I now have a /home/pi/build-julia-master-28ff641fa9/usr/etc/julia directory on my Pi.

When I type Julia into the command line - I still get the old version ( 1.0.3 ) - So I am not sure how to get the newer version. I thought it might be a path problem - but searches haven't revealed any executables ( called 'Julia' ) lurking on the drive. So do I need to do more building after the four hour 'making' - or should I have had uninstalled version ( 1.0.3 ) first.

Any help would be most appreciated ...

thanks

@terasakisatoshi
Copy link
Author

terasakisatoshi commented Apr 6, 2021

Hello, GregMc

If you run my script correctly, you can find directory something like

“/home/pi/julia-${JL_VERSION}-${JL_COMMIT_HASH}”

You’ll find julia executable over there

@GregMc
Copy link

GregMc commented Apr 7, 2021

Seems to go through all the motions - and creates a Build-Julia-Master directory - but it doesn't then create the Julia directory after that. Doesn't seem to throw many errors ( and non significant ).

I have ordered a new SD card for the Raspberry Pi and will try a build fresh onto that - perhaps it is because I had an older version of Julia installed. So I tried again - having removed that - it still doesn't work ...

Thanks for your help Terasakisatoshi

@terasakisatoshi
Copy link
Author

@GregMc

Could you try tree julia-master-28ff641fa9/ -L 2 ? it should be get something like

$ tree julia-master-28ff641fa9/ -d -L 1
julia-master-28ff641fa9/
|-- bin
|   `-- julia
|-- etc
|   `-- julia
|-- include
|   `-- julia
|-- lib
|   |-- julia
|   |-- libjulialoader.so -> libjulialoader.so.1.6
|   |-- libjulialoader.so.1 -> libjulialoader.so.1.6
|   |-- libjulialoader.so.1.6
|   |-- libjulia.so -> libjulia.so.1.6
|   |-- libjulia.so.1 -> libjulia.so.1.6
|   `-- libjulia.so.1.6
|-- libexec
|   `-- 7z
`-- share
    |-- appdata
    |-- applications
    |-- doc
    |-- julia
    `-- man

14 directories, 8 files

especially

julia-master-28ff641fa9/
|-- bin
|   `-- julia #<----- this is what we want

@GregMc
Copy link

GregMc commented Apr 7, 2021

Thanks again Terasakisatoshi - I am sure I got that bin directory - first time round ( I will have tried running things from there ) - but now it isn't there - I definately need to start from a fresh install of RaspberryPi.

@terasakisatoshi
Copy link
Author

terasakisatoshi commented Apr 7, 2021

Good news. checkout sf/lbt_v303 branch JuliaLang/julia#40381
and prepare Make.user as follow:

MARCH="armv7-a"
LDFLAGS=-latomic
prefix=~/binary_0407

then just run make -j4.

Edit note that make install fails

@GregMc
Copy link

GregMc commented Apr 12, 2021

Hi Terasakisatoshi ,

Don't want to be a pain - but you seem to be very well placed to sort this out for me ( and for everybody who follows me ). I'm a big fan of JuliaLang and I would love to get it working on my Raspberry Pi. At the weekend some new SD Cards arrived in the post - so I rebuilt my Raspbian - and now typing "uname -a" returns "Linux raspberrypi 5.10.17-v7l+ #1403 SMP Mon Feb 22 11:33:35 GMT 2021 armv7l GNU/Linux" ( which, as you can see was only released in February ).
I left my make.user file as it was :-

CXXFLAGS=-D_GLIBCXX_USE_CXX11_ABI=0
prefix=/home/pi/julia-master-8987f7ac6d
USE_BINARYBUILDER=0
LDFLAGS=-latomic
CFLAGS += "-mfpu=neon-vfpv4"
CXXFLAGS += "-mfpu=neon-vfpv4"
MARCH="armv7-a"
JULIA_CPU_TARGET="armv7-a\;armv7-a,neon\;armv7-a,neon,vfp4"
USE_SYSTEM_NGHTTP2=1
USE_SYSTEM_MBEDTLS=1

and built the system - ( as the three lines in your previous comment were there ( although the prefix was different )) and two errors I got were :-

ln -sf /lib/arm-linux-gnueabihf/libmbedcrypto.so.3 /home/pi/build-julia-master-8987f7ac6d/usr/lib/julia/libmbedcrypto.so
ln -sf /lib/arm-linux-gnueabihf/libmbedx509.so.0 /home/pi/build-julia-master-8987f7ac6d/usr/lib/julia/libmbedx509.so
make[1]: *** [Makefile:207: /home/pi/build-julia-master-8987f7ac6d/usr/lib/julia/libnghttp2.so] Error 1
make: *** [Makefile:66: julia-base] Error 2

and tree :-

pi@raspberrypi:~/build-julia-master-8987f7ac6d $ tree  -d -L 1
.
|-- base
|-- cli
|-- contrib
|-- deps
|-- doc
|-- etc
|-- src
|-- stdlib
|-- test
|-- usr
`-- usr-staging

11 directories

which has the \bin directory missing.

Doing the "make -j4" produces :-
pi@raspberrypi:~/build-julia-master-8987f7ac6d $ make -j4

rm: cannot remove './': Directory not empty
rm: cannot remove './bin/': Directory not empty
rm: cannot remove './bin/7z': Permission denied
/usr/bin/tar: ./bin/7z: Cannot open: File exists
/usr/bin/tar: Exiting with failure status due to previous errors
make[1]: *** [/home/pi/build-julia-master-8987f7ac6d/deps/p7zip.mk:41: /home/pi/build-julia-master-8987f7ac6d/usr/manifest/p7zip] Error 2
make: *** [Makefile:60: julia-deps] Error 2

As you can see I am out of my depth with understanding the errors - I am not even sure what it is trying to do at what stage.

Any help would be greatly appreciated - It is a shame that you can't get the JuliaBerry guys #simonbyrne and #avik ( both of which have their email addresses on their JuliaBerry website ) - to include your code into their JuliaBerry - and then things could be combined.

As many words as you can - please - because following the information above is difficult - especially when you don't really know what the code is trying to acheive at any given time.

Many thanks

Greg, Liverpool UK

@terasakisatoshi
Copy link
Author

Hi Greg, thank you for your feedback!

I'm a big fan of JuliaLang and I would love to get it working on my Raspberry Pi
Good to know!!! I hope you can make it.

Maybe our script build_locally.sh is too old in 2021 😭 . BTW have you tried https://gist.github.com/terasakisatoshi/8a95eb8b676a29ad3f5fe4a717ff3254#gistcomment-3696889 ?

or build julia on current master ?

we do not have to set USE_BINARYBUILDER=0, which makes rpi4 build julia from scratch including its dependencies.

Here is what I did note that lines including # are comment

# try it on your Raspberry Pi
$ git clone https://github.com/JuliaLang/julia.git
$ cd julia
$ git checkout  d29126a43e
# `git rev-parse HEAD` should be
# d29126a43ee289fc5ab8fcb3dc0e03f514605950
# create `Make.user` as follows
MARCH=armv7-a
LDFLAGS=-latomic
# then, just do it
$ cat Make.user
MARCH=armv7-a
LDFLAGS=-latomic
$ julia -j4 
$ ./julia # good luck.

image

@terasakisatoshi
Copy link
Author

@GregMc, how is it going ?

@GregMc
Copy link

GregMc commented Apr 20, 2021

Hi Terasakisatoshi ,

You haven't heard from me - because I haven't managed to get a version of Julia later than 1.0.6 onto my RaspberryPi4. I have tried 'Make' and 'Build' and both get stuck at different stages. Basically I don't know enough about the process to make informed decisions. For example - Once a 'make' fails - do I need to delete the destination directory and re-run it with different settings - Or is there more screwed up elsewhere that once it has failed - only I new Raspbian Image will restore the situation. It is those sorts of questions that I am grabbling with at the moment.

Thanks for your help and interest.

cheers

Greg, Liverpool

@terasakisatoshi
Copy link
Author

Have you seen jlcross project ?

https://github.com/Julia-Embedded/jlcross

@GregMc
Copy link

GregMc commented Apr 22, 2021

Thanks Terasakisatoshi , I've had a look and it looks very interesting - I haven't yet had a chance to try any of the stuff.

Once a 'make' or a 'build' fails - where can I restart the process from - Am I having to reflash a SD Card every time, OR can I just delete the directories I can see - and try again. I think that's my biggest problem.

Cheers for your help

Greg, Liverpool

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