Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit 2ea9861

Browse files
Junpeng Qiufacebook-github-bot
authored andcommitted
Add basic rust module support
Summary: This handles source folders and deps. The feature is controlled by the `intellij.enable_rust_module=true` config. Reviewed By: ardavank fbshipit-source-id: cdc37e9382280c04dbcf7ef818cc227884bab2e1
1 parent b4bdb5e commit 2ea9861

24 files changed

Lines changed: 224 additions & 6 deletions

File tree

build.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,13 +804,14 @@
804804
</build-buck-module-jar>
805805
</target>
806806

807-
<target name="build-module-intellij" depends="compile, build-module-python, build-module-filegroup, build-module-ziprules">
807+
<target name="build-module-intellij" depends="compile, build-module-python, build-module-rust, build-module-filegroup, build-module-ziprules">
808808
<build-buck-module-jar-with-resources module-name="intellij">
809809
<module-javac-params>
810810
<include name="com/facebook/buck/features/project/intellij/**/*.java" />
811811
</module-javac-params>
812812
<additional-classpath-entries>
813813
<include name="python.jar"/>
814+
<include name="rust.jar"/>
814815
<include name="filegroup.jar" />
815816
<include name="ziprules.jar" />
816817
</additional-classpath-entries>

src/com/facebook/buck/command/config/ConfigIgnoredByDaemon.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ private static ImmutableMap<String, ImmutableSet<String>> getIgnoreFieldsForDaem
7373
"auto_generate_android_facet_sources",
7474
"buck_out_path_for_generated_files",
7575
"default_min_android_sdk_version",
76+
"enable_rust_module",
7677
"flatten_android_generated_files_path_with_hash",
7778
"generate_module_info_binary_index",
7879
"keep_module_files_in_module_dirs",

src/com/facebook/buck/features/project/intellij/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ buck_module(
1111
),
1212
module_deps = [
1313
"//src/com/facebook/buck/features/python:module",
14+
"//src/com/facebook/buck/features/rust:rust",
1415
"//src/com/facebook/buck/features/filegroup:filegroup",
1516
"//src/com/facebook/buck/features/zip/rules:rules",
1617
],

src/com/facebook/buck/features/project/intellij/IjBuckModule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@
1919
import com.facebook.buck.core.module.BuckModule;
2020
import com.facebook.buck.features.filegroup.FilegroupModule;
2121
import com.facebook.buck.features.python.PythonModule;
22+
import com.facebook.buck.features.rust.RustModule;
2223
import com.facebook.buck.features.zip.rules.ZipRulesModule;
2324

2425
/** Module with project generator for IntelliJ. */
25-
@BuckModule(dependencies = {FilegroupModule.class, PythonModule.class, ZipRulesModule.class})
26+
@BuckModule(
27+
dependencies = {
28+
FilegroupModule.class,
29+
PythonModule.class,
30+
RustModule.class,
31+
ZipRulesModule.class
32+
})
2633
public class IjBuckModule {}

src/com/facebook/buck/features/project/intellij/IjProjectBuckConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ static IjProjectConfig.Builder createBuilder(BuckConfig buckConfig) {
197197
buckConfig.getPath(
198198
INTELLIJ_BUCK_CONFIG_SECTION, "kotlin_java_runtime_library_template_path"))
199199
.setBuckOutPathForGeneratedProjectFiles(
200-
buckConfig.getValue(INTELLIJ_BUCK_CONFIG_SECTION, "buck_out_path_for_generated_files"));
200+
buckConfig.getValue(INTELLIJ_BUCK_CONFIG_SECTION, "buck_out_path_for_generated_files"))
201+
.setRustModuleEnabled(
202+
buckConfig.getBooleanValue(INTELLIJ_BUCK_CONFIG_SECTION, "enable_rust_module", false));
201203
}
202204

