Skip to content

Commit

Permalink
[Dev] Add clang toolchains
Browse files Browse the repository at this point in the history
  • Loading branch information
lshmouse committed Sep 19, 2024
1 parent 399f838 commit a2de2d6
Show file tree
Hide file tree
Showing 30 changed files with 304 additions and 20 deletions.
Empty file added BUILD
Empty file.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ TODO
- Thanks to jiaming: https://github.com/storypku
- https://github.com/ApolloAuto/apollo
- See: https://github.com/kriscfoster/multi-language-bazel-monorepo
- https://github.com/yechuan51/multi-language-bazel-monorepo
45 changes: 44 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
workspace(name = "ai_playground")

load("//bazel:workspace.bzl", "repositories")

repositories()

# Load the LLVM toolchain
load("@toolchains_llvm//toolchain:deps.bzl", "bazel_toolchain_dependencies")
bazel_toolchain_dependencies()

load("@toolchains_llvm//toolchain:rules.bzl", "llvm_toolchain")
llvm_toolchain(
name = "llvm_toolchain",
llvm_version = "16.0.0",
)

load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")
llvm_register_toolchains()

### Python Setup
load("@rules_python//python:pip.bzl", "pip_install")

pip_install(
name = "pip",
requirements = "//bazel/python:requirements.txt",
)

### Gazelle Setup
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
### Golang Setup
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
go_rules_dependencies()
go_register_toolchains(version = "1.18")
gazelle_dependencies()

load("//bazel/go:deps.bzl", "go_dependencies")
go_dependencies()

### Rust Setup
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
rules_rust_dependencies()
rust_register_toolchains()

### Docker Setup
load("@io_bazel_rules_docker//repositories:repositories.bzl", container_repositories = "repositories")
container_repositories()

load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")
container_deps()
Empty file added bazel/go/BUILD
Empty file.
67 changes: 67 additions & 0 deletions bazel/go/deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
load("@bazel_gazelle//:deps.bzl", "go_repository")

def go_dependencies():
go_repository(
name = "com_github_cpuguy83_go_md2man_v2",
importpath = "github.com/cpuguy83/go-md2man/v2",
sum = "h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=",
version = "v2.0.2",
)
go_repository(
name = "com_github_go_logr_logr",
importpath = "github.com/go-logr/logr",
sum = "h1:QK40JKJyMdUDz+h+xvCsru/bJhvG0UxvePV0ufL/AcE=",
version = "v1.2.0",
)

go_repository(
name = "com_github_inconshreveable_mousetrap",
importpath = "github.com/inconshreveable/mousetrap",
sum = "h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=",
version = "v1.0.0",
)

go_repository(
name = "com_github_russross_blackfriday_v2",
importpath = "github.com/russross/blackfriday/v2",
sum = "h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=",
version = "v2.1.0",
)
go_repository(
name = "com_github_spf13_cobra",
importpath = "github.com/spf13/cobra",
sum = "h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=",
version = "v1.5.0",
)
go_repository(
name = "com_github_spf13_pflag",
importpath = "github.com/spf13/pflag",
sum = "h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=",
version = "v1.0.5",
)

go_repository(
name = "in_gopkg_check_v1",
importpath = "gopkg.in/check.v1",
sum = "h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=",
version = "v0.0.0-20161208181325-20d25e280405",
)

go_repository(
name = "in_gopkg_yaml_v2",
importpath = "gopkg.in/yaml.v2",
sum = "h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=",
version = "v2.4.0",
)
go_repository(
name = "io_k8s_klog_v2",
importpath = "k8s.io/klog/v2",
sum = "h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4=",
version = "v2.80.1",
)
go_repository(
name = "com_github_gorilla_mux",
importpath = "github.com/gorilla/mux",
sum = "h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=",
version = "v1.8.0",
)
Empty file added bazel/python/BUILD
Empty file.
3 changes: 3 additions & 0 deletions bazel/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Werkzeug==2.2.2
Flask==2.0.2
kubernetes==27.2.0
26 changes: 22 additions & 4 deletions bazel/workspace.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# external dependencies that can be loaded in WORKSPACE files.

load("//third_party/toolchains_llvm:workspace.bzl", toolchains_llvm = "repo")
load("//third_party/bazel_gazelle:workspace.bzl", bazel_gazelle = "repo")
load("//third_party/rules_python:workspace.bzl", rules_python = "repo")
load("//third_party/rules_foreign_cc:workspace.bzl", rules_foreign_cc = "repo")
load("//third_party/pybind11:workspace.bzl", pybind11 = "repo")
load("//third_party/rules_proto:workspace.bzl", rules_proto = "repo")
load("//third_party/rules_go:workspace.bzl", rules_go = "repo")
load("//third_party/rules_rust:workspace.bzl", rules_rust = "repo")

load("//third_party/rules_docker:workspace.bzl", rules_docker = "repo")

load("//third_party/cpplint:workspace.bzl", cpplint = "repo")

load("//third_party/glog:workspace.bzl", glog = "repo")
Expand All @@ -13,21 +21,31 @@ load("//third_party/protobuf:workspace.bzl", protobuf = "repo")

load("//third_party/absl:workspace.bzl", absl = "repo")

def initialize_language_repos():
toolchains_llvm()
bazel_gazelle()

rules_proto()
rules_foreign_cc()
rules_python()
pybind11()
rules_go()

rules_rust()
rules_docker()

def initialize_third_parties():
""" Load third party repositories. See above load() statements. """
rules_python()
rules_foreign_cc()
rules_proto()
cpplint()

glog()
gflags()
gtest()
benchmark()
protobuf()

