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

Added SCons compilation instructions #885

Merged
merged 10 commits into from
Oct 26, 2021

Conversation

Amaras
Copy link
Member

@Amaras Amaras commented Oct 18, 2021

Hey all!
As per #691, we now have a first draft of what the build system could look like.
It's definitely not good yet, and a few algorithms don't work yet, and only C instructions have been provided.

The problem I have is that I don't really know why it doesn't use the linking flags, but I did that without documentation access, so hey! I'm glad it works at all! 😅

So the plan will be to work on the C instructions, then maybe open an issue to let contributors add compilation instructions for Hacktober.

@Amaras
Copy link
Member Author

Amaras commented Oct 18, 2021

There we go, all targets (but one which can't be built) are operational if I'm not mistaken. I'll wait for confirmation that I did not miss anything before putting in to review, but it should be good to merge.
I'll probably have contributors provide SConscripts for already merged language implementations for Hacktober, if they want.

There is also a slight implementation problem, but I'll try to correct it before making it ready for review

@Amaras Amaras mentioned this pull request Oct 19, 2021
@Amaras
Copy link
Member Author

Amaras commented Oct 19, 2021

So, basically, at this point, I'm waiting for @leios to make a main function for the quantum systems C file, otherwise the compilation system for C is complete.

I could not fix the problem with my current structure, but it seems to be good enough for now.
We can always improve on it later.

As of now, I'm making this PR ready for review, since it's mostly ready.

To build everything, go to the root of the algorithm archive, and just run scons -iQ (to only show the build commands). All but one target will be built. To clean the file afterwards, run scons -c

@Amaras Amaras marked this pull request as ready for review October 19, 2021 19:50
@ShadowMitia
Copy link
Contributor

I'm checking the PR locally, running scons results in an error because I don't have fftw3 installed. Automating dependency installation would be nice, but I think a first level would be to warn that some dependencies are required? Maybe in the README?

@Amaras
Copy link
Member Author

Amaras commented Oct 19, 2021

I'm checking the PR locally, running scons results in an error because I don't have fftw3 installed. Automating dependency installation would be nice, but I think a first level would be to warn that some dependencies are required? Maybe in the README?

Yeah, this is not something I want to delve into. We probably should install it (the libfftw3-dev packet) inside the Docker container and run from there. In that case, it would not be a problem, I think

@@ -0,0 +1,2 @@
Import('*')
env.C('#/build/c/bransley/barnsley', 'barnsley.c')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in folder name

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this, it should not happen any more

contents/IFS/code/c/SConscript Outdated Show resolved Hide resolved
@ShadowMitia
Copy link
Contributor

I'm thinking that a lot of these files could be generated when scons is run. And only have a Sconscript when extra stuff are needed. This could even become a simpler file to make things easier for people contributing.

@ShadowMitia
Copy link
Contributor

ShadowMitia commented Oct 19, 2021

There is an issue with the compilation, I have all the depedencies, but I'm getting an error:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o contents/cooley_tukey/code/c/fft.o -c contents/cooley_tukey/code/c/fft.c
gcc -o build/c/cooley_tukey/cooley_tukey contents/cooley_tukey/code/c/fft.o -lm -lfftw3
gcc -o contents/euclidean_algorithm/code/c/euclidean_example.o -c contents/euclidean_algorithm/code/c/euclidean_example.c
contents/euclidean_algorithm/code/c/euclidean_example.c: In function 'euclid_mod':
contents/euclidean_algorithm/code/c/euclidean_example.c:5:9: warning: implicit declaration of function 'abs' [-Wimplicit-function-declaration]
5 | a = abs(a);
| ^~~
contents/euclidean_algorithm/code/c/euclidean_example.c:3:1: note: include '<stdlib.h>' or provide a declaration of 'abs'
2 | #include <math.h>
+++ |+#include <stdlib.h>
3 |
gcc -o build/c/euclidean_algorithm/euclidean_algorithm contents/euclidean_algorithm/code/c/euclidean_example.o -lm
gcc -o contents/flood_fill/code/c/flood_fill.o -c contents/flood_fill/code/c/flood_fill.c
gcc -o build/c/flood_fill/flood_fill contents/flood_fill/code/c/flood_fill.o
gcc -o contents/forward_euler_method/code/c/euler.o -c contents/forward_euler_method/code/c/euler.c
gcc -o build/c/forward_euler_method/forward_euler contents/forward_euler_method/code/c/euler.o -lm
gcc -o contents/gaussian_elimination/code/c/gaussian_elimination.o -c contents/gaussian_elimination/code/c/gaussian_elimination.c
gcc -o build/c/gaussian_elimination/gaussian_elimination contents/gaussian_elimination/code/c/gaussian_elimination.o
gcc -o contents/graham_scan/code/c/graham.o -c contents/graham_scan/code/c/graham.c
gcc -o build/c/graham_scan/graham_scan contents/graham_scan/code/c/graham.o -lm
gcc -o contents/huffman_encoding/code/c/huffman.o -c contents/huffman_encoding/code/c/huffman.c
gcc -o build/c/huffman_encoding/huffman contents/huffman_encoding/code/c/huffman.o
gcc -o contents/jarvis_march/code/c/jarvis_march.o -c contents/jarvis_march/code/c/jarvis_march.c
gcc -o build/c/jarvis_march/jarvis_march contents/jarvis_march/code/c/jarvis_march.o
gcc -o contents/monte_carlo_integration/code/c/monte_carlo.o -c contents/monte_carlo_integration/code/c/monte_carlo.c
gcc -o build/c/monte_carlo_integration/monte_carlo contents/monte_carlo_integration/code/c/monte_carlo.o
gcc -o contents/quantum_systems/code/c/energy.o -c contents/quantum_systems/code/c/energy.c
gcc -o build/c/quantum_systems/energy contents/quantum_systems/code/c/energy.o -lm -lfftw3
/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in function _start': (.text+0x1b): undefined reference to main'
collect2: error: ld returned 1 exit status
scons: *** [build/c/quantum_systems/energy] Error 1
scons: building terminated because of errors.

The error is what you reported about the missing main, and in itself is not an issue.
But the problem is that all subsequent compilations get "cancelled". In my case I don't have the verlet_integration (because everything is compiled in alphabetical order on folder name). And probably others, I'm not sure.

I think having a way to continue compilation instead of aborting would be preferable.

SConscript files are now mostly universal for C programs.
Additionally, the build hierarchy is now flattened (executables under the language folder)
@Amaras
Copy link
Member Author

Amaras commented Oct 19, 2021

In accordance with your review, this should now work as expected, without typos.
I also flattened the hierarchy to have executables directly under their language's folder.

Also not that you can build a single target by running scons <target>.
For example, if you want to build the Barnsley Fern executable, run scons build/c/barnsley (the target executable is derived from the folder's name).

I currently have this collection of executables:

amaras@amaras:~/algorithm-archive$ exa -1 build/c/
barnsley
computus
cooley_tukey
euclidean_algorithm
flood_fill
forward_euler_method
gaussian_elimination
graham_scan
huffman_encoding
IFS
jarvis_march
monte_carlo_integration
split-operator_method
stable_marriage_problem
thomas_algorithm
tree_traversal
verlet_integration

This list will change with the changing of folder names (if there are any), so it should be quite flexible.
Also note that all the temporary files (mainly the .o files on Linux) are located in their respective code folders; hopefully this is not a problem.

@leios leios added Hacktoberfest The label for all Hacktoberfest related things! hacktoberfest-accepted labels Oct 20, 2021
@Amaras Amaras closed this in #888 Oct 20, 2021
@Amaras Amaras reopened this Oct 20, 2021
@Amaras
Copy link
Member Author

Amaras commented Oct 20, 2021

Right, apparently this was closed because @leios decided to say that his PR solved an issue (as GH PRs are basically just issues) 😂
I opened it back, it should be good now.

@ntindle ntindle mentioned this pull request Oct 21, 2021
4 tasks
@ntindle
Copy link
Member

ntindle commented Oct 23, 2021

I can't modify the dockerfile in your branch (i think because it existed before I was added as a contributor) so you can swap the docker file to this

# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.187.0/containers/ubuntu/.devcontainer/base.Dockerfile

# [Choice] Ubuntu version: bionic, focal
ARG VARIANT="focal"
FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}

# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
    && apt-get -y install --no-install-recommends build-essential software-properties-common xz-utils g++ sbcl julia python3 python3-pip python3-dev ghc openjdk-11-jdk rustc libssl-dev gfortran libxml2-dev libyaml-dev libgmp-dev libz-dev libncurses5 gnuplot nodejs npm lua5.3 ocaml php ruby-full gnu-smalltalk scratch libfftw3-dev

# Setup Crystal
RUN echo 'deb http://download.opensuse.org/repositories/devel:/languages:/crystal/xUbuntu_20.04/ /' | sudo tee /etc/apt/sources.list.d/devel:languages:crystal.list
RUN curl -fsSL https://download.opensuse.org/repositories/devel:languages:crystal/xUbuntu_20.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/devel_languages_crystal.gpg > /dev/null

# Setup Dart
RUN sudo sh -c 'wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
RUN sudo sh -c 'wget -qO- https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'

# Setup Powershell
RUN sudo sh -c 'wget -q https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb'
RUN sudo sh -c 'dpkg -i packages-microsoft-prod.deb'

# Setup Clojure
RUN sudo sh -c 'curl -O https://download.clojure.org/install/linux-install-1.10.3.967.sh'
RUN sudo sh -c 'chmod +x linux-install-1.10.3.967.sh'
RUN sudo sh -c 'sudo ./linux-install-1.10.3.967.sh'

# Setup dotnet
RUN sudo sh -c 'wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb'
RUN sudo sh -c 'sudo dpkg -i packages-microsoft-prod.deb'
RUN sudo sh -c 'rm packages-microsoft-prod.deb'

# Setup D Lang
RUN sudo sh -c 'mkdir -p ~/dlang && wget https://dlang.org/install.sh -O ~/dlang/install.sh'
RUN sudo sh -c 'bash ~/dlang/install.sh'
## From Docs not needed though
# RUN sudo sh -c 'source ~/dlang/dmd-2.097.2/activate'
ENV PATH=$PATH:/root/dlang/dmd-2.097.2/linux/bin64

# Setup Go
RUN sudo sh -c 'wget -c https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local'
ENV PATH=$PATH:/usr/local/go/bin

# Setup Kotlin (doesnt unzip right maybe?)
RUN sudo sh -c 'wget -c https://github.com/JetBrains/kotlin/releases/download/v1.5.30/kotlin-compiler-1.5.30.zip -O /usr/local/kotlinc.zip'
RUN unzip /usr/local/kotlinc.zip
ENV PATH=$PATH:/usr/local/kotlinc/bin

# Setup lolcode
## Use: https://github.com/justinmeza/lci

# Setup Piet
## Use: https://github.com/boothby/repiet


# Setup Matlab
# ?????? This is a licensed language???

# Setup Emojicode (in progress)
RUN sudo sh -c 'wget -c https://github.com/emojicode/emojicode/releases/download/v1.0-beta.2/Emojicode-1.0-beta.2-Linux-x86_64.tar.gz -O /usr/local/Emojicode-1.0-beta.2-Linux-x86_64.tar.gz'
RUN sudo tar -xvzf /usr/local/Emojicode-1.0-beta.2-Linux-x86_64.tar.gz
# && cd ~/emojicode/ && echo && ./install.sh'
ENV PATH=$PATH:/usr/local/Emojicode-1.0-beta.2-Linux-x86_64

# Setup Factor (in progress)
RUN mkdir -p ~/factor && wget https://downloads.factorcode.org/releases/0.98/factor-linux-x86-64-0.98.tar.gz -O ~/factor/factor.tar.gz
RUN tar -xzf /root/factor/factor.tar.gz
# && rm ~/factor/factor.tar.gz
ENV PATH=$PATH:/root/factor/factor

# Setup R
RUN sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
RUN sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'

# Setup Racket and Scheme
# To run scheme files, use `racket -f <file.ss>`
RUN sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D9D33FCD84D82C17288BA03B3C9A6980F827E01E
RUN sudo add-apt-repository 'deb http://ppa.launchpad.net/plt/racket/ubuntu focal main'

# Setup Scratch
## using 1.x right now.... in future checkout snap or adobe air?

# Setup Swift
RUN mkdir -p ~/swift && wget https://swift.org/builds/swift-5.5-release/ubuntu2004/swift-5.5-RELEASE/swift-5.5-RELEASE-ubuntu20.04.tar.gz -O ~/swift/swift.tar.gz && \
    tar -xzf ~/swift/swift.tar.gz -C ~/swift --strip-components=1
ENV PATH=$PATH:~/swift/usr/bin

# Setup viml
## ?

# Setup whitespace
## ?

# Setup Elm
## https://github.com/elm/compiler/blob/master/installers/linux/README.md

# Setup V
## https://github.com/vlang/v/blob/master/doc/docs.md


# Install the packages that needed extra help
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
    && apt-get -y install --no-install-recommends crystal dart nim powershell scala dotnet-sdk-5.0 r-base racket

RUN pip install wheel matplotlib numpy coconut scons

RUN sudo sh -c 'npm install -g typescript'

Copy link
Member

@leios leios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to merge this!

@leios leios merged commit cfcfccc into algorithm-archivists:master Oct 26, 2021
@Amaras Amaras deleted the compilation_scons branch December 5, 2021 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest The label for all Hacktoberfest related things! hacktoberfest-accepted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants