Skip to content

Commit

Permalink
Add basic Rust language support
Browse files Browse the repository at this point in the history
Summary:
This adds a `rust_binary` and `rust_library` rules to Buck.

Test Plan:
* added many tests
  • Loading branch information
sdwilsh committed Jul 21, 2015
1 parent f15ddd0 commit 7f6b194
Show file tree
Hide file tree
Showing 35 changed files with 1,303 additions and 5 deletions.
10 changes: 6 additions & 4 deletions .buckconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@
test/com/facebook/buck/android/testdata, \
test/com/facebook/buck/apple/testdata, \
test/com/facebook/buck/apple/xcode/testdata, \
test/com/facebook/buck/cli/bootstrapper/testdata, \
test/com/facebook/buck/cli/testdata, \
test/com/facebook/buck/cxx/testdata, \
test/com/facebook/buck/d/testdata, \
test/com/facebook/buck/event/listener/integration/testdata, \
test/com/facebook/buck/gwt/testdata, \
test/com/facebook/buck/java/testdata, \
test/com/facebook/buck/java/intellij/testdata, \
test/com/facebook/buck/java/testdata, \
test/com/facebook/buck/js/testdata, \
test/com/facebook/buck/junit/testdata, \
test/com/facebook/buck/ocaml/testdata, \
test/com/facebook/buck/parser/testdata, \
test/com/facebook/buck/python/testdata, \
test/com/facebook/buck/rust/testdata, \
test/com/facebook/buck/shell/testdata, \
test/com/facebook/buck/test/cache/testdata, \
test/com/facebook/buck/test/labels/testdata, \
test/com/facebook/buck/test/result/groups/testdata, \
test/com/facebook/buck/event/listener/integration/testdata, \
test/com/facebook/buck/thrift/testdata, \
test/com/facebook/buck/cxx/testdata, \
test/com/facebook/buck/python/testdata, \

; Common temp file patterns:
; .*\.swp$ (vim)
Expand Down
12 changes: 12 additions & 0 deletions .watchmanconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,27 @@
"build",
"src/com/facebook/buck/cli/quickstart",
"test/com/facebook/buck/android/testdata",
"test/com/facebook/buck/apple/testdata",
"test/com/facebook/buck/apple/xcode/testdata",
"test/com/facebook/buck/cli/bootstrapper/testdata",
"test/com/facebook/buck/cli/testdata",
"test/com/facebook/buck/cxx/testdata",
"test/com/facebook/buck/d/testdata",
"test/com/facebook/buck/event/listener/integration/testdata",
"test/com/facebook/buck/gwt/testdata",
"test/com/facebook/buck/java/intellij/testdata",
"test/com/facebook/buck/java/testdata",
"test/com/facebook/buck/js/testdata",
"test/com/facebook/buck/junit/testdata",
"test/com/facebook/buck/ocaml/testdata",
"test/com/facebook/buck/parser/testdata",
"test/com/facebook/buck/python/testdata",
"test/com/facebook/buck/rust/testdata",
"test/com/facebook/buck/shell/testdata",
"test/com/facebook/buck/test/cache/testdata",
"test/com/facebook/buck/test/labels/testdata",
"test/com/facebook/buck/test/result/groups/testdata",
"test/com/facebook/buck/thrift/testdata",
"third-party/java/dx"
]
}
14 changes: 13 additions & 1 deletion buck.iml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,28 @@
<excludeFolder url="file://$MODULE_DIR$/src/com/facebook/buck/android/support" />
<excludeFolder url="file://$MODULE_DIR$/src/com/facebook/buck/cli/quickstart" />
<excludeFolder url="file://$MODULE_DIR$/src/com/facebook/buck/junit" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/android/agent/util/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/android/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/apple/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/apple/xcode/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/cli/bootstrapper/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/cli/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/cxx/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/d/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/event/listener/integration/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/gwt/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/java/intellij/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/java/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/js/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/junit/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/ocaml/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/parser/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/python/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/rust/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/shell/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/test/cache/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/test/labels/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/test/result/groups/testdata" />
<excludeFolder url="file://$MODULE_DIR$/test/com/facebook/buck/thrift/testdata" />
</content>
<orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
8 changes: 8 additions & 0 deletions docs/__common.soy
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@
'python_library',
'python_test',
],
'rust': [
'rust_binary',
'rust_library',
],
] /}
<h3>Getting Started</h3>
<ul>
Expand Down Expand Up @@ -249,6 +253,10 @@
{param platform: 'Python' /}
{param rules: $platformRulesMap['python'] /}
{/call}
{call .platformBuildRuleLink}
{param platform: 'Rust' /}
{param rules: $platformRulesMap['rust'] /}
{/call}
</ul>
<h3>Functions</h3>
<ul>
Expand Down
70 changes: 70 additions & 0 deletions docs/__rust_common.soy
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{namespace rust_common}

