Coder Social home page Coder Social logo

xie-dongping / sml_rules Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 40 KB

Bazel SML rules provide the necessary rules to build and test SML (Standard ML) applications using Bazel.

License: Apache License 2.0

Starlark 100.00%
bazel bazel-rules build-tool purely-functional-data-structures standard-ml starlark

sml_rules's Introduction

Bazel SML Rules

Bazel SML rules provide the necessary rules to build and test SML (Standard ML) applications using Bazel.

Introduction

Bazel SML rules are a set of rules for the Bazel build system that allow you to compile and test SML (Standard ML) code. The sml files are concatenated together and built by the MLton compiler.

Currently, the rules include sml_library, sml_cc_src, sml_binary, and sml_test:

  • sml_library: This rule takes a list of .sml files as input and produces an SML library as output. The library can be used as a dependency in other rules.
  • sml_cc_src: This rule transpiles SML code into C code using the MLton compiler.
  • sml_binary: This rule creates a binary executable from SML code. It is a thin wrapper of cc_binary combined with sml_cc_src.
  • sml_test: This rule is used for running tests written in SML. It is a thin wrapper of cc_binary combined with sml_cc_src.

Please refer to the source code for exact implementation.

Limitations

These rules are currently designed to work with the MLton compiler using its C code generation. The sml files are concatenated according to the dependencies defined in the build process, but I haven't tested it in large projects, so your mileage may vary.

MLton may generate multiple C files from the Standard ML source code. The current default value is set at 20, as bazel requires a static build graph. If it is not enough, error would be thrown and the user has to increase the limit by setting the max_files attribute of the rules.

These rules are built and tested for x64 Linux (my own computer). They may not work correctly on other operating systems or architectures.

Error handling and messaging may not be fully refined yet. Use at your own risk.

Disclaimer

This package is currently in an alpha stage and its usage is at the user's own risk.

Please note that I am developing this project for my own personal needs and for fun. Therefore, I cannot guarantee any specific features or provide any support beyond what I find personally useful. Please do not expect any additional contributions or updates from me.

Usage

To use these rules (provided that bazel/bazelisk is installed), include the following in your WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
    name = "sml_rules",
    remote = "https://github.com/xie-dongping/sml_rules.git",
    branch = "main", # don't specify the `branch`, use `commit` to ensure hermetic build
    # commit = "sha_hash", # please use the `commit` field to pin a certain commit
)

load("@sml_rules//:rules.bzl", "sml_repository")
sml_repository()

After downloading the rules, you may load and use the rules.

load("@sml_rules//:sml_rules.bzl", "sml_library", "sml_binary", "sml_test")

sml_library(
    name = "mylib",
    srcs = ["mylib.sml"],
)

sml_binary(
    name = "mybinary",
    srcs = ["main.sml"],
    deps = [":mylib"],
)

sml_test(
    name = "mytest",
    srcs = ["mylib.test.sml"],
    deps = [":mylib"],
)

Then you may test your code with bazel test ... (to test all available test targets) or bazel test //:mytest.

An example is also available in examples folder.

sml_rules's People

Contributors

xie-dongping avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.