-
Notifications
You must be signed in to change notification settings - Fork 2
feat(huffman): add LLAR formula #148
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
Open
MeteorsLiu
wants to merge
2
commits into
xgo-dev:main
Choose a base branch
from
MeteorsLiu:issue/90-huffman
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+127
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,123 @@ | ||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "slices" | ||
| "strings" | ||
| ) | ||
|
|
||
| const consumerSource = `#include <stdint.h> | ||
| #include <stdlib.h> | ||
|
|
||
| #include "huffman/huffman.h" | ||
|
|
||
| int main(void) { | ||
| uint8_t input[3] = {'a', 'b', 'c'}; | ||
| unsigned char *encoded = NULL; | ||
| uint32_t encoded_len = 0; | ||
|
|
||
| if (huffman_encode_memory(input, 3, &encoded, &encoded_len) != 0) { | ||
| return 1; | ||
| } | ||
|
|
||
| free(encoded); | ||
| return encoded_len == 0; | ||
| } | ||
| ` | ||
|
|
||
| id "drichardson/huffman" | ||
|
|
||
| // v1.2.3 is the first upstream tag with the CMake build and install contract | ||
| // used by v1.2.3 through v1.2.7. | ||
| fromVer "v1.2.3" | ||
|
|
||
| defaults { | ||
| "shared": "OFF", | ||
| "fPIC": "ON", | ||
| } | ||
|
|
||
| filter => { | ||
| for name, values in target.options { | ||
| if name != "shared" && name != "fPIC" { | ||
| return false | ||
| } | ||
| for value in values { | ||
| if value != "ON" && value != "OFF" { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| onBuild ctx => { | ||
| installDir := ctx.outputDir | ||
|
|
||
| // Match the Conan recipe's Cygwin source fix while retaining upstream | ||
| // behavior on native Windows and other platforms. | ||
| sourcePath := filepath.join(ctx.SourceDir, "huffman.c") | ||
| source := string(os.readFile(sourcePath)!) | ||
| source = strings.replace(source, "#ifdef WIN32", "#if defined _WIN32 || defined __CYGWIN__", 1) | ||
| os.writeFile(sourcePath, []byte(source), 0644)! | ||
|
|
||
| shared := slices.contains(target.options["shared"], "ON") | ||
| fPIC := slices.contains(target.options["fPIC"], "ON") | ||
|
|
||
| c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) | ||
| c.defineBool "BUILD_SHARED_LIBS", shared | ||
| c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC | ||
| c.configure | ||
| c.build | ||
| c.install | ||
|
|
||
| licenseDir := filepath.join(installDir, "licenses") | ||
| os.mkdirAll(licenseDir, 0755)! | ||
| os.writeFile(filepath.join(licenseDir, "LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE"))!, 0644)! | ||
|
|
||
| libs := "-L$${libdir} -lhuffman" | ||
| if slices.contains(target.require["os"], "windows") { | ||
| libs += " -lws2_32" | ||
| } | ||
|
|
||
| pcDir := filepath.join(installDir, "lib", "pkgconfig") | ||
| os.mkdirAll(pcDir, 0755)! | ||
| pc := `prefix=$${pcfiledir}/../.. | ||
| includedir=$${prefix}/include | ||
| libdir=$${prefix}/lib | ||
|
|
||
| Name: huffman | ||
| Description: Huffman encoder and decoder library | ||
| Version: 1.2.3 | ||
| Libs: ` + libs + ` | ||
| Cflags: -I$${includedir} | ||
| ` | ||
| os.writeFile(filepath.join(pcDir, "huffman.pc"), []byte(pc), 0644)! | ||
| pkgconfig.use installDir | ||
| ctx.setMetadata pkgconfig.lookup("huffman")! | ||
| } | ||
|
|
||
| onTest ctx => { | ||
| installDir := ctx.outputDir | ||
| testDir := filepath.join(ctx.SourceDir, "_llar_consumer") | ||
| os.mkdirAll(testDir, 0755)! | ||
|
|
||
| sourcePath := filepath.join(testDir, "consumer.c") | ||
| os.writeFile(sourcePath, []byte(consumerSource), 0644)! | ||
|
|
||
| binary := filepath.join(testDir, "consumer") | ||
| pkgconfig.use installDir | ||
| flags := strings.fields(pkgconfig.lookup("huffman")!) | ||
| args := []string{sourcePath} | ||
| args <- flags... | ||
| args <- "-o", binary | ||
| cc! args... | ||
|
|
||
| if slices.contains(target.options["shared"], "ON") { | ||
| os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| if slices.contains(target.require["os"], "windows") { | ||
| path := os.getenv("PATH") | ||
| os.setenv("PATH", filepath.join(installDir, "bin")+";"+path)! | ||
| } | ||
| } | ||
| exec! binary | ||
| } | ||
This file contains hidden or 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 @@ | ||
| { | ||
| "path": "drichardson/huffman", | ||
| "deps": {} | ||
| } |
Oops, something went wrong.
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.
[P3] Non-obvious consumer assertion could use a one-line comment
return encoded_len == 0;makes the consumer exit non-zero when the encoder produced no output — a deliberate assertion that encoding yielded bytes. It reads like a bug at a glance. A short comment (e.g.// non-zero exit if encoding produced nothing) would make the intent clear to future maintainers.