\documentclass[aspectratio=169,obeyspaces,spaces,hyphens,dvipsnames]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}% http://ctan.org/pkg/lm
\usepackage{minted}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage[normalem]{ulem}

\mode<presentation>
\usetheme{Bootlin}

\def\signed #1{{\leavevmode\unskip\nobreak\hfil\penalty50\hskip2em
  \hbox{}\nobreak\hfil(#1)
  \parfillskip=0pt \finalhyphendemerits=0 \endgraf}}

\newsavebox\mybox
\newenvironment{aquote}[1]
  {\savebox\mybox{#1}\begin{quotation}}
  {\signed{\usebox\mybox}\end{quotation}}

\title{Using Visual Studio Code for Embedded Linux Development}
\authors{Michael Opdenacker}
\email{michael@bootlin.com}
\slidesurl{https://bootlin.com/pub/conferences/2020/elce}
\institute{Bootlin}
\conference{Embedded Linux Conference Europe 2020}

\begin{document}

\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}
\section{Using Visual Studio Code for Embedded Linux Development}
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}

\begin{frame}{Michael Opdenacker}
  \begin{columns}
  \column{0.7\textwidth}
  \begin{itemize}
  \item Founder and Embedded Linux engineer at Bootlin:
    \begin{itemize}
    \item Embedded Linux engineering company
    \item Specialized in low level development: kernel and bootloader,
	  embedded Linux build systems, boot time reduction,
	  secure booting, graphics layers...
    \item Contributing to the community as much as possible
	  (code, experience sharing, free training materials)
    \end{itemize}
  \item Current maintainer of the Elixir Cross Referencer
	indexing the source code of Linux, U-Boot, BusyBox...
	(\url{https://elixir.bootlin.com})
  \item Interested in discovering new tools and sharing
	the experience with the community.
  \item So far, only used Microsoft tools with the purpose
	of replacing them!
  \end{itemize}
  \column{0.3\textwidth}
  \end{columns}
\end{frame}

\subsection{{\em In the Stack Overflow 2019 Developer
Survey, Visual Studio Code was ranked the most popular developer
environment tool, with 50.7\% of 87,317 respondents claiming to use
it}\\(Wikipedia)}


\begin{frame}{Disclaimer and goals}
  \begin{columns}
  \column{0.7\textwidth}
  \begin{itemize}
  \item I'm not a Visual Studio Code guru!
  \item After hearing about VS Code from many Bootlin customers,
	I wanted to do my own research on it and share it
	with you.
  \item The main focus of this research is to find out
        to what extent VS Code can help with embedded Linux development,
        and how it compares to the Elixir Cross Referencer in terms
        of code browsing.
  \item Please share your experience while this pre-recorded talk
	is played, by posting comments and questions. I'll be available
	during and after the talk.
  \end{itemize}
  \column{0.3\textwidth}
  \end{columns}
\end{frame}

\begin{frame}{Visual Studio Code}
  \begin{columns}
    \column{0.7\textwidth}
    \url{https://code.visualstudio.com/}
    \begin{itemize}
    \item {\em Visual Studio Code is a {\bf free} source-code editor made by
          Microsoft for Windows, Linux and macOS. Features include support for
          debugging, syntax highlighting, intelligent code completion, snippets,
          code refactoring, and embedded Git. Users can change the theme, keyboard
          shortcuts, preferences, and install extensions that add additional
          functionality.} (Wikipedia)
    \item First release in 2015
    \item Over 16,000 extensions developed by the community
    \item {\bf Not a free software / open-source project}, but based
	  on the {\em vscode} open-source project which is MIT licensed:
          \url{https://github.com/microsoft/vscode}
    \end{itemize}
    \column{0.3\textwidth}
    \includegraphics[width=\textwidth]{vscode-icon.pdf}
    \tiny Image source (Wikipedia):\\
	  \url{https://frama.link/GoHrYMy5}
  \end{columns}
\end{frame}

\begin{frame}{Issues in Visual Studio Code}
  \begin{columns}
  \column{0.7\textwidth}
  \begin{itemize}
  \item Telemetry:
        \begin{itemize}
           \item Visual Studio Code collects usage data and sends it
	   to Microsoft. The {\em Microsoft Privacy Statement} is about all Microsoft products
	   and doesn't reveal details about such data collection.
           \item But can can be disabled in user settings (look for
           \code{telemetry}), and the source code is available.
	\end{itemize}
  \item Extensions marketplace:
        \begin{itemize}
           \item Another issue is that Microsoft prohibits non Visual Studio
           applications from downloading binaries from their extensions
           marketplace.
	   \item See section 1.b. of
	   \href{https://cdn.vsassets.io/v/M146\_20190123.39/\_content/Microsoft-Visual-Studio-Marketplace-Terms-of-Use.pdf}{their Marketplace terms}
           \item This is disappointing as most extensions are
           open-source and not developed by Microsoft.
	   \item As a consequence, extension owners have to push their
           extensions to other extension registries too.
	\end{itemize}
  \end{itemize}
  \column{0.3\textwidth}
  \end{columns}
\end{frame}

\begin{frame}{An alternative: VSCodium}
  \begin{columns}
    \column{0.7\textwidth}
    \url{https://vscodium.com/}
    \begin{itemize}
	\item A 100 \% open-source build of Visual Studio Code,
	      with telemetry disabled
	\item Strengths:
        \begin{itemize}
	   \item Very frequent updates, staying in sync with VS Code releases
        \end{itemize}
	\item Limitations:
        \begin{itemize}
	   \item Doesn't have all of VS Code extensions (cannot use
		 the same marketplace). Missing extensions: {\em
                 DeviceTree}, {\em kconfig}, {\em Embedded Linux Kernel Dev}.
	   \item In particular, C/C++ support is built-in and doesn't
		 work out of the box. See
                 \href{https://github.com/VSCodium/vscodium/issues/530}{my
                 bug report}.
        \end{itemize}
	\item Project definitely worth supporting, but we will stick
	      to VS Code for the moment.
    \end{itemize}
    \column{0.3\textwidth}
    \includegraphics[width=\textwidth]{vscodium-icon.png}
    \tiny Image source (VSCodium project):\\
	  \url{https://frama.link/0onEnRzS}
  \end{columns}
\end{frame}

\begin{frame}{Other related solutions}
  \begin{columns}
    \column{0.7\textwidth}
    \small
    Theia IDE (\url{https://theia-ide.org/})
    \begin{itemize}
	\item Directly supports VS Code extensions
	\item But a different project with its own architecture,
	      more modular and allowing for more customizations.
	      Designed from the ground up to run on both cloud
	      and desktop.
	\item Developed and hosted by a vendor-neutral open-source
	      foundation (Eclipse Foundation)
	\item Adopted in many IDEs: new Arduino {\em PRO IDE}, ARM
              {\em mbed}, {\em Eclipse Che}, SAP's web IDE...
    \end{itemize}
    Eclipse OpenVSX (\url{http://open-vsx.org/})
    \begin{itemize}
	\item Vendor-neutral open-source alternative to the Visual Studio Marketplace
    \end{itemize}
    See the very clear article on \url{https://frama.link/MYGsYuXg} for details.
    \column{0.3\textwidth}
    \includegraphics[width=\textwidth]{theia-logo.pdf}
    \tiny Image source (Theia project):\\
          (\url{https://theia-ide.org/})
    \vfill
    \includegraphics[width=\textwidth]{openvsx-logo.png}
    Image source:\\
    \url{https://github.com/open-vsx}
   \end{columns}
\end{frame}

\begin{frame}{Quick Visual Studio Code glossary}
  \begin{columns}
  \column{0.7\textwidth}
   For words you will see in the interface...
   \begin{itemize}
      \item {\bf Intellisense} : Code Completion Tool built into
         Microsoft Visual Studio.
	 See \url{https://code.visualstudio.com/docs/editor/intellisense}
      \item {\bf Emmet}: The essential toolkit for web-developers
      \item {\bf Language Server Protocol}: open protocol for
            communication between code editors and IDEs. See
            \url{https://en.wikipedia.org/wiki/Language_Server_Protocol}
   \end{itemize}
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\begin{frame}{Demo: Visual Studio Code setup}
  \begin{columns}
  \column{0.7\textwidth}
  \begin{itemize}
	\item Installation on Ubuntu
	\item Quick interface overview
	\item Disable telemetry
	\item Most important shortcuts
  \end{itemize}
  \column{0.3\textwidth}
  \end{columns}
\end{frame}

\begin{frame}{Demo: cpptools extension}
   \begin{columns}
   \column{0.7\textwidth}
   \begin{itemize}
     \item For C and C++
     \item License: proprietary, but based on
           \code{https://github.com/microsoft/vscode-cpptools/} (MIT)
     \item Open the Linux kernel source directory
     \item Looking up identifiers
     \item Expansion of defines
     \item Typing code and autocompletion
   \end{itemize}
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\begin{frame}{Demo: VIM extension}
   \begin{columns}
   \column{0.7\textwidth}
   \begin{itemize}
     \item \url{https://github.com/VSCodeVim/Vim}
     \item License: MIT
     \item Easy to enable, all commands seem to work
   \end{itemize}
   Note: other extensions exist for other editors: Emacs, Atom...
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\begin{frame}{Demo: Checkpatch Lint extension}
   \begin{columns}
   \column{0.7\textwidth}
   \begin{itemize}
     \item \url{https://github.com/idanpa/vscode-checkpatch}
     \item License: MIT
     \item Need to install \code{checkpatch.pl} on your system
     \item Very useful to create code that's compliant with
	   the Linux kernel coding style and rules right from the start.
   \end{itemize}
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\begin{frame}{Demo: Kconfig syntax highlighting}
   \begin{columns}
   \column{0.7\textwidth}
   Kconfig syntax highlighting
   \begin{itemize}
      \item \url{https://github.com/luveti/kconfig-vscode}
      \item License: MIT
      \item Just for syntax highlighting in Linux kernel and Buildroot
	    configuration parameter definitions. No symbol lookup.
      \item Comparing to Elixir capabilities
   \end{itemize}
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\begin{frame}{Demo: Embedded Linux Kernel Dev extension}
   \begin{columns}
   \column{0.7\textwidth}
   \begin{itemize}
      \item \url{https://github.com/microhobby/linuxkerneldev}
      \item License: MIT
      \item Symbol autocompletion, function and symbol navigation, for C, Kconfig, defconfig,
            .config and device tree files.
      \item Also adds some automation to match device tree compatibles
            and open their respective driver or documentation files.
      \item Based on \code{universal-ctags} but less advanced than Elixir
   \end{itemize}
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\begin{frame}{Demo: GitLens}
   \begin{columns}
   \column{0.7\textwidth}
   \begin{itemize}
	\item \url{https://github.com/eamodio/vscode-gitlens.git}
	\item License: MIT
	\item Git blame feature
   \end{itemize}
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\begin{frame}{Demo: Linux kernel cross-compiling}
   \begin{columns}
   \column{0.7\textwidth}
   \begin{itemize}
     \item Setting the environment in a terminal
     \item Using the terminal to configure and
	   build the kernel.
     \item Didn't find much added value here.
	   cpptools could help using cross-toolchains.
   \end{itemize}
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\begin{frame}{Demo: cross-compiling a simple C program}
   \begin{columns}
   \column{0.7\textwidth}
   \begin{itemize}
	\item How to specify the use of a cross-compiler
	\item How build tasks are defined
   \end{itemize}
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\begin{frame}{Demo: CMake Tools}
   \begin{columns}
   \column{0.7\textwidth}
   From Microsoft
   \begin{itemize}
	\item \url{https://github.com/microsoft/vscode-cmake-tools}
	\item License: MIT
	\item Can generate a template project for you
	\item Nice feature: capability to detect cross-toolchains ({\em
              Kits}), but partially broken.
	\item Support for multiple compiling profiles (production,
              debug, size or speed optimizations...)
	\item Limitation: example code and CMake files only for C++ (no
              C, no Rust...)
   \end{itemize}
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\begin{frame}{Demo: remote debugging with gdbserver}
   \begin{columns}
   \column{0.7\textwidth}
   \begin{itemize}
	\item Implementing a script to cross-compile code, deploy
	      the generated executable on the target through SSH, and
	      start it remotely through \code{gdbserver}.
	\item Customizing VSCode for the use of a remote debugger.
	\item Using the remote debugger: inserting breakpoints, step
	      by step execution, reading variables, analyzing a
	      segmentation fault....
   \end{itemize}
   Thanks to \href{https://frama.link/tVsPXDh0}{Karel Vermeiren's article}
   which really helped to make this work.
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\begin{frame}{VS Code and extensions vs Elixir}
   \begin{columns}
   \column{0.7\textwidth}
   In terms of code browsing, Elixir Cross Referencer wins for:
   \begin{itemize}
	\item C/C++, Makefiles, Device Tree: provides links to included files
	\item Device Tree: finding driver bindings
	\item Kconfig language support
   \end{itemize}
   ... but VS Code wins for:
   \begin{itemize}
	\item Exposing Git information (Git blame...)
	\item In place information exposure (symbol prototypes,
	      expansion of defines)
   \end{itemize}
   But of course, VS Code offers much more than code browsing!
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\begin{frame}{Visual Studio Code limitations}
   \begin{columns}
   \column{0.7\textwidth}
   \begin{itemize}
	\item No way to filter extensions by license (open-source or
              proprietary). Same issue on Android by the way!
	\item cpptools: observed clogging the CPU (or I/O) looking for the
	      declaration of some symbols. Had to close VS Code to end
	      this. Quite rare though.
	\item Current lack of extensions for embedded Linux
              applications and tools:
	      cross-compiling toolchains,
	      Valgrind (except output syntax highlighting), strace,
	      ltrace, Yocto Project, Buildroot, nothing for kernel modules,
	      no serial port emulators...
	\item Currently, VS Code and extensions seem better suited
	      for microcontroller/RTOS work than for embedded Linux.
   \end{itemize}
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\begin{frame}{Conclusions: Visual Studio Code and Embedded Linux}
   \begin{columns}
   \column{0.7\textwidth}
   \begin{itemize}
	\item Visual Studio Code still misses important features for
	      embedded Linux development.
	\item However, Visual Studio Code is very flexible, easy to extend,
	      and has a great potential for further improvements.
	\item Great solution for debugging programs, even remotely
	\item It makes me feel like contributing new extensions,
	      for example to support Bootlin cross-compiling toolchains.
	      This will also benefit to more open platforms (VSCodium,
	      Theia...).
   \end{itemize}
   \column{0.3\textwidth}
   \end{columns}
\end{frame}

\questionslide

\end{document}
