Skip to content

Commit

Permalink
Document file for file format
Browse files Browse the repository at this point in the history
Issue #8
  • Loading branch information
AngheloAlf committed Feb 23, 2024
1 parent 94019ea commit a60b31a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 12 deletions.
51 changes: 51 additions & 0 deletions docs/file_format/file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# File

A file entry describes information about a file that should be linked in a
segment.

Every attribute listed is optional unless explicitly stated.

## `path`

This is **required**.

Path to the file.

The `base_path` from settings is used as a base for the emitted path.

### Example

```yaml
segments:
- name: boot
files:
- { path: src/boot/boot_main.o }
```
### Valid values
Any valid path.
## `kind`

Specifies the type of file entry.

### Example

```yaml
segments:
- name: boot
files:
- { path: src/boot/utils.o, kind: object }
```

### Valid values

- `object`: The path points to a relocatable object file.

### Default value

Guessed from `path` using the following file extensions:

- `.o`: `Object`.
- Anything else: `Object`.
3 changes: 0 additions & 3 deletions docs/file_format/files.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/file_format/segments.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ List of files belonging to this segment.

The order of the list implies the order on which the files will be emitted.

To see customization options for each file check the [files.md](files.md)
To see customization options for each file check the [file.md](file.md)
document.

### Example
Expand Down
7 changes: 6 additions & 1 deletion slinky/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{fs, path::Path};

use serde::Deserialize;

use crate::{Segment, Settings, SlinkyError};
use crate::{FileKind, Segment, Settings, SlinkyError};

#[derive(Deserialize, PartialEq, Debug)]
pub struct Document {
Expand Down Expand Up @@ -43,6 +43,11 @@ impl Document {
segment
.wildcard_sections
.get_or_insert(document.settings.wildcard_sections);

for file in &mut segment.files {
// TODO: guess based on file extension
file.kind.get_or_insert(FileKind::Object);
}
}

Ok(document)
Expand Down
7 changes: 1 addition & 6 deletions slinky/src/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,5 @@ use crate::file_kind::FileKind;
pub struct FileInfo {
pub path: PathBuf,

#[serde(default = "default_fileinfo_kind")]
pub kind: FileKind,
}

fn default_fileinfo_kind() -> FileKind {
FileKind::Object
pub kind: Option<FileKind>,
}
1 change: 1 addition & 0 deletions slinky/src/file_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use serde::Deserialize;

#[derive(Deserialize, PartialEq, Debug)]
#[serde(rename_all = "snake_case")]
pub enum FileKind {
Object,
Archive,
Expand Down
2 changes: 1 addition & 1 deletion slinky/src/linker_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl LinkerWriter<'_> {
};

// TODO: figure out glob support
match file.kind {
match file.kind.as_ref().unwrap() {
FileKind::Object => {
self.writeln(&format!("{}({}{});", path.display(), section, wildcard));
}
Expand Down

0 comments on commit a60b31a

Please sign in to comment.