203205
private static String getModuleGroupName(String moduleGroupName, BuckConfig buckConfig) {

src/com/facebook/buck/features/project/intellij/SupportedTargetTypeRegistry.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@
3939
import com.facebook.buck.features.project.intellij.lang.kotlin.KotlinTestModuleRule;
4040
import com.facebook.buck.features.project.intellij.lang.python.PythonLibraryModuleRule;
4141
import com.facebook.buck.features.project.intellij.lang.python.PythonTestModuleRule;
42+
import com.facebook.buck.features.project.intellij.lang.rust.RustBinaryModuleRule;
43+
import com.facebook.buck.features.project.intellij.lang.rust.RustLibraryModuleRule;
4244
import com.facebook.buck.features.project.intellij.lang.scala.ScalaLibraryModuleRule;
4345
import com.facebook.buck.features.project.intellij.lang.scala.ScalaTestModuleRule;
4446
import com.facebook.buck.features.project.intellij.model.IjModuleFactoryResolver;
4547
import com.facebook.buck.features.project.intellij.model.IjModuleRule;
4648
import com.facebook.buck.features.project.intellij.model.IjProjectConfig;
4749
import com.facebook.buck.features.python.PythonLibraryDescription;
4850
import com.facebook.buck.features.python.PythonTestDescription;
51+
import com.facebook.buck.features.rust.RustBinaryDescription;
52+
import com.facebook.buck.features.rust.RustLibraryDescription;
4953
import com.facebook.buck.io.filesystem.ProjectFilesystem;
5054
import com.facebook.buck.jvm.core.JavaPackageFinder;
5155
import com.facebook.buck.jvm.groovy.GroovyLibraryDescription;
@@ -84,7 +88,9 @@ public class SupportedTargetTypeRegistry {
8488
PythonLibraryDescription.class,
8589
PythonTestDescription.class,
8690
ScalaLibraryDescription.class,
87-
ScalaTestDescription.class);
91+
ScalaTestDescription.class,
92+
RustLibraryDescription.class,
93+
RustBinaryDescription.class);
8894

