<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Embedding on Arzedlab 🪵</title><link>https://arzedlab.github.io/tags/embedding/</link><description>Recent content in Embedding on Arzedlab 🪵</description><generator>Hugo</generator><language>en-us</language><copyright>© Ravshan</copyright><lastBuildDate>Thu, 06 Jul 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://arzedlab.github.io/tags/embedding/index.xml" rel="self" type="application/rss+xml"/><item><title>Getting Started with Embedding V8</title><link>https://arzedlab.github.io/posts/getting-started-with-embedding-v8-a91a35cbf98c46c08dde76f3f5958406/</link><pubDate>Thu, 06 Jul 2023 00:00:00 +0000</pubDate><guid>https://arzedlab.github.io/posts/getting-started-with-embedding-v8-a91a35cbf98c46c08dde76f3f5958406/</guid><description>&lt;h1 id="getting-started-with-embedding-v8">Getting Started with Embedding V8&lt;/h1>
&lt;h2 id="installing--testing-standalone-v8-application">Installing &amp;amp; Testing Standalone V8 application&lt;/h2>
&lt;ol>
&lt;li>Download the V8 source code&lt;/li>
&lt;li>Create a build configuration using the helper script:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>tools/dev/v8gen.py x64.release.sample
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>You can inspect and manually edit the build configuration by running:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>gn args out.gn/x64.release.sample 
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>Build the static library on a Linux 64 system:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>ninja -C out.gn/x64.release.sample v8_monolith
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>Compile &lt;code>hello-world.cc&lt;/code>, linking to the static library created in the build process. For example, on 64bit Linux using the GNU compiler:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>g++ -I. -Iinclude samples/hello-world.cc -o hello_world -fno-rtti -lv8_monolith -lv8_libbase -lv8_libplatform -ldl -Lout.gn/x64.release.sample/obj/ -pthread -std&lt;span style="color:#ff79c6">=&lt;/span>c++17 -DV8_COMPRESS_POINTERS -DV8_ENABLE_SANDBOX
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>For more complex code, V8 fails without an ICU data file. Copy this file to where your binary is stored:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>cp out.gn/x64.release.sample/icudtl.dat .
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>Run the &lt;code>hello_world&lt;/code> executable file at the command line. e.g. On Linux, in the V8 directory, run:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>./hello_world
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>V8 as a standalone virtual machine has some key V8 concepts such as &lt;strong>handles&lt;/strong>, &lt;strong>scopes&lt;/strong>, and &lt;strong>contexts.&lt;/strong> The V8 API provides functions for compiling and executing scripts, accessing C++ methods and data structures, handling errors, and enabling security checks. Your application can use V8 just like any other C++ library. Your C++ code accesses V8 through the V8 API by including the header &lt;code>include/v8.h&lt;/code>.&lt;/p></description></item></channel></rss>