Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Add bazel container #47

Merged
merged 10 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json

# Bazel
bazel-*

# StyleCop
StyleCopReport.xml

Expand Down
34 changes: 34 additions & 0 deletions containers/bazel/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
FROM debian:9

# Configure apt
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils 2>&1

# Install git, process tools, lsb-release (common in install instructions for CLIs)
RUN apt-get -y install git procps lsb-release

# Install Bazel
ENV BAZEL_VERSION=0.25.2
ENV BAZEL_SHA256=5b9ab8a68c53421256909f79c47bde76a051910217531cbf35ee995448254fa7
RUN apt-get -y install curl pkg-config zip g++ zlib1g-dev unzip python
RUN curl -fSsL -o bazel-installer.sh https://github.com/bazelbuild/bazel/releases/download/0.25.2/bazel-0.25.2-installer-linux-x86_64.sh \
&& echo "${BAZEL_SHA256} *bazel-installer.sh" | sha256sum --check - \
&& chmod +x bazel-installer.sh \
&& ./bazel-installer.sh \
&& rm ./bazel-installer.sh

RUN echo '\n\
export PATH="$PATH:$HOME/bin" \n\
'\
>> $HOME/.bashrc

# Clean up
RUN apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
ENV DEBIAN_FRONTEND=dialog
17 changes: 17 additions & 0 deletions containers/bazel/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Bazel",
"dockerFile": "Dockerfile",

// Uncomment the next line to automatically install extensions.
"extensions": ["devondcarew.bazel-code"],

// Uncomment the next line if you want to publish any ports.
// "appPort": [],

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "uname -a",

// Uncomment the next line if you will use a ptrace-based debugger like C++, Go, and Rust.
// "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ]

}
4 changes: 4 additions & 0 deletions containers/bazel/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
README.md
test-project
.vscode
.npmignore
17 changes: 17 additions & 0 deletions containers/bazel/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "cd test-project && bazel build",
"type": "shell",
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
48 changes: 48 additions & 0 deletions containers/bazel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Bazel

## Summary

*Develop and compile efficiently on any language with the Bazel compilation tool.*

| Metadata | Value |
|----------|-------|
| *Contributors* | William Phetsinorath <deva.shikanime@protonmail.com> |
| *Definition type* | Dockerfile |
| *Languages, platforms* | All platforms |

## Using this definition with an existing folder

Just follow these steps:

1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine.

2. To use VS Code's copy of this definition:
1. Start VS Code and open your project folder.
2. Press <kbd>F1</kbd> select and **Remote-Containers: Create Container Configuration File...** from the command palette.
3. Select the Dart definition.

3. To use latest-and-greatest copy of this definition from the repository:
1. Clone this repository.
2. Copy the contents of this folder in the cloned repository to the root of your project folder.
3. Start VS Code and open your project folder.

4. After following step 2 or 3, the contents of the `.devcontainer` folder in your project can be adapted to meet your needs.

5. Finally, press <kbd>F1</kbd> and run **Remote-Containers: Reopen Folder in Container** to start using the definition.

## Testing the definition

This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps:

1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine.
2. Clone this repository.
3. Start VS Code, press <kbd>F1</kbd>, and select **Remote-Containers: Open Folder in Container...**
4. Select this folder from the cloned repository.
5. Press <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>\`</kbd> and type the following command to verify installation: `bazel run //test-project:hello-world`
6. You should see "Hello remote world!" in the Debug Console after the program executes.

## License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License. See [LICENSE](https://github.com/Microsoft/vscode-dev-containers/blob/master/LICENSE).
1 change: 1 addition & 0 deletions containers/bazel/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace(name = "hello_world")
24 changes: 24 additions & 0 deletions containers/bazel/test-project/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "hello-lib",
srcs = ["hello-lib.cc"],
hdrs = ["hello-lib.h"],
)

cc_binary(
name = "hello-world",
srcs = ["hello-world.cc"],
deps = [":hello-lib"],
)

cc_test(
name = "hello-test",
srcs = ["hello-world.cc"],
deps = [":hello-lib"],
)

filegroup(
name = "srcs",
srcs = glob(["**"]),
)
22 changes: 22 additions & 0 deletions containers/bazel/test-project/hello-lib.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "./hello-lib.h"

#include <iostream>

using std::cout;
using std::endl;
using std::string;

namespace hello
{

HelloLib::HelloLib(const string &greeting)
: greeting_(new string(greeting))
{
}

void HelloLib::greet(const string &thing)
{
cout << *greeting_ << " " << thing << endl;
}

} // namespace hello
23 changes: 23 additions & 0 deletions containers/bazel/test-project/hello-lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef EXAMPLES_CPP_HELLO_LIB_H_
#define EXAMPLES_CPP_HELLO_LIB_H_

#include <string>
#include <memory>

namespace hello
{

class HelloLib
{
public:
explicit HelloLib(const std::string &greeting);

void greet(const std::string &thing);

private:
std::unique_ptr<const std::string> greeting_;
};

} // namespace hello

#endif // EXAMPLES_CPP_HELLO_LIB_H_
28 changes: 28 additions & 0 deletions containers/bazel/test-project/hello-world.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "./hello-lib.h"

#include <string>

using hello::HelloLib;
using std::string;

/**
* This prints "Hello world". If it is run with arguments, it will use the first
* argument instead of "world". Build and run //examples/cpp:hello-world to see
* this program in action.
*
* This file does double-duty as a "test." It is a cc_binary, so it can also be
* compiled as a cc_test and Bazel will decide on whether it passed or failed
* based on exit code (which is always 0 here, so the test "passes"). See
* hello-fail.cc for an example of making a test fail.
*/
int main(int argc, char **argv)
{
HelloLib lib("Hello");
string thing = "world";
if (argc > 1)
{
thing = argv[1];
}
lib.greet(thing);
return 0;
}