/***/
{template .supported_language_version}
Note: Buck is currently tested with (and therefore supports) version 1.1.0 of Rust.
{/template}

/***/
{template .deps_arg}
{call buck.arg}
{param name : 'deps' /}
{param default : '[]' /}
{param desc}
The set of dependencies of this rule. Currently, this only supports rust_library rules.
{/param}
{/call}
{/template}

/***/
{template .srcs_arg}
{call buck.arg}
{param name : 'srcs' /}
{param desc}
<p>
The set of Rust source files to be compiled by this rule.
</p>
<p>
One of these files must be named <code>{lb}name{rb}.rs</code> or <code>main.rs</code>. This
file will be passed to <code>rustc</code> as the crate root.
</p>
{/param}
{/call}
{/template}

/***/
{template .features_arg}
{call buck.arg}
{param name : 'features' /}
{param default : '[]' /}
{param desc}
<p>
The set of features to be enabled for this rule.
</p>
<p>
These are passed to <code>rustc</code> with <code>--cfg feature="{lb}feature{rb}"</code>, and
can be used in the code with <code>#[cfg(feature = "{lb}feature{rb}")]</code>.
</p>
{/param}
{/call}
{/template}

/***/
{template .rustc_flags_arg}
{call buck.arg}
{param name : 'rustc_flags' /}
{param default : '[]' /}
{param desc}
The set of additional compiler flags to pass to <code>rustc</code>.
{/param}
{/call}
{/template}

/***/
{template .more_examples}
<p>
For more examples, check out our <a
href="https://github.com/facebook/buck/tree/master/test/com/facebook/buck/rust/testdata/">
integration tests</a>.
</p>
{/template}
12 changes: 12 additions & 0 deletions docs/concept/buckconfig.soy
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The following sections are recognized by Buck:
'log',
'ndk',
'project',
'rust',
'test',
'thrift',
'tools',
Expand Down Expand Up @@ -545,6 +546,17 @@ on the generated files.
</pre>{/literal}


{call .section}{param title: 'rust'} /}{/call}

This section may define a <code>compiler</code> that is used by <code>rust_</code> rules.

{literal}<pre class="prettyprint lang-ini">
[rust]
# The path to rustc that Buck should use to compile Rust files.
compiler = /usr/local/bin/rustc
</pre>{/literal}


{call .section}{param title: 'test' /}{/call}

This section may define a <code>timeout</code> for each test that Buck runs.
Expand Down
82 changes: 82 additions & 0 deletions docs/rule/rust_binary.soy
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{namespace rust_binary}

/***/
{template .soyweb}
{call buck.page}
{param title: 'rust_binary()' /}
{param prettify: true /}
{param description}
A rust_binary() rule builds a native Rust executable.
{/param}
{param content}

{call buck.rule}
{param status: 'UNFROZEN' /}
{param overview}
<p>
A rust_binary() rule builds a native executable from the supplied set of Rust source files
and dependencies.
</p>
<p>
{call rust_common.supported_language_version /}
</p>
{/param}

{param args}

{call buck.arg}
{param name: 'name' /}
{param desc}
The name of the rule.
{/param}
{/call}

{call rust_common.srcs_arg /}

{call rust_common.deps_arg /}

{call rust_common.features_arg /}

{call rust_common.rustc_flags_arg /}

{/param} // close args

{param examples}

{call rust_common.more_examples /}

