forked from neo-ai/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rust][Diagnostics] Add initial boilerplate for Rust diagnostic inter…
…face. (apache#6656) * Add initial boilerplate for Rust diagnostic interface. * Codespan example almost working * WIP * Hacking on Rust inside of TVM * Borrow code from Egg * Update CMake and delete old API * Fix Linux build * Clean up exporting to show off new diagnostics * Improve Rust bindings * Fix calling * Fix * Rust Diagnostics work * Remove type checker * Format and cleanup * Fix the extension code * More cleanup * Fix some CR * Add docs and address feedback * WIP more improvments * Update cmake/modules/RustExt.cmake Co-authored-by: Robert Kimball <bobkimball@gmail.com> * Update rust/tvm/src/ir/diagnostics/mod.rs Co-authored-by: Robert Kimball <bobkimball@gmail.com> * Clean up PR * Format all * Remove dead comment * Code review comments and apache headers * Purge test file * Update cmake/modules/LLVM.cmake Co-authored-by: Tristan Konolige <tristan.konolige@gmail.com> * Format Rust * Add TK's suggestion * More CR and cleanup * Fix tyck line * Format Co-authored-by: Robert Kimball <bobkimball@gmail.com> Co-authored-by: Tristan Konolige <tristan.konolige@gmail.com>
- Loading branch information
1 parent
41d4d87
commit c5500ac
Showing
34 changed files
with
968 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
if(USE_RUST_EXT) | ||
set(RUST_SRC_DIR "${CMAKE_SOURCE_DIR}/rust") | ||
set(CARGO_OUT_DIR "${CMAKE_SOURCE_DIR}/rust/target") | ||
|
||
if(USE_RUST_EXT STREQUAL "STATIC") | ||
set(COMPILER_EXT_PATH "${CARGO_OUT_DIR}/release/libcompiler_ext.a") | ||
elseif(USE_RUST_EXT STREQUAL "DYNAMIC") | ||
set(COMPILER_EXT_PATH "${CARGO_OUT_DIR}/release/libcompiler_ext.so") | ||
else() | ||
message(FATAL_ERROR "invalid setting for USE_RUST_EXT, STATIC, DYNAMIC or OFF") | ||
endif() | ||
|
||
add_custom_command( | ||
OUTPUT "${COMPILER_EXT_PATH}" | ||
COMMAND cargo build --release | ||
MAIN_DEPENDENCY "${RUST_SRC_DIR}" | ||
WORKING_DIRECTORY "${RUST_SRC_DIR}/compiler-ext") | ||
|
||
add_custom_target(rust_ext ALL DEPENDS "${COMPILER_EXT_PATH}") | ||
|
||
# TODO(@jroesch, @tkonolige): move this to CMake target | ||
# target_link_libraries(tvm "${COMPILER_EXT_PATH}" PRIVATE) | ||
list(APPEND TVM_LINKER_LIBS ${COMPILER_EXT_PATH}) | ||
|
||
add_definitions(-DRUST_COMPILER_EXT=1) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
[package] | ||
name = "compiler-ext" | ||
version = "0.1.0" | ||
authors = ["TVM Contributors"] | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["staticlib", "cdylib"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
tvm = { path = "../tvm", default-features = false, features = ["static-linking"] } | ||
log = "*" | ||
env_logger = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
use env_logger; | ||
use tvm::export; | ||
|
||
fn diagnostics() -> Result<(), tvm::Error> { | ||
tvm::ir::diagnostics::codespan::init() | ||
} | ||
|
||
export!(diagnostics); | ||
|
||
#[no_mangle] | ||
extern "C" fn compiler_ext_initialize() -> i32 { | ||
let _ = env_logger::try_init(); | ||
tvm_export("rust_ext").expect("failed to initialize the Rust compiler extensions."); | ||
log::debug!("Loaded the Rust compiler extension."); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.