From 1838dc11fe9a489ac465aa61df3384c8ade8b4a9 Mon Sep 17 00:00:00 2001 From: PikachuHy Date: Sat, 3 Feb 2024 16:57:22 +0800 Subject: [PATCH] [language binding] add c-api, java-api and python-api --- .github/workflows/linux_bazel.yml | 3 + .github/workflows/macos_bazel.yml | 5 +- .gitignore | 2 + BUILD.bazel | 9 +++ WORKSPACE.bazel | 60 ++++++++++++++- android/app/src/main/BUILD.bazel | 12 +-- android/app/src/main/cpp/native-lib.cpp | 28 ------- .../java/dev/pscm/android/MainActivity.java | 19 ++--- binding/c/BUILD.bazel | 9 +++ binding/c/pscm_c_api.cpp | 27 +++++++ binding/c/pscm_c_api.h | 8 ++ binding/java/BUILD.bazel | 73 +++++++++++++++++++ binding/java/dev/pscm/PSCMScheme.java | 27 +++++++ binding/java/example/PSCMSchemeExample.java | 17 +++++ binding/java/pscm_java_binding.cpp | 19 +++++ binding/java/test/PSCMSchemeTest.java | 26 +++++++ binding/python/BUILD.bazel | 32 ++++++++ binding/python/pscm_python_api_example.py | 6 ++ binding/python/pscm_python_api_test.py | 19 +++++ binding/python/pscm_python_binding.cpp | 29 ++++++++ docs/.vitepress/config.ts | 4 + docs/cn/how_to_build_pscm.md | 6 ++ docs/cn/language_binding.md | 61 ++++++++++++++++ requirements.txt | 1 + toolchains/BUILD.bazel | 20 +++++ 25 files changed, 470 insertions(+), 52 deletions(-) delete mode 100644 android/app/src/main/cpp/native-lib.cpp create mode 100644 binding/c/BUILD.bazel create mode 100644 binding/c/pscm_c_api.cpp create mode 100644 binding/c/pscm_c_api.h create mode 100644 binding/java/BUILD.bazel create mode 100644 binding/java/dev/pscm/PSCMScheme.java create mode 100644 binding/java/example/PSCMSchemeExample.java create mode 100644 binding/java/pscm_java_binding.cpp create mode 100644 binding/java/test/PSCMSchemeTest.java create mode 100644 binding/python/BUILD.bazel create mode 100644 binding/python/pscm_python_api_example.py create mode 100644 binding/python/pscm_python_api_test.py create mode 100644 binding/python/pscm_python_binding.cpp create mode 100644 docs/cn/language_binding.md create mode 100644 requirements.txt create mode 100644 toolchains/BUILD.bazel diff --git a/.github/workflows/linux_bazel.yml b/.github/workflows/linux_bazel.yml index be870abc..63df6c97 100644 --- a/.github/workflows/linux_bazel.yml +++ b/.github/workflows/linux_bazel.yml @@ -27,6 +27,9 @@ jobs: - name: Test run: bazel test \:all --test_output=errors + - name: Test Java Binding + run: bazel run //binding/java:pscm_java_api_test + - name: Build Android App run: bazel build //android/app/src/main:app --android_crosstool_top=@androidndk//:toolchain --fat_apk_cpu=arm64-v8a --config=android diff --git a/.github/workflows/macos_bazel.yml b/.github/workflows/macos_bazel.yml index 444ce43f..4f26259c 100644 --- a/.github/workflows/macos_bazel.yml +++ b/.github/workflows/macos_bazel.yml @@ -8,7 +8,7 @@ on: jobs: build_with_bazel: - runs-on: macos-13 + runs-on: macos-14 steps: - uses: actions/checkout@v3 @@ -28,6 +28,9 @@ jobs: - name: Test run: bazel test \:all --config=macos --test_output=errors + - name: Test Java Binding + run: bazel run //binding/java:pscm_java_api_test + - name: Build with MLIR run: bazel build \:all --config=macos --define codegen=mlir diff --git a/.gitignore b/.gitignore index 9ebf8ce0..f40d2d80 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,5 @@ pscm-build-bin #coverage cov/ /build-* + +.aswb \ No newline at end of file diff --git a/BUILD.bazel b/BUILD.bazel index 241f4e32..30f3cfa1 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -2,6 +2,7 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") load("version.bzl", "gen_pscm_version_info") load("test.bzl", "collect_pscm_tests") load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library", "td_library") +load("@pybind11_bazel//:build_defs.bzl", "pybind_extension", "pybind_library") config_setting( name = "mlir_codegen", @@ -184,3 +185,11 @@ gentbl_cc_library( td_file = "include/pscm/codegen/mlir/Ops.td", deps = [":pscm-ops-td-files"], ) + +# when import pscm, the pscm.so must in root folder +# TODO: rename pypscm to pscm +pybind_extension( + name = "pypscm", + visibility = ["//visibility:public"], + deps = ["//binding/python:pscm"], +) diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index e9ab8528..99d35c61 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -85,6 +85,7 @@ maven_install( "androidx.lifecycle:lifecycle-service:2.5.1", "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.5.1", "androidx.lifecycle:lifecycle-viewmodel:2.5.1", + "junit:junit:4.12", ], repositories = [ "https://maven.google.com", @@ -246,7 +247,7 @@ new_git_repository( patches = [ "@dev_pscm//3rd/patch:llvm/fix_build_on_macos_13.patch", ], - remote = "https://github.com/llvm/llvm-project.git" + remote = "https://github.com/llvm/llvm-project.git", ) load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure") @@ -352,3 +353,60 @@ http_archive( strip_prefix = "freetype-2.9", urls = ["https://download.savannah.gnu.org/releases/freetype/freetype-2.9.tar.gz"], ) + +# https://thethoughtfulkoala.com/posts/2020/05/16/bazel-hermetic-python.html +# Special logic for building python interpreter with OpenSSL from homebrew. +# See https://devguide.python.org/setup/#macos-and-os-x +_py_configure = """ +if [[ "$OSTYPE" == "darwin"* ]]; then + ./configure --prefix=$(pwd)/bazel_install --with-openssl=$(brew --prefix openssl) +else + ./configure --prefix=$(pwd)/bazel_install +fi +""" + +http_archive( + name = "python_interpreter", + build_file_content = """ +exports_files(["python_bin"]) +filegroup( + name = "files", + srcs = glob(["bazel_install/**"], exclude = ["**/* *"]), + visibility = ["//visibility:public"], +) +""", + patch_cmds = [ + "mkdir $(pwd)/bazel_install", + _py_configure, + "make", + "make install", + "ln -s bazel_install/bin/python3 python_bin", + ], + sha256 = "5a99f8e7a6a11a7b98b4e75e0d1303d3832cada5534068f69c7b6222a7b1b002", + strip_prefix = "Python-3.10.0", + urls = ["https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tar.xz"], +) + +register_toolchains("@dev_pscm//toolchains:my_py_toolchain") + +http_archive( + name = "pybind11_bazel", + sha256 = "dc4882b23a617575d0fd822aba88aa4a14133c3d428b5a8fb83d81d03444a475", + strip_prefix = "pybind11_bazel-8889d39b2b925b2a47519ae09402a96f00ccf2b4", + urls = ["https://github.com/pybind/pybind11_bazel/archive/8889d39b2b925b2a47519ae09402a96f00ccf2b4.zip"], +) + +http_archive( + name = "pybind11", + build_file = "@pybind11_bazel//:pybind11.BUILD", + sha256 = "c9375b7453bef1ba0106849c83881e6b6882d892c9fae5b2572a2192100ffb8a", + strip_prefix = "pybind11-a54eab92d265337996b8e4b4149d9176c2d428a6", + urls = ["https://github.com/pybind/pybind11/archive/a54eab92d265337996b8e4b4149d9176c2d428a6.tar.gz"], +) + +load("@pybind11_bazel//:python_configure.bzl", "python_configure") + +python_configure( + name = "local_config_python", + python_interpreter_target = "@python_interpreter//:python_bin", +) diff --git a/android/app/src/main/BUILD.bazel b/android/app/src/main/BUILD.bazel index 00c4d4b3..6dd18693 100644 --- a/android/app/src/main/BUILD.bazel +++ b/android/app/src/main/BUILD.bazel @@ -8,19 +8,15 @@ android_library( manifest = "LibraryManifest.xml", resource_files = glob(["res/**/*"]), deps = [ - ":jni_lib", + # ":jni_lib", + "//binding/java:pscm_java_api", + # must depend on cc_library directly + "//binding/java:pscm_java_binding", "@maven//:androidx_appcompat_appcompat", "@maven//:androidx_constraintlayout_constraintlayout", ], ) -cc_library( - name = "jni_lib", - srcs = ["cpp/native-lib.cpp"], - copts = ["-std=c++20"], - deps = ["//:pscm"], -) - android_binary( name = "app", manifest = "AndroidManifest.xml", diff --git a/android/app/src/main/cpp/native-lib.cpp b/android/app/src/main/cpp/native-lib.cpp deleted file mode 100644 index a39cbd71..00000000 --- a/android/app/src/main/cpp/native-lib.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -// #include -#include - -extern "C" JNIEXPORT jstring JNICALL Java_dev_pscm_android_MainActivity_stringFromJNI(JNIEnv *env, jobject /* this -*/) { - std::string hello = "Hello from C++"; - return env->NewStringUTF(hello.c_str()); -} - -extern "C" JNIEXPORT jlong JNICALL Java_dev_pscm_android_MainActivity_createScheme(JNIEnv *env, jobject /* this */) { - auto scm = new pscm::Scheme(); - return (jlong)scm; -} - -extern "C" JNIEXPORT jstring JNICALL Java_dev_pscm_android_MainActivity_evalSchemeCode(JNIEnv *env, jobject /* this - */ - , - jlong scm, jstring code) { - auto _scm = (pscm::Scheme *)scm; - auto c_str = env->GetStringChars(code, nullptr); - auto len = env->GetStringLength(code); - pscm::UString s(c_str, len); - auto ret = _scm->eval(s); - auto s3 = ret.to_string(); - return env->NewString(reinterpret_cast(s3.getBuffer()), s3.length()); -} \ No newline at end of file diff --git a/android/app/src/main/java/dev/pscm/android/MainActivity.java b/android/app/src/main/java/dev/pscm/android/MainActivity.java index 7fad4344..b4912aa3 100644 --- a/android/app/src/main/java/dev/pscm/android/MainActivity.java +++ b/android/app/src/main/java/dev/pscm/android/MainActivity.java @@ -3,9 +3,11 @@ import android.os.Bundle; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; +import dev.pscm.PSCMScheme; public class MainActivity extends AppCompatActivity { - private long scm; + private PSCMScheme scm; + static { System.loadLibrary("app"); } @@ -14,20 +16,9 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - - // Example of a call to a native method + scm = new PSCMScheme(); TextView tv = (TextView)findViewById(R.id.sample_text); - tv.setText(stringFromJNI()); - scm = createScheme(); - String ret = evalSchemeCode(scm, "(version)"); + String ret = scm.eval("(version)"); tv.setText(ret); } - - /** - * A native method that is implemented by the 'native-lib' native library, - * which is packaged with this application. - */ - public native String stringFromJNI(); - public native long createScheme(); - public native String evalSchemeCode(long scm, String code); } diff --git a/binding/c/BUILD.bazel b/binding/c/BUILD.bazel new file mode 100644 index 00000000..4227b1db --- /dev/null +++ b/binding/c/BUILD.bazel @@ -0,0 +1,9 @@ +cc_library( + name = "pscm_c_api", + srcs = ["pscm_c_api.cpp"], + hdrs = ["pscm_c_api.h"], + copts = ["-std=c++20"], + implementation_deps = ["//:pscm"], + includes = ["."], + visibility = ["//visibility:public"], +) diff --git a/binding/c/pscm_c_api.cpp b/binding/c/pscm_c_api.cpp new file mode 100644 index 00000000..e3b21236 --- /dev/null +++ b/binding/c/pscm_c_api.cpp @@ -0,0 +1,27 @@ +#include "pscm_c_api.h" +#include +using namespace pscm; + +void *pscm_create_scheme() { + return new Scheme(); +} + +void pscm_destroy_scheme(void *scm) { + auto p = (Scheme *)scm; + delete p; +} + +void *pscm_eval(void *scm, const char *code) { + auto p = (Scheme *)scm; + auto ret = p->eval(code); + return new Cell(ret); +} + +const char *pscm_to_string(void *value) { + auto p = (Cell *)value; + auto s = p->to_std_string(); + char *c_str = new char[s.size() + 1]; + strcpy(c_str, s.c_str()); + c_str[s.size()] = '\0'; + return c_str; +} \ No newline at end of file diff --git a/binding/c/pscm_c_api.h b/binding/c/pscm_c_api.h new file mode 100644 index 00000000..ebf6fc48 --- /dev/null +++ b/binding/c/pscm_c_api.h @@ -0,0 +1,8 @@ +#pragma once + +extern "C" { +void *pscm_create_scheme(); +void pscm_destroy_scheme(void *scm); +void *pscm_eval(void *scm, const char *code); +const char *pscm_to_string(void *value); +} \ No newline at end of file diff --git a/binding/java/BUILD.bazel b/binding/java/BUILD.bazel new file mode 100644 index 00000000..4b6f9c8c --- /dev/null +++ b/binding/java/BUILD.bazel @@ -0,0 +1,73 @@ +java_library( + name = "pscm_java_api", + srcs = ["dev/pscm/PSCMScheme.java"], + visibility = ["//visibility:public"], + deps = select({ + "@platforms//os:android": [], + "//conditions:default": [":pscm-jni"], + }), +) + +cc_library( + name = "pscm_java_binding", + srcs = ["pscm_java_binding.cpp"], + copts = ["-std=c++20"], + visibility = ["//visibility:public"], + deps = [ + ":copy_jni_hdr_lib", + "//binding/c:pscm_c_api", + ], + alwayslink = True, +) + +cc_binary( + name = "pscm-jni", + linkshared = True, + deps = [":pscm_java_binding"], +) + +java_test( + name = "pscm_java_api_test", + srcs = ["test/PSCMSchemeTest.java"], + test_class = "test.PSCMSchemeTest", + deps = [ + ":pscm_java_api", + "@maven//:junit_junit", + ], +) + +java_binary( + name = "pscm_java_api_example", + srcs = ["example/PSCMSchemeExample.java"], + main_class = "PSCMSchemeExample", + deps = [ + ":pscm_java_api", + ], +) + +genrule( + name = "copy_link_jni_md_header", + srcs = select({ + "@platforms//os:macos": ["@bazel_tools//tools/jdk:jni_md_header-darwin"], + "@platforms//os:linux": ["@bazel_tools//tools/jdk:jni_md_header-linux"], + "//conditions:default": [], + }), + outs = ["jni_md.h"], + cmd = "cp -f $< $@", +) + +genrule( + name = "copy_link_jni_header", + srcs = ["@bazel_tools//tools/jdk:jni_header"], + outs = ["jni.h"], + cmd = "cp -f $< $@", +) + +cc_library( + name = "copy_jni_hdr_lib", + hdrs = [ + ":copy_link_jni_header", + ":copy_link_jni_md_header", + ], + includes = ["."], +) diff --git a/binding/java/dev/pscm/PSCMScheme.java b/binding/java/dev/pscm/PSCMScheme.java new file mode 100644 index 00000000..8a9b7b11 --- /dev/null +++ b/binding/java/dev/pscm/PSCMScheme.java @@ -0,0 +1,27 @@ +package dev.pscm; + +public class PSCMScheme { + + private long scm = 0; + + public PSCMScheme() { + init(); + } + + public void init() { + if (scm == 0) { + scm = createScheme(); + } + } + + public String eval(String code) { + return evalSchemeCode(scm, code); + } + + /** + * A native method that is implemented by the 'native-lib' native library, + * which is packaged with this application. + */ + public native long createScheme(); + public native String evalSchemeCode(long scm, String code); +} \ No newline at end of file diff --git a/binding/java/example/PSCMSchemeExample.java b/binding/java/example/PSCMSchemeExample.java new file mode 100644 index 00000000..50a02cc5 --- /dev/null +++ b/binding/java/example/PSCMSchemeExample.java @@ -0,0 +1,17 @@ +import dev.pscm.PSCMScheme; + +public class PSCMSchemeExample { + + static { + // load shared library + System.loadLibrary("pscm-jni"); + } + + public static void main(String args[]) { + System.out.println("Hello World"); + PSCMScheme scm = new PSCMScheme(); + // eval (version) + String ret = scm.eval("(version)"); + System.out.println(ret); + } +} diff --git a/binding/java/pscm_java_binding.cpp b/binding/java/pscm_java_binding.cpp new file mode 100644 index 00000000..5c03e097 --- /dev/null +++ b/binding/java/pscm_java_binding.cpp @@ -0,0 +1,19 @@ +#include "pscm_c_api.h" +#include +#include + +extern "C" JNIEXPORT jlong JNICALL Java_dev_pscm_PSCMScheme_createScheme(JNIEnv *env, jobject /* this */) { + auto scm = pscm_create_scheme(); + return (jlong)scm; +} + +extern "C" JNIEXPORT jstring JNICALL Java_dev_pscm_PSCMScheme_evalSchemeCode(JNIEnv *env, jobject /* this + */ + , + jlong scm, jstring code) { + auto p = (void *)scm; + auto c_str = env->GetStringUTFChars(code, nullptr); + auto ret = pscm_eval(p, c_str); + auto s = pscm_to_string(ret); + return env->NewStringUTF(s); +} \ No newline at end of file diff --git a/binding/java/test/PSCMSchemeTest.java b/binding/java/test/PSCMSchemeTest.java new file mode 100644 index 00000000..64992379 --- /dev/null +++ b/binding/java/test/PSCMSchemeTest.java @@ -0,0 +1,26 @@ +package test; +import static org.junit.Assert.assertEquals; + +import dev.pscm.PSCMScheme; +import org.junit.Test; + +public class PSCMSchemeTest { + + static { + System.loadLibrary("pscm-jni"); + } + + // public static void main(String args[]) { + // System.out.println("Hello World"); + // PSCMScheme scm = new PSCMScheme(); + // String ret = scm.eval("(version)"); + // System.out.println(ret); + // } + + @Test + public void testAdd() { + PSCMScheme scm = new PSCMScheme(); + String ret = scm.eval("(+ 2 3)"); + assertEquals("should return 5 when calculate (+ 2 3)", "5", ret); + } +} \ No newline at end of file diff --git a/binding/python/BUILD.bazel b/binding/python/BUILD.bazel new file mode 100644 index 00000000..7d0ad220 --- /dev/null +++ b/binding/python/BUILD.bazel @@ -0,0 +1,32 @@ +load("@pybind11_bazel//:build_defs.bzl", "pybind_extension", "pybind_library") +# load("@pip_deps//:requirements.bzl", "requirement") + +pybind_library( + name = "pscm", # This name is not actually created! + srcs = ["pscm_python_binding.cpp"], + visibility = ["//visibility:public"], + deps = ["//binding/c:pscm_c_api"], + alwayslink = 1, +) + +py_library( + name = "pscm_python_api", + data = ["//:pypscm.so"], +) + +py_binary( + name = "pscm_python_api_example", + srcs = ["pscm_python_api_example.py"], + deps = [ + ":pscm_python_api", + ], +) + +py_binary( + name = "pscm_python_api_test", + srcs = ["pscm_python_api_test.py"], + deps = [ + ":pscm_python_api", + # requirement("pytest"), + ], +) diff --git a/binding/python/pscm_python_api_example.py b/binding/python/pscm_python_api_example.py new file mode 100644 index 00000000..5a9b8df2 --- /dev/null +++ b/binding/python/pscm_python_api_example.py @@ -0,0 +1,6 @@ +import pypscm + +scm = pypscm.Scheme() +print(scm) +ret = scm.eval("(+ 2 6)") +print(ret) diff --git a/binding/python/pscm_python_api_test.py b/binding/python/pscm_python_api_test.py new file mode 100644 index 00000000..7585544f --- /dev/null +++ b/binding/python/pscm_python_api_test.py @@ -0,0 +1,19 @@ +import pypscm + +import sys + + +# FIXME: how to use pip? +# Currently, rules_python version is not correct +# import pytest + + +def test_scheme_add(): + scm = pypscm.Scheme() + ret = scm.eval("(+ 2 6)") + assert ret == "8" + + +# if using 'bazel test ...' +if __name__ == "__main__": + test_scheme_add() diff --git a/binding/python/pscm_python_binding.cpp b/binding/python/pscm_python_binding.cpp new file mode 100644 index 00000000..7401ca45 --- /dev/null +++ b/binding/python/pscm_python_binding.cpp @@ -0,0 +1,29 @@ +#include +#include +namespace py = pybind11; + +namespace { + +struct Scheme { + Scheme() { + scm = pscm_create_scheme(); + } + + ~Scheme() { + pscm_destroy_scheme(scm); + } + + const char *eval(const char *code) { + auto ret = pscm_eval(scm, code); + return pscm_to_string(ret); + } + +private: + void *scm; +}; + +} // namespace + +PYBIND11_MODULE(pypscm, m) { + py::class_(m, "Scheme").def(py::init<>()).def("eval", &Scheme::eval); +} \ No newline at end of file diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 00b9bea4..a89346f1 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -93,6 +93,10 @@ function sidebarGuideZh() { text: 'Unicode Support', link: '/cn/unicode_support' }, + { + text: 'Language Binding', + link: '/cn/language_binding' + }, ] }, { diff --git a/docs/cn/how_to_build_pscm.md b/docs/cn/how_to_build_pscm.md index d47841b0..1216129f 100644 --- a/docs/cn/how_to_build_pscm.md +++ b/docs/cn/how_to_build_pscm.md @@ -67,6 +67,12 @@ Note: don't use `bazel mobile-install //android/app/src/main:app --android_crosstool_top=@androidndk//:toolchain --fat_apk_cpu=arm64-v8a`, which may cause app crash +- launch pscm android app + +``` +adb shell am start -n dev.pscm.android/dev.pscm.android.MainActivity +``` + - build pscm ios app ``` diff --git a/docs/cn/language_binding.md b/docs/cn/language_binding.md new file mode 100644 index 00000000..3d2dca1d --- /dev/null +++ b/docs/cn/language_binding.md @@ -0,0 +1,61 @@ +# Language Binding + +## C API + +添加下面的基本 API + +- `void *pscm_create_scheme();` + 创建一个Scheme解释器 + +- `void pscm_destroy_scheme(void *scm);` + 销毁解释器 `scm` + +- `void *pscm_eval(void *scm, const char *code);` + 使用解释器 `scm` 对代码 `code` 进行求值 + +- `const char *pscm_to_string(void *value);` + 将所求的结果转换为字符串。注意,这里会拷贝一份字符串。 + +## Java API + +通过类 `dev.pscm.PSCMScheme` 包裹 C API + +- 使用前需要加载动态库。Android环境下需要直接依赖`//binding/java:pscm_java_binding`,其他环境加载`pscm-jni` +- 目前提供 `String PSCMScheme.eval(String code)` 接口,完成求值 + +使用示例 + +```java +import dev.pscm.PSCMScheme; +public class PSCMSchemeExample { + + static { + // load shared library + System.loadLibrary("pscm-jni"); + } + + public static void main(String args[]) { + System.out.println("Hello World"); + PSCMScheme scm = new PSCMScheme(); + // eval (version) + String ret = scm.eval("(version)"); + System.out.println(ret); + } + +} +``` + +## Python API + +- 使用 `pybind11` 提供 `pypscm.Scheme` 类 + +使用示例 + +```python +import pypscm + +scm = pypscm.Scheme() +print(scm) +ret = scm.eval("(+ 2 6)") +print(ret) +``` diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..ca6b421e --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pytest==5.4.1 \ No newline at end of file diff --git a/toolchains/BUILD.bazel b/toolchains/BUILD.bazel new file mode 100644 index 00000000..d3138f50 --- /dev/null +++ b/toolchains/BUILD.bazel @@ -0,0 +1,20 @@ +load("@rules_python//python:defs.bzl", "py_runtime_pair") +py_runtime( + name = "python3_runtime", + files = ["@python_interpreter//:files"], + interpreter = "@python_interpreter//:python_bin", + python_version = "PY3", + visibility = ["//visibility:public"], +) + +py_runtime_pair( + name = "my_py_runtime_pair", + py2_runtime = None, + py3_runtime = ":python3_runtime", +) + +toolchain( + name = "my_py_toolchain", + toolchain = ":my_py_runtime_pair", + toolchain_type = "@bazel_tools//tools/python:toolchain_type", +)