-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cross-compilation and testing to Arm64 on CI #6
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# cross configuration file to use the Dockerfile | ||
|
||
[target.aarch64-unknown-linux-gnu] | ||
image = "parsec-cross" |
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,8 @@ | ||
# This Dockerfile is used by cross for cross-compilation and cross-testing of | ||
# PARSEC. | ||
|
||
FROM rustembedded/cross:aarch64-unknown-linux-gnu-0.1.16 | ||
|
||
RUN apt-get update && \ | ||
# wget is needed in the build script to download the operations. | ||
apt-get install -y wget |
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 |
---|---|---|
|
@@ -12,39 +12,21 @@ | |
// 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 std::fs::{read_dir, OpenOptions}; | ||
use std::io::{Result, Write}; | ||
use std::env; | ||
use std::fs::read_dir; | ||
use std::io::Result; | ||
use std::path::Path; | ||
use std::process::{Command, Output}; | ||
use std::process::Command; | ||
|
||
const PROTO_FOLDER: &str = "target/parsec-operations/protobuf"; | ||
const PROTO_OUT_DIR: &str = "src/operations_protobuf/generated_ops"; | ||
const PARSEC_OPERATIONS_VERSION: &str = "0.2.0"; | ||
|
||
// TODO: handle OsStrings more carefully, as .into_string() might fail | ||
|
||
fn generate_mod_file() -> Result<()> { | ||
let dir_entries = read_dir(Path::new(PROTO_FOLDER))?; | ||
let mod_file_path = format!("{}/mod.rs", PROTO_OUT_DIR); | ||
let mut mod_file = OpenOptions::new() | ||
.write(true) | ||
.truncate(true) | ||
.create(true) | ||
.open(&mod_file_path)?; | ||
dir_entries.for_each(|file| { | ||
let filename = file.unwrap().file_name().into_string().unwrap(); | ||
if filename.ends_with(".proto") { | ||
writeln!(&mut mod_file, "pub mod {};", filename.replace(".proto", "")).unwrap(); | ||
} | ||
}); | ||
|
||
mod_file.flush()?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn generate_proto_sources() -> Result<()> { | ||
let dir_entries = read_dir(Path::new(PROTO_FOLDER))?; | ||
let path = format!( | ||
"{}/parsec-operations-{}/protobuf", | ||
env::var("OUT_DIR").unwrap(), | ||
PARSEC_OPERATIONS_VERSION | ||
); | ||
let dir_entries = read_dir(Path::new(&path))?; | ||
let files: Vec<String> = dir_entries | ||
.map(|protos_file| { | ||
protos_file | ||
|
@@ -57,31 +39,48 @@ fn generate_proto_sources() -> Result<()> { | |
.filter(|string| string.ends_with(".proto")) | ||
.collect(); | ||
let files_slices: Vec<&str> = files.iter().map(|file| &file[..]).collect(); | ||
let mut prost_config = prost_build::Config::new(); | ||
prost_config.out_dir(Path::new("./src/operations_protobuf/generated_ops")); | ||
prost_config | ||
.compile_protos(&files_slices, &[PROTO_FOLDER]) | ||
.expect("failed to generate protos"); | ||
prost_build::compile_protos(&files_slices, &[&path]).expect("failed to generate protos"); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn get_protobuf_files() -> Result<Output> { | ||
// TODO: Downloading a release file and decompressing it might be faster here. | ||
fn get_protobuf_files() { | ||
// TODO: Use semantic versioning to get the newest versions. | ||
Command::new("git") | ||
.arg("clone") | ||
.arg("https://github.com/parallaxsecond/parsec-operations.git") | ||
.arg("-b") | ||
.arg(PARSEC_OPERATIONS_VERSION) | ||
.arg("target/parsec-operations") | ||
.output() | ||
if !Command::new("wget") | ||
.arg(format!( | ||
"https://github.com/parallaxsecond/parsec-operations/archive/{}.tar.gz", | ||
PARSEC_OPERATIONS_VERSION | ||
)) | ||
.arg(format!( | ||
"--directory-prefix={}", | ||
env::var("OUT_DIR").unwrap() | ||
)) | ||
.status() | ||
.expect("wget command failed.") | ||
.success() | ||
{ | ||
panic!("wget command returned an error status."); | ||
} | ||
|
||
// Gets extracted as parsec-operations-PARSEC_OPERATIONS_VERSION directory. | ||
if !Command::new("tar") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have bindings to tar as a library too. |
||
.arg("xf") | ||
.arg(format!( | ||
"{}/{}.tar.gz", | ||
env::var("OUT_DIR").unwrap(), | ||
PARSEC_OPERATIONS_VERSION | ||
)) | ||
.arg("--directory") | ||
.arg(env::var("OUT_DIR").unwrap()) | ||
.status() | ||
.expect("tar command failed.") | ||
.success() | ||
{ | ||
panic!("tar command returned an error status."); | ||
} | ||
} | ||
|
||
fn main() { | ||
get_protobuf_files().expect("Failed to download the protobuf files."); | ||
|
||
generate_mod_file().expect("Failed to generate a mod file for the proto dir."); | ||
|
||
get_protobuf_files(); | ||
generate_proto_sources().expect("Failed to generate protobuf source code from proto files."); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curl might be easier to use. Using Rust only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if you manage to use curl, you don't need the whole shenanigans of installing wget/having a special Docker image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, I will look into using that one.