Skip to content

Commit

Permalink
Merge pull request #2 from gvatsal60/feature/add_files
Browse files Browse the repository at this point in the history
Added Files
  • Loading branch information
gvatsal60 authored Nov 13, 2024
2 parents 8d7d7b2 + 0ee7c99 commit bd076b6
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 3 deletions.
68 changes: 68 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# ##########################################################################
# File: Dockerfile
# Author: Vatsal Gupta (gvatsal60)
# Date: 08-Nov-2024
# Description: TBD
# ##########################################################################

# ##########################################################################
# License
# ##########################################################################
# This Dockerfile is licensed under the Apache 2.0 License.

# ##########################################################################
# Base Image
# ##########################################################################
FROM gcr.io/bazel-public/bazel:latest AS base

# ##########################################################################
# Maintainer
# ##########################################################################
LABEL maintainer="Vatsal Gupta (gvatsal60)"

# ##########################################################################
# Install Dependencies
# ##########################################################################
USER root

RUN apt-get update \
&& apt-get -y install --no-install-recommends \
apt-transport-https \
apt-utils \
bash-completion \
build-essential \
ca-certificates \
curl \
git \
&& apt-get -y clean \
&& rm -rf /var/lib/apt/lists/*

# Add buildifier
ARG BUILDIFIER_BIN_PATH="/usr/local/bin/buildifier"
ARG BUILDIFIER_VER=v7.3.1
ARG BUILDIFIER_LINK=https://github.com/bazelbuild/buildtools/releases/download/${BUILDIFIER_VER}/buildifier-linux-amd64

ADD ${BUILDIFIER_LINK} ${BUILDIFIER_BIN_PATH}
RUN chmod +x ${BUILDIFIER_BIN_PATH}

# ##########################################################################
# USER
# ##########################################################################
USER ubuntu

# ##########################################################################
# Copy Files
# ##########################################################################

# ##########################################################################
# Set Working Directory
# ##########################################################################

# ##########################################################################
# Expose Port
# ##########################################################################

# ##########################################################################
# Command to Run
# ##########################################################################
CMD ["/bin/bash"]
19 changes: 17 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
{
"build": {
"context": ".",
"dockerfile": "Dockerfile"
},
"capAdd": [
"SYS_PTRACE"
],
"customizations": {
"vscode": {
"extensions": [
"BazelBuild.vscode-bazel",
"DavidAnson.vscode-markdownlint",
"Gruntfuggly.todo-tree",
"PKief.material-icon-theme",
"SonarSource.sonarlint-vscode",
"Tyriar.sort-lines",
"bradzacher.vscode-copy-filename",
"esbenp.prettier-vscode",
"foxundermoon.shell-format",
"gurumukhi.selected-lines-count",
"llvm-vs-code-extensions.vscode-clangd",
"ms-azuretools.vscode-docker",
"ms-vscode.cpptools",
"streetsidesoftware.code-spell-checker",
"usernamehw.errorlens"
],
Expand Down Expand Up @@ -48,6 +56,13 @@
"editor.tabSize": 4,
"files.eol": "\n"
},
"[starlark]": {
"editor.defaultFormatter": "BazelBuild.vscode-bazel"
},
"clangd.arguments": [
"-background-index",
"-compile-commands-dir=${localWorkspaceFolder}"
],
"editor.bracketPairColorization.enabled": true,
"editor.comments.insertSpace": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
Expand Down Expand Up @@ -76,6 +91,7 @@
"**/bower_components": true,
"**/node_modules": true
},
"sonarlint.pathToCompileCommands": "${localWorkspaceFolder}/compile_commands.json",
"telemetry.telemetryLevel": "off",
"windows.title": "${folderPath}",
"workbench.iconTheme": "material-icon-theme",
Expand All @@ -86,9 +102,8 @@
"features": {
"ghcr.io/gvatsal60/dev-container-features/sonarlint": {}
},
"image": "mcr.microsoft.com/devcontainers/base:noble",
"mounts": [
"source=${containerWorkspaceFolder}/snippets,target=${containerWorkspaceFolder}/.vscode,type=bind,consistency=cached,readonly"
"source=${localWorkspaceFolder:-./}/snippets,target=${containerWorkspaceFolder}/.vscode,type=bind,consistency=cached,readonly"
],
"postCreateCommand": "chmod +x ${containerWorkspaceFolder}/.devcontainer/postCreateScript.sh && ${containerWorkspaceFolder}/.devcontainer/postCreateScript.sh",
"runArgs": [
Expand Down
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ coverage/
# Binaries, node_modules, and other folders #
############################################
bin/
lib/
dist/
bower_components/
*.min.js

# Bazel
bazel-bin
bazel-genfiles
bazel-googletest
bazel-out
bazel-testlogs
MODULE.bazel.lock
bazel-Bazel_Cpp_Template
17 changes: 17 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
###############################################################################
# Bazel now uses Bzlmod by default to manage external dependencies.
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
#
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
###############################################################################

# Hedron's Compile Commands Extractor for Bazel
# https://github.com/hedronvision/bazel-compile-commands-extractor
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
git_override(
module_name = "hedron_compile_commands",
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
commit = "4f28899228fb3ad0126897876f147ca15026151e",
# Replace the commit hash (above) with the latest (https://github.com/hedronvision/bazel-compile-commands-extractor/commits/main).
# Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
)
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Targets
.PHONY: all
all:
.PHONY: test
test:
.PHONY: clean
clean:

sonar:
bazel run @hedron_compile_commands//:refresh_all -- --compilation_mode=dbg
Empty file added WORKSPACE
Empty file.
25 changes: 25 additions & 0 deletions project/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cc_library(
name = "newlib",
hdrs = glob([
"lib/inc/*.h",
"inc/*.h",
]),
visibility = ["//visibility:public"],
)

cc_binary(
name = "main",
srcs = glob(["src/*.cc"]), # Automatically include all .cc files in src/
cxxopts = [
"-Iproject/inc",
"-Iproject/lib/inc",
],
includes = [
"inc", # Add inc directory to search paths for header files
"lib/inc", # Add lib/inc directory for hello-time headers
],
deps = [
":newlib",
"//project/lib:hello-time", # Use the correct target name: //project/lib:hello-time
],
)
5 changes: 5 additions & 0 deletions project/inc/hello-greet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <string>

std::string get_greet(const std::string &thing);
7 changes: 7 additions & 0 deletions project/lib/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cc_library(
name = "hello-time",
srcs = glob(["src/*.cc"]), # Automatically include all .cc files in lib/src/
hdrs = glob(["inc/*.h"]), # Automatically include all .h files in lib/inc/
includes = ["inc"], # Include lib/inc in the include search path
visibility = ["//project:__pkg__"], # Make hello-time visible to the main target
)
3 changes: 3 additions & 0 deletions project/lib/inc/hello-time.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void print_localtime();
8 changes: 8 additions & 0 deletions project/lib/src/hello-time.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "hello-time.h"
#include <ctime>
#include <iostream>

void print_localtime() {
std::time_t result = std::time(nullptr);
std::cout << std::asctime(std::localtime(&result));
}
4 changes: 4 additions & 0 deletions project/src/hello-greet.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "hello-greet.h"
#include <string>

std::string get_greet(const std::string &who) { return "Hello " + who; }
15 changes: 15 additions & 0 deletions project/src/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "hello-greet.h"
#include "hello-time.h"
#include <iostream>
#include <string>

int main(int argc, char **argv) {
std::string who = "world";
if (argc > 1) {
who = argv[1];
}
std::cout << get_greet(who) << std::endl;
print_localtime();

return 0;
}

0 comments on commit bd076b6

Please sign in to comment.