<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Devex on despatches</title><link>https://icle.es/tags/devex/</link><description>Recent content in Devex on despatches</description><generator>Hugo</generator><language>en</language><lastBuildDate>Mon, 23 Jun 2025 12:11:10 +0100</lastBuildDate><atom:link href="https://icle.es/tags/devex/index.xml" rel="self" type="application/rss+xml"/><item><title>Add zig dependency in bazel</title><link>https://icle.es/2025/06/11/add-zig-dependency-in-bazel/</link><pubDate>Wed, 11 Jun 2025 20:44:01 +0100</pubDate><guid>https://icle.es/2025/06/11/add-zig-dependency-in-bazel/</guid><description>&lt;p>&lt;code>[rules-zig][https://github.com/aherrmann/rules_zig]&lt;/code> doesn&amp;rsquo;t use &lt;code>zon&lt;/code>
files(yet) and addind dependencies involves adding it into &lt;code>MODULES.bazel&lt;/code>. If
you&amp;rsquo;re still using workspaces on bazel,
&lt;a href="https://github.com/aherrmann/rules_zig/issues/231#issuecomment-2723684385">this code sample mentioned in the related issue might help&lt;/a>.
I started with that code sample.&lt;/p>
&lt;p>I was adding in a dependency to &lt;a href="https://github.com/sam701/zig-toml">zig-toml&lt;/a>
and this is the
&lt;a href="https://github.com/drone-ah/wordsonsand/blob/9dd185e5f330403cad9afe2ad67cc511565e1325/MODULE.bazel#L43">rule that I used&lt;/a>:&lt;/p>
```starlark
zig_toml_archive(
 name = "zig_toml",
 urls = ["https://github.com/sam701/zig-toml/archive/refs/heads/main.zip"],
 sha256 = "b1f0846c3b5e9696892b0d96f8add4878c057c728623b03d6bfbd508e4af48d5",
 strip_prefix = "zig-toml-main",
 build_file_content = """
load("@rules_zig//zig:defs.bzl", "zig_module")
zig_module(
 name = "toml",
 main = "src/root.zig",
 srcs = glob(["src/**/*.zig"]),
 visibility = ["//visibility:public"],
)
""",
)
```
&lt;p>Let&amp;rsquo;s break it down:&lt;/p></description><content:encoded><![CDATA[<p><code>[rules-zig][https://github.com/aherrmann/rules_zig]</code> doesn&rsquo;t use <code>zon</code>
files(yet) and addind dependencies involves adding it into <code>MODULES.bazel</code>. If
you&rsquo;re still using workspaces on bazel,
<a href="https://github.com/aherrmann/rules_zig/issues/231#issuecomment-2723684385">this code sample mentioned in the related issue might help</a>.
I started with that code sample.</p>
<p>I was adding in a dependency to <a href="https://github.com/sam701/zig-toml">zig-toml</a>
and this is the
<a href="https://github.com/drone-ah/wordsonsand/blob/9dd185e5f330403cad9afe2ad67cc511565e1325/MODULE.bazel#L43">rule that I used</a>:</p>
```starlark
zig_toml_archive(
    name = "zig_toml",
    urls = ["https://github.com/sam701/zig-toml/archive/refs/heads/main.zip"],
    sha256 = "b1f0846c3b5e9696892b0d96f8add4878c057c728623b03d6bfbd508e4af48d5",
    strip_prefix = "zig-toml-main",
    build_file_content = """
load("@rules_zig//zig:defs.bzl", "zig_module")
zig_module(
    name = "toml",
    main = "src/root.zig",
    srcs = glob(["src/**/*.zig"]),
    visibility = ["//visibility:public"],
)
""",
)
```
<p>Let&rsquo;s break it down:</p>
<ul>
<li><code>name</code>: Pretty flexible, but you probably want to use the lib name, or the
name you would use in the zon file.</li>
<li><code>urls</code>: You need the url to the zip file. If you want main - you can click on
the button that says <code>Code</code> and at the use the link at the bottom that says
&ldquo;Download ZIP&rdquo;.
<a href="https://docs.github.com/en/repositories/working-with-files/using-files/downloading-source-code-archives">GitHub documentation on source code archives</a>
has more information as well as details on how to get he url for specific
commits etc.</li>
<li><code>sha256</code>: When running for the first time, bazel will tell you that
<code>a canonical reproducible form can be obtained by modifying arguments integrity = &quot;sha256-&lt;hash&gt;&quot;</code>.
However, for whatever reason, it uses a different format from what you need to
use in the <code>MODULES.bazel</code> file. To convert it, you can use:</li>
</ul>
```bash
echo '<hash>' | base64 -d | xxd -p -c 256
```
<ul>
<li><code>strip_prefix</code>: The zip file will extract the files out into a directory. This
parameter is that directory name. I just unzipped the zip file and put that
here. I&rsquo;m sure there are simpler ways to get at it (please let me know below
if you know of a way)</li>
<li><code>build_file_content</code>: This parameter lets you define what the contents of the
build file will be when building that library. It might be nice to be able to
reference a file rather than include it here - I think I&rsquo;ve done that before
but I can&rsquo;t remember how. Please let me know below if you know how it&rsquo;s done
and I&rsquo;ll update it here.</li>
</ul>
]]></content:encoded></item><item><title>Use `protoc` bin instead of building from source in `bazel`</title><link>https://icle.es/2025/06/09/use-protoc-bin-in-bazel/</link><pubDate>Mon, 09 Jun 2025 20:57:53 +0000</pubDate><guid>https://icle.es/2025/06/09/use-protoc-bin-in-bazel/</guid><description>&lt;p>I work on a project that uses &lt;code>pulumi&lt;/code> automation api, which in turn uses
&lt;code>protobuf&lt;/code>. I think there are other bits in &lt;code>bazel&lt;/code> that also uses it.&lt;/p>
&lt;p>For a while, it was fine - except that some &lt;code>CI&lt;/code> runs would take 15 minutes and
we couldn&amp;rsquo;t quite figure out why.&lt;/p>
&lt;p>I finally had to update &lt;code>bazel&lt;/code> from 7.x to 8 and in that process (which
honestly could have been easier, but oh well), I ran into a problem with
compiling protobuf.&lt;/p>
&lt;p>Namely, I kept running into this error:&lt;/p>
```
error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
```
&lt;p>I tried many things but was not able to get past this error. In the end, I was
able to narrow it down to devbox/nix and how it messes with the environment that
doesn&amp;rsquo;t quite agree with &lt;code>bazel&lt;/code>.&lt;/p>
&lt;h2 id="what-didnt-work">What didn&amp;rsquo;t work&lt;/h2>
&lt;ul>
&lt;li>installing &lt;code>gcc&lt;/code> from devbox&lt;/li>
&lt;li>installing &lt;code>stdenv.cc.cc.lib&lt;/code>&lt;/li>
&lt;li>Setting &lt;code>LD_LIBRARY_PATH&lt;/code> (to
&lt;code>&amp;lt;workspace-dir&amp;gt;/.devbox/nix/profile/default/lib&lt;/code>, which is where the devbo
version of &lt;code>libstdc++.so.6&lt;/code> is installed by &lt;code>stdenv.cc.cc.lib&lt;/code>)&lt;/li>
&lt;li>Using the &lt;code>--action-env=&lt;/code>&lt;/li>
&lt;li>&lt;a href="https://github.com/tweag/rules_nixpkgs">rules-nixpkgs&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>None of which really worked.&lt;/p>
&lt;p>Disabling &lt;code>devbox&lt;/code> &lt;strong>did&lt;/strong> work, which was at least partly encouraging. I also
found a bunch of evidence online around this issue
(&lt;a href="https://github.com/bazelbuild/bazel/issues/12978">1&lt;/a>,
&lt;a href="https://github.com/jetify-com/devbox/issues/1100">2&lt;/a>,
&lt;a href="https://github.com/jetify-com/devbox/issues/1596">3&lt;/a>,
&lt;a href="https://github.com/jetify-com/devbox/issues/710">4&lt;/a>,
&lt;a href="https://github.com/tweag/rules_nixpkgs/issues/573">5&lt;/a>). Bazel seems to
&lt;a href="https://discuss.ray.io/t/bazel-protobuf-build-errors-libstdc-with-non-system-gcc/3329">generally dislike non-system gcc&lt;/a>.&lt;/p></description><content:encoded><![CDATA[<p>I work on a project that uses <code>pulumi</code> automation api, which in turn uses
<code>protobuf</code>. I think there are other bits in <code>bazel</code> that also uses it.</p>
<p>For a while, it was fine - except that some <code>CI</code> runs would take 15 minutes and
we couldn&rsquo;t quite figure out why.</p>
<p>I finally had to update <code>bazel</code> from 7.x to 8 and in that process (which
honestly could have been easier, but oh well), I ran into a problem with
compiling protobuf.</p>
<p>Namely, I kept running into this error:</p>
```
error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
```
<p>I tried many things but was not able to get past this error. In the end, I was
able to narrow it down to devbox/nix and how it messes with the environment that
doesn&rsquo;t quite agree with <code>bazel</code>.</p>
<h2 id="what-didnt-work">What didn&rsquo;t work</h2>
<ul>
<li>installing <code>gcc</code> from devbox</li>
<li>installing <code>stdenv.cc.cc.lib</code></li>
<li>Setting <code>LD_LIBRARY_PATH</code> (to
<code>&lt;workspace-dir&gt;/.devbox/nix/profile/default/lib</code>, which is where the devbo
version of <code>libstdc++.so.6</code> is installed by <code>stdenv.cc.cc.lib</code>)</li>
<li>Using the <code>--action-env=</code></li>
<li><a href="https://github.com/tweag/rules_nixpkgs">rules-nixpkgs</a></li>
</ul>
<p>None of which really worked.</p>
<p>Disabling <code>devbox</code> <strong>did</strong> work, which was at least partly encouraging. I also
found a bunch of evidence online around this issue
(<a href="https://github.com/bazelbuild/bazel/issues/12978">1</a>,
<a href="https://github.com/jetify-com/devbox/issues/1100">2</a>,
<a href="https://github.com/jetify-com/devbox/issues/1596">3</a>,
<a href="https://github.com/jetify-com/devbox/issues/710">4</a>,
<a href="https://github.com/tweag/rules_nixpkgs/issues/573">5</a>). Bazel seems to
<a href="https://discuss.ray.io/t/bazel-protobuf-build-errors-libstdc-with-non-system-gcc/3329">generally dislike non-system gcc</a>.</p>
<h2 id="a-ray-of-hope">A ray of hope</h2>
<p>I was just about ready to throw in the towel when ChatGPT, in passing suggested
using the <code>protobuf</code> binary directly. I wasn&rsquo;t even using this binary - it was
being pulled in as a dependency and I just needed it to work. I did not need it
to be built from source.</p>
<p>Furthermore, I found, from my research into trying to solve this that building
<code>protobuf</code> was the likely culprit in the <code>CI</code> taking 15 minutes.</p>
<p>I also remembered that someone else on the team had issues trying to get it to
build on a mac at some point.</p>
<p>All in all, it was a problematic piece of software and I was seriously
considering switching to <code>opentofu</code> - but they might be using it too.</p>
<h2 id="bin-protoc">bin <code>protoc</code></h2>
<p>It was difficult to find decent documentation about how to achieve this though,
apart from a partially answered on:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/68918369/is-it-possible-to-use-bazel-without-compiling-protobuf-compiler">stackoverflow question</a>,</li>
<li><a href="https://groups.google.com/g/bazel-discuss/c/3Q_GEqNZrC0">google groups for bazel-discuss</a>
<ul>
<li>which also led me to
<a href="https://gitlab.com/mvfwd/issue-bazel-protobuf-compile/-/tree/main">a gitlab repo with some code</a></li>
</ul>
</li>
</ul>
<p>These resources gave me just enough to be able to cobble together a working
solution, which needs:</p>
<h3 id="install-protoc">Install <code>protoc</code></h3>
<p>The first thing we need is a locally installed <code>protoc</code> bin (I&rsquo;ll used devbox to
install it for consistency across dev environments)</p>
```bash
devbox add protobuf
```
<p>You can add a version specifier for better reproducibility.</p>
<h3 id="runnable-target">Runnable Target</h3>
<p>We also need a shell target that will execute this correctly. The <code>bazel</code> flag
to override <code>protoc</code> takes a local target, not a bin.</p>
<p><code>third_party/tools/BUILD.bazel</code></p>
```python
package(default_visibility = ["//visibility:public"])

sh_binary(
    name = "protoc",
    srcs = ["protoc.sh"],
)

# https://github.com/protocolbuffers/protobuf/blob/b4b0e304be5a68de3d0ee1af9b286f958750f5e4/BUILD#L773
proto_lang_toolchain(
    name = "cc_toolchain",
    command_line = "--cpp_out=$(OUT)",
    runtime = ":protoc",
    visibility = ["//visibility:public"],
)
```
<p><code>third_party/tools/protoc.sh</code></p>
```bash
#!/bin/env bash
protoc "$@"
```
<h3 id="override-protoc">Override protoc</h3>
<p>You should now be able to override <code>protoc</code> with:</p>
```bash
bazel build --proto_compiler=//third_party/tools:protoc ...
```
<p>Having to pass in a flag each time is annoying though, and you can add it to
your <code>.bazelrc</code></p>
```
build --proto_compiler=//third_party/tools:protoc
```
<h3 id="sample-code">Sample code</h3>
<p>You can find the sample code in
<a href="https://github.com/drone-ah/wordsonsand">the wordsonsand repo</a> which uses this
exact solution to override <code>protoc</code> and get the <code>pulumi</code> sample code to work ;)</p>
<p>PS: It also includes a fully migrated <code>MODULES.bazel</code> with support for <code>golang</code>.
You will also want to check out <code>BUILD</code> in the root.</p>]]></content:encoded></item><item><title>Unable to write to $HOME/.pulumi/credentials.json during bazel test</title><link>https://icle.es/2023/11/14/unable-to-write-to-home-pulumi-credentials-json-during-bazel-test/</link><pubDate>Tue, 14 Nov 2023 13:46:46 +0000</pubDate><guid>https://icle.es/2023/11/14/unable-to-write-to-home-pulumi-credentials-json-during-bazel-test/</guid><description>&lt;h1 id="the-problem">The Problem&lt;/h1>
&lt;p>You can add it to your ~/.bazelrc (it needs the path to be absolute)&lt;/p>
&lt;p>From our integration tests, we run &lt;code>pulumi stack output&lt;/code> (or in some cases
&lt;code>pulumi up&lt;/code>) through the automation API before we run the tests so that we can&lt;/p>
&lt;ul>
&lt;li>Confirm that the stack is up&lt;/li>
&lt;li>Get the relevant parameters (actual names of lambdas / dynamo db tables etc.)&lt;/li>
&lt;/ul>
&lt;p>However, since we use bazel for our tests, we ran into a small problem in that
Bazel (rightly) prevents the tests from writing to anything outside the sandbox.
This restrictions results in this error&lt;/p>
```
error: open /home/&lt;username>/.pulumi/credentials.json: read-only file system
```</description><content:encoded><![CDATA[<h1 id="the-problem">The Problem</h1>
<p>You can add it to your ~/.bazelrc (it needs the path to be absolute)</p>
<p>From our integration tests, we run <code>pulumi stack output</code> (or in some cases
<code>pulumi up</code>) through the automation API before we run the tests so that we can</p>
<ul>
<li>Confirm that the stack is up</li>
<li>Get the relevant parameters (actual names of lambdas / dynamo db tables etc.)</li>
</ul>
<p>However, since we use bazel for our tests, we ran into a small problem in that
Bazel (rightly) prevents the tests from writing to anything outside the sandbox.
This restrictions results in this error</p>
```
error: open /home/<username>/.pulumi/credentials.json: read-only file system
```
<h1 id="the-solution">The Solution</h1>
<p>The easiest way to solve this is to ask <code>bazel</code> to allow writing to this
location, which you can do with:</p>
```bash
bazel test ... --sandbox_writable_path=$HOME/.pulumi
```
<p><code>bazel</code> needs to the path to be absolute, so <code>~/.pulumi</code> won't work.</p>
<h1 id="automation">Automation</h1>
<p>It is annoying to add this flag into all the tests, but there is an way to
automatically add it to all tests. You can add it to <code>.bazelrc</code>. Due to the
aforementioned requirement for the path to be absolute, it is not possible to
put it into the git repo root. However, you can put it into your home directory
rool <code>.bazelrc</code></p>
<p><code>$HOME/.bazelrc</code></p>
```
test --sandbox_writable_path=/home/<your-username>/.pulumi
```]]></content:encoded></item><item><title>Separating out integration tests for golang in Bazel</title><link>https://icle.es/2023/11/13/separating-out-integration-tests-for-golang-in-bazel/</link><pubDate>Mon, 13 Nov 2023 13:47:53 +0000</pubDate><guid>https://icle.es/2023/11/13/separating-out-integration-tests-for-golang-in-bazel/</guid><description>&lt;p>There are many kinds of automated tests and two main kinds are integration tests
and unit tests.&lt;/p>
&lt;p>Unit tests are designed to run as fast as possible, so any slower processes like
databases are mocked out. While super helpful and powerful in terms of providing
confidence in the software, it should be only one part of the testing strategy.&lt;/p>
&lt;p>Integration tests, as is implied runs tests of the different part of the
software integrated together. Technically speaking, you can still mock out the
database and other slower layers to keep it running quickly. However, there is
value in including a database or other slower services in the process to test as
them in an automated fashion.&lt;/p>
&lt;p>What this does mean though, is that you want to be able to run only the unit
tests or run the integration tests as well. You might also want to have smoke
tests, which are run on your live production environment.&lt;/p></description><content:encoded><![CDATA[<p>There are many kinds of automated tests and two main kinds are integration tests
and unit tests.</p>
<p>Unit tests are designed to run as fast as possible, so any slower processes like
databases are mocked out. While super helpful and powerful in terms of providing
confidence in the software, it should be only one part of the testing strategy.</p>
<p>Integration tests, as is implied runs tests of the different part of the
software integrated together. Technically speaking, you can still mock out the
database and other slower layers to keep it running quickly. However, there is
value in including a database or other slower services in the process to test as
them in an automated fashion.</p>
<p>What this does mean though, is that you want to be able to run only the unit
tests or run the integration tests as well. You might also want to have smoke
tests, which are run on your live production environment.</p>
<h1 id="how">How</h1>
<p>You could define a separate target in your <code>BUILD</code> file with the unit tests and
let <code>gazelle</code> automatically build your default test target with all the tests. I
found this frustrating to use as I had to keep tweaking the dependencies
manually whenever anything changed (which happened often)</p>
<h2 id="tagging">Tagging</h2>
<p>The easiest way to achieve this for golang and bazel is to tag your source code
files. You can do this by adding the following to the top of your integration
test files</p>
<p><code>something_integration_test.go</code></p>
```go
//go:build integration_test

package somepackage
```
<p>You can pick any tag name you want instead of <code>integration_test</code> like
<code>integration</code>, <code>smoke_test</code> etc.</p>
<h2 id="ide-support">IDE Support</h2>
<p>You will likely need to add this source file into the IDEs build constraints to
get the IDE to treat it as a source file. In IntelliJ (IDEA/Goland), you will be
warned of this</p>
<p>
  <img src="/assets/2023/11/image.png" alt="idea screenshot, main_test.go is ignored by build tool">

</p>
<p>If you click <code>Edit settings</code>, you can add the tag in</p>
<p>
  <img src="/assets/2023/11/image-1.png" alt="set custom tags in build tags">

</p>
<p>When running <code>gazelle</code>, you want to include the files with these tags</p>
<h2 id="gazelle">Gazelle</h2>
```bash
bazel run //:gazelle -- -build_tags=integration_test
```
<p>If you have multiple tags, you can separate them with commas. This command will
generate a test target with all of the source files and its dependencies</p>
<h2 id="bazel-integration-on-test">Bazel Integration on test</h2>
<p>To run only the unit tests, you test as normal:</p>
```bash
bazel test ... # or the specific target, and it'll run only the unit tests
```
<p>To run the integration tests as well, include that tag</p>
```bash
bazel test ... --define  gotags=integration_test # Will run unit & integration tests
```
<h2 id="run-only-unit-tests">Run only Unit Tests</h2>
<p>This setup will currently not allow you to run ONLY the integration tests. To be
able to do that you'll need to add a <code>unit_test</code> tag to the unit test files so
that you can exclude them.</p>
```
something_test.go
```
```go
//go:build integration_test

package somepackage
```
<p>You can then run only the unit tests with</p>
```bash
bazel test … --define gotags=unit_test # Will run unit & integration tests
```
<p>Only the integration tests</p>
```bash
bazel test … --define gotags=integration_test # Will run unit & integration tests
```
<p>Or both:</p>
```bash
bazel test … --define gotags=unit_test,integration_test # Will run unit & integration tests
```
<h2 id="simpler-gazelle-command">Simpler gazelle command</h2>
<p>You can enable the tags by default in the <code>BUILD</code> file so that you don't have
to pass the tags into gazelle each time.</p>
<p><code>BUILD</code></p>
```starlark
# gazelle:build_tags unit_test,integration_test
```
<p>You can then just run <code>bazel run //:gazelle</code> which will run with these tags
enabled.</p>
<h1 id="sample-source">Sample Source</h1>
<p>You can find sample source code demonstrating this in
<a href="https://github.com/drone-ah/wordsonsand">my github repo</a>, under
<a href="https://github.com/drone-ah/wordsonsand/tree/main/post/2023/11/separatetests">post/2023/11/separatetests</a></p>]]></content:encoded></item><item><title>Bazel + Pulumi Automation API. Deploying an inline stack along with Pulumi.[stack].yaml</title><link>https://icle.es/2023/11/07/bazel-pulumi-automation-api-deploying-an-inline-stack-along-with-pulumi-yaml/</link><pubDate>Tue, 07 Nov 2023 15:57:52 +0000</pubDate><guid>https://icle.es/2023/11/07/bazel-pulumi-automation-api-deploying-an-inline-stack-along-with-pulumi-yaml/</guid><description>&lt;p>I believe in CI/CD/CD as in Continuous, integration, delivery and deployment. As
part of this, I am setting up a workflow where on merge to develop (or
main/trunk), the deployment is triggered automatically. Pulumi deploys the
current state of code and infrastructure through GitHub actions and
&lt;a href="https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services">OpenID Connect(OIDC)&lt;/a>
as part of the GitHub Action.&lt;/p>
&lt;p>I used to configure Pulumi to be triggered directly from the build process, but
bazel (as far I know), does not support Pulumi. When I used pants, there was a
custom module, developed by one of the community members which did support
pulumi (You might have to ask in the slack channel if you're interested), but
they stopped maintaining it as they moved to the Pulumi Automation API.&lt;/p></description><content:encoded><![CDATA[<p>I believe in CI/CD/CD as in Continuous, integration, delivery and deployment. As
part of this, I am setting up a workflow where on merge to develop (or
main/trunk), the deployment is triggered automatically. Pulumi deploys the
current state of code and infrastructure through GitHub actions and
<a href="https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services">OpenID Connect(OIDC)</a>
as part of the GitHub Action.</p>
<p>I used to configure Pulumi to be triggered directly from the build process, but
bazel (as far I know), does not support Pulumi. When I used pants, there was a
custom module, developed by one of the community members which did support
pulumi (You might have to ask in the slack channel if you're interested), but
they stopped maintaining it as they moved to the Pulumi Automation API.</p>
<p>I am using Automation API from the start, and configuring a &quot;deployer&quot; per
product/project within the monorepo. The intention is for the deployer to be as
smart as possible - eventually <code>up</code>-ing only the stacks that have changes since
the last time- but that's a way down the line.</p>
<p>Another benefit from the Automation API is to pick up the stack outputs
automatically when running integration/e2e tests, making the test configuration
smoother.</p>
<p>The first step is to be able to define a stack within a product, hook it into
the main iac executable and have it working. My directory structure is roughly
as below: While I am using golang as my language of choice, it's probably not
hugely different in other languages.</p>
<ul>
<li>products
<ul>
<li>productA
<ul>
<li>auth
<ul>
<li>iac_auth
<ul>
<li>BUILD</li>
<li>deploy.go</li>
<li>Pulumi.dev.yaml</li>
<li>Pulumi.yaml</li>
</ul>
</li>
<li>OtherAuthModules</li>
</ul>
</li>
<li>iac
<ul>
<li>BUILD</li>
<li>main.go</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h1 id="iac_authbuild"><code>iac_auth/BUILD</code></h1>
```wp-block-syntaxhighlighter-code
# load etc.
go_library(
    name = "iac_auth",
    srcs = ["deploy.go"],
    data = glob([
        "Pulumi.*.yaml",
    ]) + [
        "Pulumi.yaml",
    ],
    visibility = ["//visibility:public"],
    deps = [
       # dependencies automated with gazelle
    ],
)
```
<h1 id="iac_authdeploy.go"><code>iac_auth/deploy.go</code></h1>
```wp-block-syntaxhighlighter-code
package iac_sync

import (
    "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

const moduleName = "auth"

func DeployGithubLambda(ctx *pulumi.Context) error {
    fmt.Println("Deploy")

    conf := config.Require(ctx, "key")
    fmt.Printf("conf: %s\n", conf) // Will successfully pick up the value if key is in Pulumi.<stack>.yaml

    // Actual deployment code here

    return nil
}
```
<h1 id="iacbuild"><code>iac/BUILD</code></h1>
```wp-block-syntaxhighlighter-code
# other config including standard config of :iac_lib by gazelle

go_binary(
    name = "iac",
    args = [
        "-iac_auth",
        "$(location //products/productA/auth/iac_auth)",
    ],
    data = [
        "//products/gitolink/productA/iac_auth",
    ],
    embed = [":iac_lib"],
    visibility = ["//visibility:public"],
)
```
<p>Worth noting the <code>args</code> bit, which is what we use to identify the path where the
<code>Pulumi.yaml</code> and <code>Pulumi.&lt;stack&gt;.yaml</code> files are:</p>
<h1 id="iacmain.go"><code>iac/main.go</code></h1>
```wp-block-syntaxhighlighter-code
package main

import (
    "context"
    "flag"
    "fmt"
    iacAuth "github.com/drone-ah/monorepo/products/gitolink/auth/iac_auth"
    "github.com/pulumi/pulumi/sdk/v3/go/auto"
    "path/filepath"
)

func main() {

    // Pick up the path from args
    var iacAuthPath = flag.String("iac_auth", "", "bin for iac_auth")
    flag.Parse()
    fmt.Printf("param iac: %s \n", *iacAuthPath)

    ctx := context.Background()

    projectName := "gitolink"
    stackName := "dev"

    stack, err := auto.NewStackInlineSource(ctx,
        stackName,
        projectName,
        iacAuth.DeployGithubLambda,
        // Define workdir for locatin of the Pulumi yaml files
        auto.WorkDir(filepath.Dir(*iacAuthPath)))

    preview, err := stack.Preview(ctx)

    fmt.Println(err)
    fmt.Println(preview)
}
```
<p>You might also have to use <code>RLocation</code> (see my previous post about
<a href="https://drone-ah.com/2023/11/01/including-a-built-artifact-in-another-target-bazel-golang/">including an artifact in another target</a>
for an example of this), though when I tried it, it was missing one of the yaml
files and I didn't investigate further.</p>]]></content:encoded></item><item><title>Including a built artifact in another target (Bazel, golang)</title><link>https://icle.es/2023/11/01/including-a-built-artifact-in-another-target-bazel-golang/</link><pubDate>Wed, 01 Nov 2023 19:42:30 +0000</pubDate><guid>https://icle.es/2023/11/01/including-a-built-artifact-in-another-target-bazel-golang/</guid><description>&lt;p>We use pulumi to do IaC and we use a monorepo with Bazel as the build tool. We
have out modules set out as following&lt;/p>
&lt;p>One of the requirements we have is to build a lambda module and then deploy it.
The lambda module is a target being built by Bazel (golang, but shouldn't
matter):&lt;/p>
```go
go_binary(
 name = "lambda_module",
 visibility = ["//visibility:public"],
)
```</description><content:encoded><![CDATA[<p>We use pulumi to do IaC and we use a monorepo with Bazel as the build tool. We
have out modules set out as following</p>
<p>One of the requirements we have is to build a lambda module and then deploy it.
The lambda module is a target being built by Bazel (golang, but shouldn't
matter):</p>
```go
go_binary(
    name = "lambda_module",
    visibility = ["//visibility:public"],
)
```
<p>We then have the iac module, which should get the built version of the above
module, so that it can then upload it into lambda</p>
```go
go_binary(
    name = "iac",
    args = [
        "-lambda_module",
        "$(location //products/productA/module/lambda_module)",
    ],
    data = ["//products/productA/module/lambda_module"],
    visibility = ["//visibility:public"],
)
```
<p>There are two key parameters here to note:</p>
<ul>
<li><code>args</code>: We generate the path to the target module using
<code> //products/productA/module/lambda_module)</code></li>
<li><code>data</code>: We use the data tag to ensure that the built output is included when
building/running this target</li>
</ul>
<p>We then need to use runfiles support within golang to be ablet to identify the
correct location for the built binary. The reason this part is complex is to be
able to support multiple operating systems. I should caveat that I have only got
this working on Linux, but Mac/Win shouldn't be too different.</p>
```go
package main

import (
    _ "embed"
    "flag"
    "fmt"
    "github.com/bazelbuild/rules_go/go/runfiles"
    "path/filepath"
)

func main() {

    var webhookAuth = flag.String("webhook_auth", "", "bin for webhook_auth")
    flag.Parse()
    fmt.Printf("param : %s \n", *webhookAuth)

    path, err := runfiles.Rlocation(fmt.Sprintf("workspace_name/%s", *webhookAuth))
    fmt.Printf("rLoc path: %s, err: %v \n", path, err)

    symlinks, err := filepath.EvalSymlinks(path)
    fmt.Printf("evaluated path: %s, err: %v \n", symlinks, err)

}
```
<p>We use the flag module to retrieve the path passed in as a runtime parameter</p>
<p>We use <code>runfiles.Rlocation</code> to pick up the &quot;real&quot; path to the file, prepending
the workspace name to the start. You can
<a href="https://bazel.build/rules/lib/globals/workspace#workspace">define the workspace name</a>
in the root WORKSPACE file with <code>workspace(name = &quot;workspace_name&quot;)</code></p>
<p>Finally, resolve the Symlink to get the actual file path</p>
<h2 id="references">References</h2>
<p>There are similar mechanisms to find the rLocation in other languages, a couple
of which are described in
<a href="https://docs.google.com/document/d/e/2PACX-1vSDIrFnFvEYhKsCMdGdD40wZRBX3m3aZ5HhVj4CtHPmiXKDCxioTUbYsDydjKtFDAzER5eg7OjJWs3V/pub">its design document</a></p>
<p>There is some documentation in <code>rules_go</code> around
<a href="https://github.com/bazelbuild/rules_go#how-do-i-access-go_binary-executables-from-go_test">accessing <code>go_binary</code> from <code>go_test</code></a>
which I referenced and updated to get the above example</p>
<p>I found the above link from
<a href="https://stackoverflow.com/questions/70193581/feed-bazel-output-to-another-bazel-rule">a stackoverflow post about feeding bazel output to another bazel rule</a></p>]]></content:encoded></item><item><title>Eclipse TPTP on Ubuntu (64bit)</title><link>https://icle.es/2008/12/28/eclipse-tptp-on-ubuntu-64bit/</link><pubDate>Sun, 28 Dec 2008 18:15:45 +0000</pubDate><guid>https://icle.es/2008/12/28/eclipse-tptp-on-ubuntu-64bit/</guid><description>&lt;p>I run ubuntu 64 bit (technically, I run an ubuntu 64bit vserver which I access
from ubuntu 32 bit but thats not really relevant).&lt;/p>
&lt;p>In the open source world, I expect that all things which are accessible as 32bit
are also accessible and 64bit and ubuntu makes it automagic enough that
everything just works. Yes, I run into problems with closed source software like
Flash Player (recently resolved with flash player 10) and the Java Plugin but
that is another story. I use Eclipse and wanted to do some performance analysis
and benchmarking to find a bottleneck and installed the TPTP plugin; and ran
into a problem. It just didn&amp;rsquo;t work.&lt;/p></description><content:encoded><![CDATA[<p>I run ubuntu 64 bit (technically, I run an ubuntu 64bit vserver which I access
from ubuntu 32 bit but thats not really relevant).</p>
<p>In the open source world, I expect that all things which are accessible as 32bit
are also accessible and 64bit and ubuntu makes it automagic enough that
everything just works. Yes, I run into problems with closed source software like
Flash Player (recently resolved with flash player 10) and the Java Plugin but
that is another story. I use Eclipse and wanted to do some performance analysis
and benchmarking to find a bottleneck and installed the TPTP plugin; and ran
into a problem. It just didn&rsquo;t work.</p>
<p>To resolve it, I turned to google&hellip; In this instance, it turned out to be a
distraction and a red-herring. It lead me in the direction of installing
libstdc++2.10-glibc2.2_2.95.4-27_i386.deb which was difficult at best since
there was only a 32bit version of the package and that wasn&rsquo;t even in the
standard repository.</p>
<p>In the end, digging deeper, I found that it simply missed the following shared
object libstdc++.so.5.</p>
<p>All I had to do was install libstdc++5:</p>
```bash
sudo aptitude install libstdc++5
```
<p>and it worked&hellip; :-D</p>
<p>Now, I think that ACServer which Eclipse uses to do TPTP should not link to an
outdated library but that is another issue&hellip;</p>
]]></content:encoded></item></channel></rss>