1*d4726bddSHONG Yifan# Rules Rust - Architecture 2*d4726bddSHONG Yifan 3*d4726bddSHONG YifanIn this file we describe how we think about the architecture 4*d4726bddSHONG Yifanof `rules_rust`. Its goal is to help contributors orient themselves, and to 5*d4726bddSHONG Yifandocument code restrictions and assumptions. 6*d4726bddSHONG Yifan 7*d4726bddSHONG YifanIn general we try to follow the common standard defined by 8*d4726bddSHONG Yifanhttps://docs.bazel.build/versions/master/skylark/deploying.html. 9*d4726bddSHONG Yifan 10*d4726bddSHONG Yifan## //rust 11*d4726bddSHONG Yifan 12*d4726bddSHONG YifanThis is the core package of the rules. It contains all the core rules such as 13*d4726bddSHONG Yifan`rust_binary` and `rust_library`. It also contains `rust_common`, a Starlark 14*d4726bddSHONG Yifanstruct providing all rules_rust APIs that one might need when writing custom 15*d4726bddSHONG Yifanrules integrating with rules_rust. 16*d4726bddSHONG Yifan 17*d4726bddSHONG Yifan`//rust` and all its subpackages have to be standalone. Users who only need 18*d4726bddSHONG Yifanthe core rules should be able to ignore all other packages. 19*d4726bddSHONG Yifan 20*d4726bddSHONG Yifan`//rust:defs.bzl` is the file that all users of `rules_rust` will be using. 21*d4726bddSHONG YifanEverything in this file can be used (depended on) and is supported (though 22*d4726bddSHONG Yifanstability is not currently guaranteed across commits, see 23*d4726bddSHONG Yifan[#600](https://github.com/bazelbuild/rules_rust/issues/600)). Typically this 24*d4726bddSHONG Yifanfile re-exports definitions from other files, typically from `//rust/private`. 25*d4726bddSHONG YifanAlso other packages in `rules_rust` should access core rules through the public 26*d4726bddSHONG YifanAPI only. We expect dogfooding our own APIs increases their 27*d4726bddSHONG Yifanquality. 28*d4726bddSHONG Yifan 29*d4726bddSHONG Yifan`//rust/private` package contains code for rule implementation. This file can only 30*d4726bddSHONG Yifandepend on `//rust` and its subpackages. Exceptions are Bazel's builtin packages 31*d4726bddSHONG Yifanand public APIs of other rules (such as `rules_cc`). Depending on 32*d4726bddSHONG Yifan`//rust/private` from packages other than `//rust` is not supported, we reserve 33*d4726bddSHONG Yifanthe right to change anything there and not tell anybody. 34*d4726bddSHONG Yifan 35*d4726bddSHONG YifanWhen core rules need custom tools (such as process wrapper, launcher, test 36*d4726bddSHONG Yifanrunner, and so on), they should be stored in `//rust/tools` (for public tools) 37*d4726bddSHONG Yifanor in `//rust/private/tools` (for private tools). These should: 38*d4726bddSHONG Yifan 39*d4726bddSHONG Yifan* be essential (it does not make sense to have core rules without them) 40*d4726bddSHONG Yifan* have few or no third party dependencies, and their third party dependencies 41*d4726bddSHONG Yifan should be checked in. 42*d4726bddSHONG Yifan* be usable for cross compilation 43*d4726bddSHONG Yifan* have only essential requirements on the host system (requiring that a custom 44*d4726bddSHONG Yifan library is installed on the system is frowned upon) 45*d4726bddSHONG Yifan 46*d4726bddSHONG Yifan## //examples (@examples) 47*d4726bddSHONG Yifan 48*d4726bddSHONG YifanExamples package is actually a local repository. This repository can have 49*d4726bddSHONG Yifanadditional dependencies on anything that helps demonstrate an example. Non 50*d4726bddSHONG Yifantrivial examples should have an accompanying README.md file. 51*d4726bddSHONG Yifan 52*d4726bddSHONG YifanThe goal of examples is to demonstrate usage of `rules_rust`, not to test code. 53*d4726bddSHONG YifanUse `//test` for testing. 54*d4726bddSHONG Yifan 55*d4726bddSHONG Yifan## //test 56*d4726bddSHONG Yifan 57*d4726bddSHONG YifanContains unit (in `//test/unit`) and integration tests. CI configuration is 58*d4726bddSHONG Yifanstored in .bazelci. 59