-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45f75b7
commit 2264a8b
Showing
6 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
venv | ||
bazel-* | ||
__pycache__ | ||
MODULE.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Installation (currently only works on linux) | ||
|
||
* Install Bazelisk | ||
* `wget https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0/bazelisk-linux-amd64` | ||
* `chmod +x bazelisk-linux-amd64` | ||
* `sudo mv bazelisk-linux-amd64 /usr/local/bin/bazel` | ||
* `python3.11 -m venv venv --prompt modal-cpp-example` | ||
* `source venv/bin/activate` | ||
* `pip install modal` | ||
|
||
# Running example | ||
|
||
* `bazel build //main:hello-world --sandbox_add_mount_pair=/tmp` | ||
* `source venv/bin/activate` | ||
* `modal run run_binary_modal.py` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "aspect_gcc_toolchain", | ||
sha256 = "3341394b1376fb96a87ac3ca01c582f7f18e7dc5e16e8cf40880a31dd7ac0e1e", | ||
strip_prefix = "gcc-toolchain-0.4.2", | ||
urls = [ | ||
"https://github.com/aspect-build/gcc-toolchain/archive/refs/tags/0.4.2.tar.gz", | ||
], | ||
) | ||
|
||
load("@aspect_gcc_toolchain//toolchain:repositories.bzl", "gcc_toolchain_dependencies") | ||
|
||
gcc_toolchain_dependencies() | ||
|
||
load("@aspect_gcc_toolchain//toolchain:defs.bzl", "gcc_register_toolchain", "ARCHS") | ||
|
||
gcc_register_toolchain( | ||
name = "gcc_toolchain_x86_64", | ||
target_arch = ARCHS.x86_64, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
load("@rules_cc//cc:defs.bzl", "cc_binary") | ||
|
||
cc_binary( | ||
name = "hello-world", | ||
srcs = ["hello-world.cc"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <ctime> | ||
#include <string> | ||
#include <iostream> | ||
|
||
std::string get_greet(const std::string& who) { | ||
return "Hello " + who; | ||
} | ||
|
||
void print_localtime() { | ||
std::time_t result = std::time(nullptr); | ||
std::cout << std::asctime(std::localtime(&result)); | ||
} | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from modal import App, Mount | ||
import os | ||
|
||
app = App("example-modal-bazel-cpp") | ||
|
||
CWD = os.getcwd() | ||
LOCAL_REL_PATH= "bazel-bin/main/hello-world" | ||
REMOTE_PATH = "/root/my-binary" | ||
|
||
@app.function(mounts=[Mount.from_local_file(local_path=f"{CWD}/{LOCAL_REL_PATH}", remote_path=REMOTE_PATH)]) | ||
def f(): | ||
import subprocess | ||
subprocess.run(REMOTE_PATH) |