VSCode and Docker

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

VSCode and Docker

Post by vanuan »

I'd like to share my IDE setup and ask if anybody is interested in replicating/using it.

I'm using VSCode and Docker.

Docker is used for the purpose similar to AppImage - to improve security and workaround incompatible dependencies.
Screenshot from 2020-07-01 19-22-54.jpg
Screenshot from 2020-07-01 19-22-54.jpg (113.36 KiB) Viewed 2229 times
As a base docker image, I'm using registry.gitlab.com/daviddaish/freecad_docker_env:latest
which is apparently being migrated to GitHub: https://github.com/FreeCAD/Docker/pull/1/files

My workspace folders:

- freecad-docker (bash scripts and docker-compose files, workspace files)
- freecad-source (main freecad git repo)
- freecad-build (CMake build directory)

The main challenge was how to make VSCode see header files installed inside a docker image.
So, I've decided to write a script which copies include folders from the docker image to the `freecad-build/include` directory.

For that, I wrote a CMake query.json which generates a log of *.json files from which I grab include paths and copy them.

After that, I'm putting those to the `.vscode/c_cpp_properties.json`

A snippet which copies includes and generates include paths:

Code: Select all

# get includes
INCLUDES_ALL=`cat .cmake/api/v1/reply/target-*.json | jq -r 'select(.compileGroups != null).compileGroups[].includes[].path' | sort | uniq`
INCLUDES_TO_COPY=${for include in $INCLUDES_ALL; do echo "$include" | grep -v mnt; done}
INCLUDES_BUILD=`for include in $INCLUDES_ALL; do echo "$include" | grep 'mnt/build'; done`
INCLUDES_SOURCE=`for include in $INCLUDES_ALL; do echo "$include" | grep 'mnt/source'; done`

# cp includes
mkdir includes
for include in $INCLUDES_TO_COPY; do cp -r -L --parents "$include"/* ./includes; done
cp -r -L --parents "/usr/local/include/" ./includes

# standard location library includes
echo "\"\${workspaceFolder}/../freecad-build/includes/usr/local/include\""
# non-standard location library includes
for include in $INCLUDES_TO_COPY; do echo "\"\${workspaceFolder}/../freecad-build/includes$include\","; done
# generated includes
for include in $INCLUDES_BUILD; do echo "\"\${workspaceFolder}/../freecad-build`sed -E 's/\/mnt\/build//' <<<$include`\","; done
# source includes
for include in $INCLUDES_SOURCE; do echo "\"\${workspaceFolder}/../freecad-source`sed -E 's/\/mnt\/source//' <<<$include`\","; done
To run Freecad (as it links with libraries inside the container, not my host libraries), I'm using X11 Unix sockets. I think this setup also can be used to develop in OS X and Windows environments.

If anybody's interested, I can share more.
Maybe you have any thoughts on this setup and how it can be improved.
Smiling_user
Posts: 196
Joined: Tue Jul 28, 2020 7:31 am

Re: VSCode and Docker

Post by Smiling_user »

Well...
Interested

Are there any differences Windows 7 - Ubuntu ? Which OS will be more comfortable: easy-findable and steady working solutions (maybe command line).
How much space needed for comfortable FreeCAD coding? // How much does it take Full IDE + source + Libs + couple of versions
What about Git?
What about Code compatibility Win/Lin/Mac ? // how to code so, that the code will be compatible with all OS-s?
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: VSCode and Docker

Post by vanuan »

Smiling_user wrote: Wed Sep 02, 2020 6:06 am

Are there any differences Windows 7 - Ubuntu ? Which OS will be more comfortable: easy-findable and steady working solutions (maybe command line).
How much space needed for comfortable FreeCAD coding? // How much does it take Full IDE + source + Libs + couple of versions
What about Git?
What about Code compatibility Win/Lin/Mac ? // how to code so, that the code will be compatible with all OS-s?
I haven't tried but windows should work the same if you manage to install Docker. The only issue would be running X11 apps, as you would need X client.

Ubuntu is preferred I believe. Windows 7 is quite an outdated OS and might not support Docker.

Wrt space, I think several gigabytes. 10 GB should be enough. If you want specifics, the docker image (libraries and build tools) is 1.5 GB, the debug FreeCAD builld is around 700 MB, source code is also heavy. VSCode is a beast in itself - 1GB at least.
I would also reserve twice as much as you probably want to work on several branches at the same time, and switching between branches usually requires heavy rebuilds, so I just clone FreeCAD multiple times.

Git is comparably small, though to use it in Windows you'd need some Unix distribution like MinGW. OTOH, VSCode probably has git integrated, but GUI is not as powerful as CLI.

Wrt to compatibility, you've got covered: FreeCAD uses Qt which is a cross platform framework, it also uses Python which is crossplatform by design (unless you use some native modules which requires binaries to be compatible). When you submit a PR, the code is checked against all supported environments by CI.
etrombly
Posts: 144
Joined: Thu Dec 05, 2019 6:50 pm

Re: VSCode and Docker

Post by etrombly »

Thanks, I've been using docker with VSCode as well, but never bothered with the headers. This should help. I also modified it to use dist_cc, if you have other computers you can do distributed builds. Are you using docker-compose? That makes managing it easier.
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: VSCode and Docker

Post by vanuan »

etrombly wrote: Fri Sep 04, 2020 10:08 pm Thanks, I've been using docker with VSCode as well, but never bothered with the headers. This should help. I also modified it to use dist_cc, if you have other computers you can do distributed builds. Are you using docker-compose? That makes managing it easier.
Actually, I think CMake plugin manages headers for you. Yes, I'm using docker-compose.
Smiling_user
Posts: 196
Joined: Tue Jul 28, 2020 7:31 am

Re: VSCode and Docker

Post by Smiling_user »

Stacked on installing Docker: Got info from
https://docs.docker.com/engine/install/ ... requisites
But did not manage to install.

Could you, please, provide certain terminal commands to install Docker - VSCode environment?
######
Solution:
Before running

Code: Select all

$ docker run hello-world
the computer must be restarted, or at least logOut - LogIn.
ari_yagui
Posts: 3
Joined: Thu Jul 16, 2020 5:08 pm

Re: VSCode and Docker

Post by ari_yagui »

Hi Vanuan, Would you be so kind as to write a step by step tutorial for configuring VSCode and Docker in the freecad help? May be in the same section of https://wiki.freecadweb.org/Compile_on_Docker

It would be very usefull.


Thanks!!!
Post Reply