8995
public static boolean isTargetTypeSupported(Class<?> descriptionClass) {
9096
return SUPPORTED_MODULE_DESCRIPTION_CLASSES.contains(descriptionClass);
@@ -163,6 +169,12 @@ public SupportedTargetTypeRegistry(
163169
addToIndex(
164170
new ScalaTestModuleRule(
165171
projectFilesystem, moduleFactoryResolver, depsQueryResolver, projectConfig));
172+
addToIndex(
173+
new RustLibraryModuleRule(
174+
projectFilesystem, moduleFactoryResolver, depsQueryResolver, projectConfig));
175+
addToIndex(
176+
new RustBinaryModuleRule(
177+
projectFilesystem, moduleFactoryResolver, depsQueryResolver, projectConfig));
166178
Preconditions.checkState(areTargetTypesEqual(moduleRuleIndex.keySet()));
167179
}
168180

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.facebook.buck.features.project.intellij.lang.rust;
18+
19+
import com.facebook.buck.core.model.targetgraph.TargetNode;
20+
import com.facebook.buck.core.rules.DescriptionWithTargetGraph;
21+
import com.facebook.buck.features.project.intellij.BaseIjModuleRule;
22+
import com.facebook.buck.features.project.intellij.ModuleBuildContext;
23+
import com.facebook.buck.features.project.intellij.depsquery.IjDepsQueryResolver;
24+
import com.facebook.buck.features.project.intellij.model.IjModuleFactoryResolver;
25+
import com.facebook.buck.features.project.intellij.model.IjModuleType;
26+
import com.facebook.buck.features.project.intellij.model.IjProjectConfig;
27+
import com.facebook.buck.features.rust.RustBinaryDescription;
28+
import com.facebook.buck.features.rust.RustBinaryDescriptionArg;
29+
import com.facebook.buck.io.filesystem.ProjectFilesystem;
30+
31+
/** Support for transforming a rust_binary declaration to an intellij module */
32+
public class RustBinaryModuleRule extends BaseIjModuleRule<RustBinaryDescriptionArg> {
33+
34+
public RustBinaryModuleRule(
35+
ProjectFilesystem projectFilesystem,
36+
IjModuleFactoryResolver moduleFactoryResolver,
37+
IjDepsQueryResolver depsQueryResolver,
38+
IjProjectConfig projectConfig) {
39+
super(projectFilesystem, moduleFactoryResolver, depsQueryResolver, projectConfig);
40+
}
41+
42+
@Override
43+
public Class<? extends DescriptionWithTargetGraph<?>> getDescriptionClass() {
44+
return RustBinaryDescription.class;
45+
}
46+
47+
@Override
48+
public void apply(TargetNode<RustBinaryDescriptionArg> target, ModuleBuildContext context) {
49+
if (projectConfig.isRustModuleEnabled()) {
50+
addDepsAndSources(target, false /* wantsPackagePrefix */, context);
51+
}
52+
}
53+
54+
@Override
55+
public IjModuleType detectModuleType(TargetNode<RustBinaryDescriptionArg> targetNode) {
56+
return projectConfig.isRustModuleEnabled()
57+
? IjModuleType.RUST_MODULE
58+
: IjModuleType.UNKNOWN_MODULE;
59+
}
60+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.facebook.buck.features.project.intellij.lang.rust;
18+
19+
import com.facebook.buck.core.model.targetgraph.TargetNode;
20+
import com.facebook.buck.core.rules.DescriptionWithTargetGraph;
21+
import com.facebook.buck.features.project.intellij.BaseIjModuleRule;
22+
import com.facebook.buck.features.project.intellij.ModuleBuildContext;
23+
import com.facebook.buck.features.project.intellij.depsquery.IjDepsQueryResolver;
24+
import com.facebook.buck.features.project.intellij.model.IjModuleFactoryResolver;
25+
import com.facebook.buck.features.project.intellij.model.IjModuleType;
26+
import com.facebook.buck.features.project.intellij.model.IjProjectConfig;
27+
import com.facebook.buck.features.rust.RustLibraryDescription;
28+
import com.facebook.buck.features.rust.RustLibraryDescriptionArg;
29+
import com.facebook.buck.io.filesystem.ProjectFilesystem;
30+
31+
/** Support for transforming a rust_library declaration to an intellij module */
32+
public class RustLibraryModuleRule extends BaseIjModuleRule<RustLibraryDescriptionArg> {
33+
34+
public RustLibraryModuleRule(
35+
ProjectFilesystem projectFilesystem,
36+
IjModuleFactoryResolver moduleFactoryResolver,
37+
IjDepsQueryResolver depsQueryResolver,
38+
IjProjectConfig projectConfig) {
39+
super(projectFilesystem, moduleFactoryResolver, depsQueryResolver, projectConfig);
40+
}
41+
42+
@Override
43+
public Class<? extends DescriptionWithTargetGraph<?>> getDescriptionClass() {
44+
return RustLibraryDescription.class;
45+
}
46+
47+
@Override
48+
public void apply(TargetNode<RustLibraryDescriptionArg> target, ModuleBuildContext context) {
49+
if (projectConfig.isRustModuleEnabled()) {
50+
addDepsAndSources(target, false /* wantsPackagePrefix */, context);
51+
}
52+
}
53+
54+
@Override
55+
public IjModuleType detectModuleType(TargetNode<RustLibraryDescriptionArg> targetNode) {
56+
return projectConfig.isRustModuleEnabled()
57+
? IjModuleType.RUST_MODULE
58+
: IjModuleType.UNKNOWN_MODULE;
59+
}
60+
}

src/com/facebook/buck/features/project/intellij/model/IjModuleType.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ public String getSdkType(IjProjectConfig projectConfig) {
112112
}
113113
},
114114

115+
RUST_MODULE("RUST_MODULE") {
116+
@Override
117+
public Optional<String> getSdkName(IjProjectConfig projectConfig) {
118+
return Optional.empty();
119+
}
120+
121+
@Override
122+
public String getSdkType(IjProjectConfig projectConfig) {
123+
return SDK_TYPE_JAVA;
124+
}
125+
},
126+
115127
UNKNOWN_MODULE("JAVA_MODULE") {
116128
@Override
117129
public Optional<String> getSdkName(IjProjectConfig projectConfig) {

src/com/facebook/buck/features/project/intellij/model/IjProjectConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ public boolean isAutogenerateAndroidFacetSourcesEnabled() {
137137

138138
public abstract Optional<String> getBuckOutPathForGeneratedProjectFiles();
139139

140+
public abstract boolean isRustModuleEnabled();
141+
140142
public static Builder builder() {
141143
return new Builder();
142144
}

0 commit comments

Comments
 (0)