{literal}<pre class="prettyprint lang-py">
rust_binary(
name='greet',
srcs=[
'greet.rs',
],
deps=[
':greeting',
],
)

rust_library(
name='greeting',
srcs=[
'greeting.rs',
],
deps=[
':join',
],
)

rust_library(
name='join',
srcs=[
'join.rs',
],
)
</pre>{/literal}
{/param}

{/call} // close buck.rule

{/param}
{/call}
{/template}
65 changes: 65 additions & 0 deletions docs/rule/rust_library.soy
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{namespace rust_library}

/***/
{template .soyweb}
{call buck.page}
{param title: 'rust_library()' /}
{param prettify: true /}
{param description}
A rust_library() rule builds a native Rust library.
{/param}
{param content}

{call buck.rule}
{param status: 'UNFROZEN' /}
{param overview}
<p>
A rust_library() rule builds a native library from the supplied set of Rust source files
and dependencies.
</p>
<p>
{call rust_common.supported_language_version /}
</p>
{/param}

{param args}

{call buck.arg}
{param name: 'name' /}
{param desc}
The name of the rule.
{/param}
{/call}

{call rust_common.srcs_arg /}

{call rust_common.deps_arg /}

{call rust_common.features_arg /}

{call rust_common.rustc_flags_arg /}

{/param} // close args

{param examples}

{call rust_common.more_examples /}

{literal}<pre class="prettyprint lang-py">
rust_library(
name='greeting',
srcs=[
'greeting.rs',
],
deps=[
':join',
],
)
</pre>{/literal}
{/param}

{/call} // close buck.rule

{/param}
{/call}
{/template}
1 change: 1 addition & 0 deletions src/com/facebook/buck/cli/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ java_library(
'//src/com/facebook/buck/parser:parser',
'//src/com/facebook/buck/python:config',
'//src/com/facebook/buck/rules:types',
'//src/com/facebook/buck/rust:rust',
'//src/com/facebook/buck/thrift:rules',
'//test/com/facebook/buck/...',
]
Expand Down
1 change: 1 addition & 0 deletions src/com/facebook/buck/rules/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ java_immutables_library(
'//src/com/facebook/buck/ocaml:rules',
'//src/com/facebook/buck/cxx:rules',
'//src/com/facebook/buck/rules/macros:macros',
'//src/com/facebook/buck/rust:rust',
'//src/com/facebook/buck/shell:rules',
'//src/com/facebook/buck/thrift:rules',
'//src/com/facebook/buck/util:constants',
Expand Down
7 changes: 7 additions & 0 deletions src/com/facebook/buck/rules/KnownBuildRuleTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
import com.facebook.buck.python.PythonEnvironment;
import com.facebook.buck.python.PythonLibraryDescription;
import com.facebook.buck.python.PythonTestDescription;
import com.facebook.buck.rust.RustBinaryDescription;
import com.facebook.buck.rust.RustBuckConfig;
import com.facebook.buck.rust.RustLibraryDescription;
import com.facebook.buck.shell.ExportFileDescription;
import com.facebook.buck.shell.GenruleDescription;
import com.facebook.buck.shell.ShBinaryDescription;
Expand Down Expand Up @@ -344,6 +347,8 @@ static Builder createBuilder(

ReactNativeBuckConfig reactNativeBuckConfig = new ReactNativeBuckConfig(config);

RustBuckConfig rustBuckConfig = new RustBuckConfig(config);

ProGuardConfig proGuardConfig = new ProGuardConfig(config);

PythonBuckConfig pyConfig = new PythonBuckConfig(config, new ExecutableFinder());
Expand Down Expand Up @@ -492,6 +497,8 @@ static Builder createBuilder(
androidBinaryOptions,
testRuleTimeoutMs,
defaultCxxPlatform));
builder.register(new RustBinaryDescription(rustBuckConfig));
builder.register(new RustLibraryDescription(rustBuckConfig));
builder.register(new ShBinaryDescription());
builder.register(new ShTestDescription());
ThriftBuckConfig thriftBuckConfig = new ThriftBuckConfig(config);
Expand Down
Loading

0 comments on commit 7f6b194

Please sign in to comment.