absl()

# Define all external repositories required by
def repositories():
initialize_language_repos()
initialize_third_parties()
17 changes: 17 additions & 0 deletions experimental/go_example/go_web/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
name = "go_web_lib",
srcs = ["main.go"],
importpath = "github.com/lshmouse/ai-playground/experimental/go_example/go_web",
visibility = ["//visibility:private"],
deps = [
"@com_github_gorilla_mux//:mux",
],
)

go_binary(
name = "go_web",
embed = [":go_web_lib"],
visibility = ["//visibility:public"],
)
33 changes: 33 additions & 0 deletions experimental/go_example/go_web/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"log"
"net/http"
"os"

"github.com/gorilla/mux"
)

func YourHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Received request")
w.Write([]byte("Bazoku is cool!!"))
}

func getPort() string {
port := os.Getenv("PORT")
if port == "" {
return "8080"
}

return port
}

func main() {
r := mux.NewRouter()
// Routes consist of a path and a handler function.
r.HandleFunc("/", YourHandler)
// Bind to a port and pass our router in
port := getPort()
log.Println("Going to listen on port: " + port)
log.Fatal(http.ListenAndServe(":"+port, r))
}
22 changes: 22 additions & 0 deletions experimental/python_example/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@pip//:requirements.bzl", "requirement")

py_binary(
name = "python_cli",
srcs = ["python_cli.py"],
)

py_library(
name = "python_web_lib",
srcs = ["python_web.py"],
deps = [
requirement("Flask"),
],
)

py_binary(
name = "python_web",
srcs = ["python_web.py"],
main = "python_web.py",
deps = [":python_web_lib"],
)
File renamed without changes.
10 changes: 10 additions & 0 deletions experimental/python_example/python_web.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
return "hello world"

if __name__ == '__main__':
app.run(host='0.0.0.0')
1 change: 1 addition & 0 deletions third_party/bazel_gazelle/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package(default_visibility = ["//visibility:public"])
2 changes: 2 additions & 0 deletions third_party/bazel_gazelle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## bazel_gazelle
See: https://github.com/bazelbuild/bazel-gazelle
13 changes: 13 additions & 0 deletions third_party/bazel_gazelle/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Loads the bazel_gazelle library"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def repo():
http_archive(
name = "bazel_gazelle",
sha256 = "efbbba6ac1a4fd342d5122cbdfdb82aeb2cf2862e35022c752eaddffada7c3f3",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz",
],
)
1 change: 1 addition & 0 deletions third_party/rules_docker/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package(default_visibility = ["//visibility:public"])
10 changes: 10 additions & 0 deletions third_party/rules_docker/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Loads the rules_docker library"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def repo():
http_archive(
name = "io_bazel_rules_docker",
sha256 = "b1e80761a8a8243d03ebca8845e9cc1ba6c82ce7c5179ce2b295cd36f7e394bf",
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.25.0/rules_docker-v0.25.0.tar.gz"],
)
1 change: 1 addition & 0 deletions third_party/rules_go/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package(default_visibility = ["//visibility:public"])
2 changes: 2 additions & 0 deletions third_party/rules_go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## rules_go
See: https://github.com/bazelbuild/rules_go
11 changes: 11 additions & 0 deletions third_party/rules_go/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def repo():
http_archive(
name = "io_bazel_rules_go",
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
],
)
9 changes: 1 addition & 8 deletions third_party/rules_python/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
load("@rules_python//python:defs.bzl", "py_binary")

package(default_visibility = ["//visibility:public"])

py_binary(
name = "example",
srcs = ["example.py"],
)
package(default_visibility = ["//visibility:public"])
6 changes: 6 additions & 0 deletions third_party/rules_python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## rules_python

See: https://rules-python.readthedocs.io/

### references
- https://github.com/bazelbuild/rules_python
11 changes: 4 additions & 7 deletions third_party/rules_python/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ def clean_dep(dep):
return str(Label(dep))

def repo():
version = "0.8.1"
http_archive(
name = "rules_python",
strip_prefix = "rules_python-{}".format(version),
sha256 = "cdf6b84084aad8f10bf20b46b77cb48d83c319ebe6458a18e9d2cebf57807cdd",
urls = [
"https://github.com/bazelbuild/rules_python/archive/{}.tar.gz".format(version),
],
)
sha256 = "b593d13bb43c94ce94b483c2858e53a9b811f6f10e1e0eedc61073bd90e58d9c",
strip_prefix = "rules_python-0.12.0",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.12.0.tar.gz",
)
1 change: 1 addition & 0 deletions third_party/rules_rust/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package(default_visibility = ["//visibility:public"])
2 changes: 2 additions & 0 deletions third_party/rules_rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## rules_rust
See: https://bazelbuild.github.io/rules_rust/
12 changes: 12 additions & 0 deletions third_party/rules_rust/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Loads the rules_proto library"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def repo():
# To find additional information on this release or newer ones visit:
# https://github.com/bazelbuild/rules_rust/releases
http_archive(
name = "rules_rust",
integrity = "sha256-Weev1uz2QztBlDA88JX6A1N72SucD1V8lBsaliM0TTg=",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.48.0/rules_rust-v0.48.0.tar.gz"],
)
1 change: 1 addition & 0 deletions third_party/toolchains_llvm/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package(default_visibility = ["//visibility:public"])
2 changes: 2 additions & 0 deletions third_party/toolchains_llvm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## toolchains_llvm
See: https://github.com/bazel-contrib/toolchains_llvm
Loading

0 comments on commit a2de2d6

Please sign in to comment.