1. Mac 安裝 homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
homebrew的作用就是友善安裝,解除安裝程式,隻要一條指令就能完成這些。
2. 安裝 Scala
brew install scala
在終端輸入 scala -version。如果列印版本号代表安裝成功
3. 安裝sbt
brew install sbt
在終端輸入sbt,進入sbt指令行,輸入sbtVersion,可以列印版本号。sbt 的作用是進行項目管理,将項目中的檔案放在特定的目錄結構中。這個目錄結構要自己通過mkdir生成(不知道sbt有沒有指令可以生成,如果沒有的話,自己可以寫一個腳本)
├── src
│ ├── main
│ │ ├── java
│ │ ├── resources
│ │ └── scala
│ ├── test
│ │ ├── java
│ │ ├── resources
│ │ └── scala
├── build.sbt
├── project
│ ├── build.properties
│ ├── plugins.sbt
main 檔案夾中主要放源代碼,scala 代碼放在Scala中,Java代碼放在Java中,一些資料檔案放在resources中。
test 檔案夾中主要放測試代碼,類似testbench之類的檔案,按照檔案類型分别放在不同的檔案夾中。
build.sbt 是你這個項目的配置檔案,例如:
name := "CombLogic"
version := "0.1"
scalaVersion := "2.12.10"
crossScalaVersions := Seq("2.12.10", "2.11.12")
resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("releases")
)
// Provide a managed dependency on X if -DXVersion="" is supplied on the command line.
libraryDependencies += "edu.berkeley.cs" %% "chisel3" % "3.2-SNAPSHOT"
libraryDependencies += "edu.berkeley.cs" %% "chisel-testers2" % "0.1-SNAPSHOT"
4. 測試環境
(1)建立一個項目self_learning
cd self_learning
mkdir src
mkdir src/main
mkdir src/test
mkdir src/main/scala
//由于隻是測試用,沒有把完整的sbt項目結建構好
(2)編寫helloworld.scala,放在src/main/scala檔案夾中
object HelloWorld {
def main(args: Array[String]) {
println("Hello world")
}
}
(3)在self_learning的根目錄中,輸入sbt, 進入sbt指令模式,輸入run。項目中的helloworld.scala就會自動執行,并且會在self_learning 目錄中生成project和target兩個檔案夾。
zhongyudeMacBook-Pro:self_learning yu$ sbt
[info] Loading project definition from /Users/yu/scala_project/self_learning/project
[info] Updating ProjectRef(uri("file:/Users/yu/scala_project/self_learning/project/"), "self_learning-build")...
[info] Done updating.
[info] Set current project to self_learning (in build file:/Users/yu/scala_project/self_learning/)
[info] sbt server started at local:///Users/yu/.sbt/1.0/server/3ecf151dd53beddfd07e/sock
sbt:self_learning> run
[info] Compiling 1 Scala source to /Users/yu/scala_project/self_learning/target/scala-2.12/classes ...
[info] Done compiling.
[info] Packaging /Users/yu/scala_project/self_learning/target/scala-2.12/self_learning_2.12-0.1.0-SNAPSHOT.jar ...
[info] Done packaging.
[info] Running HelloWorld
Hello world
5. 搭建chisel環境
(1)下載下傳chisel3 repository
在本地library檔案夾中,使用Git輸入如下指令:
git clone https://github.com/freechipsproject/chisel3.git
下載下傳完後 cd chisel3,首先編譯chisel3 repository:
sbt compile
編譯成功後,進行測試:
sbt test
最後将chisel3添加到.ivy2/local/edu.berkeley.cs/中,輸入如下指令:
sbt pulishLocal
(2)下載下傳firrtl repository
跟(1)下載下傳chisel3采用相同的步驟
(3)修改build.sbt檔案
使用https://github.com/freechipsproject/chisel-template/blob/release/build.sbt中的build.sbt檔案:
這是官網上給的添加庫依賴的代碼,Scala版本得是2.11.+或者2.12.+,如果你用2.13,則sbt update不通過。